# HG changeset patch # User Drew Perttula # Date 1363506567 25200 # Node ID 9fc1f5c8aa4e9097fa9ca2ff4220c3f71f86ee01 # Parent 7ef5365591fd57f438020b1856177577bd80fdbe working on the 'share' selectbox ui Ignore-this: 5e6f80568920eb3aab9e56bdfb509d19 diff -r 7ef5365591fd -r 9fc1f5c8aa4e static/add.js --- a/static/add.js Sun Mar 17 00:49:17 2013 -0700 +++ b/static/add.js Sun Mar 17 00:49:27 2013 -0700 @@ -30,42 +30,59 @@ ko.applyBindings(model); -$("#shareWith").select2({ - tokenSeparators: [",", " "], - ajax: { - url: "/foaf/findPerson", - data: function (term, page) { - return {q: term}; +(function (inputElem, model) { + inputElem.select2({ + tokenSeparators: [",", " "], + ajax: { + url: "/foaf/findPerson", + data: function (term, page) { + return {q: term}; + }, + results: function (data, page) { + var ret = { + results: data.people.map( + function (row) { + return {id: row.uri, + text: row.label + " ("+row.uri+")"}; + }), + more: false, + context: {} + }; + //ret.results.push({id: "new1", text: this.context}); + return ret; + } }, - results: function (data, page) { - var ret = {results: data.people.map( - function (row) { - return {id: row.uri, text: row.label + " ("+row.uri+")"} - }), - more: false, - context: {} - }; - //ret.results.push({id: "new1", text: this.context}); - return ret; - } - }, - tags: [], -}); -$("#shareWith").on('change', function (e) { setModelFromShares(e.val); }); - -var setSharesFromModel = ko.computed( - function () { - var uris = ko.utils.arrayGetDistinctValues(model.linkRecord.shareWith()); - console.log("from model", uris) - $("#shareWith").select2("data", uris.map( - function (uri) { - return {id: uri, text: "("+uri+")"}; - })); + tags: [], + }); + inputElem.on('change', function (e) { + console.log("onchange", inputElem.select2('val')); + setModelFromShares(inputElem.select2('val')); }); -function setModelFromShares(n) { - console.log("from val", $("#shareWith").select2("val"), "new", n) - model.linkRecord.shareWith($("#shareWith").select2("val")); -} + var enableModel = true; + + var setSharesFromModel = ko.computed( + function () { + var uris = ko.utils.arrayGetDistinctValues(model.linkRecord.shareWith()); + if (!enableModel) { + return; + } + console.log("from model", uris) -setSharesFromModel(); + inputElem.select2("data", uris.map( + function (uri) { + return {id: uri, text: "("+uri+")"}; + })); + }); + + function setModelFromShares(n) { + console.log("from val", inputElem.select2("val"), "new", n) + enableModel = false; + model.linkRecord.shareWith(inputElem.select2("val")); + enableModel = true; + } + + // setSharesFromModel(); +})($("#shareWith"), model); + + diff -r 7ef5365591fd -r 9fc1f5c8aa4e template/add.jade.mustache --- a/template/add.jade.mustache Sun Mar 17 00:49:17 2013 -0700 +++ b/template/add.jade.mustache Sun Mar 17 00:49:27 2013 -0700 @@ -25,6 +25,10 @@ div Share with (this does not work yet): input#shareWith(type='hidden', name='shareWith', style="width: 600px") + div(style='opacity: .5') + | shareWith + // ko text: JSON.stringify(shareWith()) + // /ko pre | upon submit, send msgs to c3po who has to buffer them against resends. | bigfoaf display should talk to c3po to learn msgs sent from and to this person.