Mercurial > code > home > repos > href
changeset 19:9fc1f5c8aa4e
working on the 'share' selectbox ui
Ignore-this: 5e6f80568920eb3aab9e56bdfb509d19
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sun, 17 Mar 2013 00:49:27 -0700 |
parents | 7ef5365591fd |
children | a8887fb93676 |
files | static/add.js template/add.jade.mustache |
diffstat | 2 files changed, 56 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- 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); + +
--- 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.