diff --git a/build/knockout-kendo.js b/build/knockout-kendo.js index d537c8e..fe9718a 100644 --- a/build/knockout-kendo.js +++ b/build/knockout-kendo.js @@ -715,6 +715,16 @@ createBinding({ } }); +createBinding({ + async: true, + name: "kendoScheduler", + watch: { + data: function(value, options) { + ko.kendo.setDataSource(this, value, options); + } + } +}); + createBinding({ name: "kendoSlider", defaultOption: VALUE, diff --git a/build/knockout-kendo.min.js b/build/knockout-kendo.min.js index 85ec967..611644e 100644 --- a/build/knockout-kendo.min.js +++ b/build/knockout-kendo.min.js @@ -14,4 +14,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -!function(a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?a(require("knockout"),require("jquery"),require("kendo")):"function"==typeof define&&define.amd?define(["knockout","jquery","kendo"],a):a(window.ko,window.jQuery,window.kendo)}(function(a,b,c,d){c=c||window.kendo,a.kendo=a.kendo||{},a.kendo.BindingFactory=function(){var e=this;this.createBinding=function(c){if(b()[c.parent||c.name]){var d={};d.init=function(a,b,f,g,h){var i=e.buildOptions(c,b);return i.async===!0||c.async===!0&&i.async!==!1?(setTimeout(function(){d.setup(a,i,h)},0),void 0):(d.setup(a,i,h),i&&i.useKOTemplates?{controlsDescendantBindings:!0}:void 0)},d.setup=function(d,f,g){var h,i=b(d);e.setupTemplates(c.templates,f,d,g),h=e.getWidget(c,f,i),e.handleEvents(f,c,d,h,g),e.watchValues(h,f,c,d),h.destroy&&a.utils.domNodeDisposal.addDisposeCallback(d,function(){h.destroy()})},d.options={},d.widgetConfig=c,a.bindingHandlers[c.bindingName||c.name]=d}},this.buildOptions=function(b,d){var e=b.defaultOption,f=a.utils.extend({},a.bindingHandlers[b.name].options),g=a.utils.unwrapObservable(d());return g instanceof c.data.DataSource||"object"!=typeof g||null===g||e&&!(e in g)?f[e]=d():a.utils.extend(f,g),f};var f=function(b,c){return function(d){return a.renderTemplate(b,c.createChildContext(d._raw&&d._raw()||d))}};this.setupTemplates=function(b,c,d,e){var g,h,i,j;if(b&&c&&c.useKOTemplates){for(g=0,h=b.length;h>g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(a,b,c,d,f){var g,h,i=b.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),e.handleOneEvent(g,h,a,c,d,b.childProp,f))},this.handleOneEvent=function(b,c,d,e,f,g,h){var i;c.call&&"function"==typeof d[c.call]?i=d[c.call].bind(h.$data,h.$data):c.writeTo&&a.isWriteableObservable(d[c.writeTo])&&(console.log("binding handler for",b),i=function(a){console.log("firing handler for",c.writeTo);var b,f;g&&a[g]&&a[g]!==e||(b=c.value,f="string"==typeof b&&this[b]?this[b](g&&e):b,d[c.writeTo](f))}),i&&f.bind(b,i)}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="clicked",h="close",i="collapse",j="content",k="data",l="enable",m="expand",n="expanded",o="error",p="filter",q="info",r="isOpen",s="max",t="min",u="open",v="palette",w="readonly",x="search",y="selected",z="success",A="size",B="title",C="value",D="values",E="warning";f({name:"kendoAutoComplete",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoButton",defaultOption:g,events:{click:{call:g}},watch:{enabled:l}}),f({name:"kendoCalendar",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C}}),f({name:"kendoColorPicker",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,value:C,color:C,palette:v}}),f({name:"kendoComboBox",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoDatePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDateTimePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDropDownList",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:C}}),f({name:"kendoEditor",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoGrid",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMaskedTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,isReadOnly:w,value:C}}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:l,isOpen:[u,h]},async:!0}),f({name:"kendoMultiSelect",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}});var F=function(a,b){b||0===b?this.show(b,a):this.hide()};f({name:"kendoNotification",watch:{error:function(a){F.call(this,o,a)},info:function(a){F.call(this,q,a)},success:function(a){F.call(this,z,a)},warning:function(a){F.call(this,E,a)}}}),f({name:"kendoNumericTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,value:C,max:function(a){this.options.max=a,this.value()>a&&this.value(a)},min:function(a){this.options.min=a,this.value()g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(a,b,c,d,f){var g,h,i=b.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),e.handleOneEvent(g,h,a,c,d,b.childProp,f))},this.handleOneEvent=function(b,c,d,e,f,g,h){var i;c.call&&"function"==typeof d[c.call]?i=d[c.call].bind(h.$data,h.$data):c.writeTo&&a.isWriteableObservable(d[c.writeTo])&&(console.log("binding handler for",b),i=function(a){console.log("firing handler for",c.writeTo);var b,f;g&&a[g]&&a[g]!==e||(b=c.value,f="string"==typeof b&&this[b]?this[b](g&&e):b,d[c.writeTo](f))}),i&&f.bind(b,i)}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="clicked",h="close",i="collapse",j="content",k="data",l="enable",m="expand",n="expanded",o="error",p="filter",q="info",r="isOpen",s="max",t="min",u="open",v="palette",w="readonly",x="search",y="selected",z="success",A="size",B="title",C="value",D="values",E="warning";f({name:"kendoAutoComplete",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoButton",defaultOption:g,events:{click:{call:g}},watch:{enabled:l}}),f({name:"kendoCalendar",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C}}),f({name:"kendoColorPicker",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,value:C,color:C,palette:v}}),f({name:"kendoComboBox",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoDatePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDateTimePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDropDownList",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:C}}),f({name:"kendoEditor",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoGrid",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMaskedTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,isReadOnly:w,value:C}}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:l,isOpen:[u,h]},async:!0}),f({name:"kendoMultiSelect",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}});var F=function(a,b){b||0===b?this.show(b,a):this.hide()};f({name:"kendoNotification",watch:{error:function(a){F.call(this,o,a)},info:function(a){F.call(this,q,a)},success:function(a){F.call(this,z,a)},warning:function(a){F.call(this,E,a)}}}),f({name:"kendoNumericTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,value:C,max:function(a){this.options.max=a,this.value()>a&&this.value(a)},min:function(a){this.options.min=a,this.value()" + }); + + //additional kendoScheduler cases + +}); \ No newline at end of file diff --git a/spec/runner.html b/spec/runner.html index de67de1..62d9f2d 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -36,7 +36,8 @@ - + + diff --git a/src/knockout-kendo.js b/src/knockout-kendo.js index 47333c3..4c049bb 100644 --- a/src/knockout-kendo.js +++ b/src/knockout-kendo.js @@ -56,6 +56,8 @@ kendo = kendo || window.kendo; //import "knockout-kendoRangeSlider.js" +//import "knockout-kendoScheduler.js" + //import "knockout-kendoSlider.js" //import "knockout-kendoSplitter.js" diff --git a/src/knockout-kendoScheduler.js b/src/knockout-kendoScheduler.js new file mode 100644 index 0000000..d7c6cbd --- /dev/null +++ b/src/knockout-kendoScheduler.js @@ -0,0 +1,9 @@ +createBinding({ + async: true, + name: "kendoScheduler", + watch: { + data: function(value, options) { + ko.kendo.setDataSource(this, value, options); + } + } +}); \ No newline at end of file