Mercurial > code > home > repos > href
annotate static/add.js @ 33:b82432594778
skaffold config and other updates
author | drewp@bigasterisk.com |
---|---|
date | Sat, 21 Aug 2021 14:24:57 -0700 |
parents | 8008ec2fd763 |
children |
rev | line source |
---|---|
4 | 1 var model = { |
10
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
2 linkRecord: { |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
3 href: ko.observable(""), |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
4 description: ko.observable(""), |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
5 tag: ko.observable(""), |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
6 extended: ko.observable(""), |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
7 private: ko.observable(false), |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
8 shareWith: ko.observableArray([]), // foaf uris |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
9 }, |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
10 submitLabel: ko.observable("Add"), |
4 | 11 }; |
12 | |
13 ko.computed(function() { | |
10
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
14 if (model.linkRecord.href() == "") { |
4 | 15 return; |
16 } | |
17 | |
10
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
18 $.getJSON("addLink/proposedUri", {uri: model.linkRecord.href()}, function (data) { |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
19 // these could arrive after the user has started typing in the fields! |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
20 |
10
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
21 model.linkRecord.description(data.description); |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
22 model.linkRecord.tag(data.tag); |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
23 model.linkRecord.extended(data.extended); |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
24 model.linkRecord.shareWith(data.shareWith); |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
25 model.submitLabel(data.existed ? "Update existing" : "Add"); |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
26 |
4 | 27 }); |
28 | |
29 }); | |
30 | |
31 ko.applyBindings(model); | |
10
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
32 |
19
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
33 (function (inputElem, model) { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
34 inputElem.select2({ |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
35 tokenSeparators: [",", " "], |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
36 ajax: { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
37 url: "/foaf/findPerson", |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
38 data: function (term, page) { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
39 return {q: term}; |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
40 }, |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
41 results: function (data, page) { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
42 var ret = { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
43 results: data.people.map( |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
44 function (row) { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
45 return {id: row.uri, |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
46 text: row.label + " ("+row.uri+")"}; |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
47 }), |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
48 more: false, |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
49 context: {} |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
50 }; |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
51 //ret.results.push({id: "new1", text: this.context}); |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
52 return ret; |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
53 } |
10
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
54 }, |
19
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
55 tags: [], |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
56 }); |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
57 inputElem.on('change', function (e) { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
58 console.log("onchange", inputElem.select2('val')); |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
59 setModelFromShares(inputElem.select2('val')); |
10
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
60 }); |
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
61 |
19
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
62 var enableModel = true; |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
63 |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
64 var setSharesFromModel = ko.computed( |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
65 function () { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
66 var uris = ko.utils.arrayGetDistinctValues(model.linkRecord.shareWith()); |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
67 if (!enableModel) { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
68 return; |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
69 } |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
70 console.log("from model", uris) |
10
e054949143e9
reworking addlink and shareWith support
drewp@bigasterisk.com
parents:
5
diff
changeset
|
71 |
21
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
72 async.map(uris, |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
73 function (uri, cb) { |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
74 $.ajax({ |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
75 url: uri.replace(/^http:/, "https:"), |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
76 dataType: "text", |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
77 success: function (page) { |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
78 pp = page |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
79 d = $(page).rdfa().databank; |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
80 console.log("from", uri, "extracted", d.size(), "triples"); |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
81 "trying to get the rdfa out of this page to attempt prettier label/icon for the listed person" |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
82 console.log(JSON.stringify(d.dump())); |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
83 } |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
84 }); |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
85 cb(null, {id: uri, text: "("+uri+")"}); |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
86 }, |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
87 function (err, selections) { |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
88 inputElem.select2("data", selections); |
8008ec2fd763
fix up link page reloading. tried davisjs; may not need it
Drew Perttula <drewp@bigasterisk.com>
parents:
19
diff
changeset
|
89 }); |
19
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
90 }); |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
91 |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
92 function setModelFromShares(n) { |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
93 console.log("from val", inputElem.select2("val"), "new", n) |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
94 enableModel = false; |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
95 model.linkRecord.shareWith(inputElem.select2("val")); |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
96 enableModel = true; |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
97 } |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
98 |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
99 // setSharesFromModel(); |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
100 })($("#shareWith"), model); |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
101 |
9fc1f5c8aa4e
working on the 'share' selectbox ui
Drew Perttula <drewp@bigasterisk.com>
parents:
10
diff
changeset
|
102 |