a35e53b9b2b9d99f5c92a03f1b480fdc6435fcc6
[ccsdk/features.git] /
1 (function( $, app ) {
2
3         var data = app.ns("data");
4         var ux = app.ns("ux");
5
6         data.Model = ux.Observable.extend({
7                 defaults: {
8                         data: null
9                 },
10                 init: function() {
11                         this.set( this.config.data );
12                 },
13                 set: function( key, value ) {
14                         if( arguments.length === 1 ) {
15                                 this._data = $.extend( {}, key );
16                         } else {
17                                 key.split(".").reduce(function( ptr, prop, i, props) {
18                                         if(i === (props.length - 1) ) {
19                                                 ptr[prop] = value;
20                                         } else {
21                                                 if( !(prop in ptr) ) {
22                                                         ptr[ prop ] = {};
23                                                 }
24                                                 return ptr[prop];
25                                         }
26                                 }, this._data );
27                         }
28                 },
29                 get: function( key ) {
30                         return key.split(".").reduce( function( ptr, prop ) {
31                                 return ( ptr && ( prop in ptr ) ) ? ptr[ prop ] : undefined;
32                         }, this._data );
33                 },
34         });
35 })( this.jQuery, this.app );