// A widgets-in-template widget that composes the application UI of TodoMVC (Dojo 1.8 version).
// Also, this class inherits todo/_CssToggleMixin so that it can react to change in "present"/"complete" attributes and add/remove CSS class to the root DOM node of this widget.
// templateString: String
// The HTML of widget template.
templateString:template,
// _setPresentAttr: Object
// A object used by todo/_CssToggleMixin to reflect true/false state of "present" attribute to existence of "todos_present" CSS class in this widget's root DOM.
// A object used by todo/_CssToggleMixin to reflect true/false state of "complete" attribute to existence of "todos_selected" CSS class in this widget's root DOM.
// Kicks off instantiation of this controller, in a similar manner as dijit/_WidgetBase.postscript().
// params: Object?
// The optional parameters for this controller.
// srcNodeRef: DOMNode?
// The DOM node declaring this controller. Set if this controller is created via Dojo parser.
this.inherited(arguments);
srcNodeRef&&srcNodeRef.setAttribute("widgetId",this.id);// If this is created via Dojo parser, set widgetId attribute so that destroyDescendants() of parent widget works
},
startup:function(){
// summary:
// A function called after the DOM fragment declaring this controller is added to the document, in a similar manner as dijit/_WidgetBase.startup().
var_self=this;
this.own(router.register(/.*/,function(e){// Register a route handling callback for any route, make sure it's cleaned up upon this controller being destroyed
// Removes a todo item having the given unique ID.
// uniqueId: String
// The unique ID of the todo item to be removed.
varmodel=this[this._refModelProp],
indices=array.filter(array.map(model,function(item,idx){returnitem.uniqueId==uniqueId?idx:-1;}),function(idx){returnidx>=0;});// The array index of the todo item to bd removed
if(indices.length>0){
model.splice(indices[0],1);
}
},
removeCompletedItems:function(){
// summary:
// Removes todo items that have been marked as complete.
varmodel=this[this._refModelProp];
for(vari=model.length-1;i>=0;--i){
if(model[i].get("completed")){
model.splice(i,1);
}
}
},
markAll:function(/*Boolean*/markComplete){
// summary:
// Mark all todo items as complete or incomplete.
// markComplete: Boolean
// True to mark all todo items as complete. Otherwise to mark all todo items as incomplete.
// - Provide references to the data model, whose data comes from above Dojo Object Store
// defaultId: String
// The default ID to fetch data as this controller starts up.
defaultId:"",
// store: dojo/store
// Our custom Dojo Object Store, backed by localStorage.
// This will be used to read the initial items, if available, and persist the current items when the application finishes.
store:null,
// modelClass: todo/model/SimpleTodoModel
// The class of our data model, based on dojo/Stateful and dojox/mvc/StatefulArray.
// This will be used to automatically keep various Todo properties (e.g. number of complete/incomplete items) consistent, and to auto-generate properties (e.g. default unique IDs).
modelClass:null,
getStatefulOptions:{
// summary:
// An object that specifies how plain object from Dojo Object Store should be converted to a data model based on dojo/Stateful and dojox/mvc/StatefulArray.
getType:function(/*Object*/v){
return"specifiedModel";// We are converting given object at once using modelClass here, instead of using per-data-item based data conversion callbacks
},
getStatefulSpecifiedModel:function(/*Object*/o){
returnnew(this.parent.modelClass)(o);// Create an instance of modelClass given the plain object from Dojo Object Store
}
},
getPlainValueOptions:{
// summary:
// An object that specifies how a data model based on dojo/Stateful and dojox/mvc/StatefulArray should be converted to a plain object, to be saved to Dojo Object Store.
// Kicks off instantiation of this controller, in a similar manner as dijit/_WidgetBase.postscript().
// params: Object?
// The optional parameters for this controller.
// srcNodeRef: DOMNode?
// The DOM node declaring this controller. Set if this controller is created via Dojo parser.
this.getStatefulOptions.parent=this;// For getStatefulOptions object to have a reference to this object
this.inherited(arguments);
srcNodeRef&&srcNodeRef.setAttribute("widgetId",this.id);// If this is created via Dojo parser, set widgetId attribute so that destroyDescendants() of parent widget works
},
startup:function(){
// summary:
// A function called after the DOM fragment declaring this controller is added to the document, in a similar manner as dijit/_WidgetBase.startup().
this.inherited(arguments);
this.getStore(this.defaultId);// Obtain data from Dojo Object Store as soon as this starts up
},
set:function(/*String*/name,/*Anything*/value){
// summary:
// A function called when a property value is set to this controller.
// A dojox/mvc data converter, that does one-way conversion that returns whether we have less than n todo items in a specific state, where n is the given number in data converter options.
// Data converter options can be specified by setting constraints property in one of data binding endpoints.
// See data converter section of dojox/mvc/sync library's documentation for more details.
varstatefulData=getStateful(data||defaultData);// Convert a plain object to dojo/Stateful, hierarchically. Use the default data if (lastly saved) data is not there
array.forEach(statefulData.todos,assignPropertiesToNewItem);// Add additional properties to todo items
// This is a build profile for Dojo version of TodoMVC.
// To use this, place todomvc directory at the directory containing dojo/dijit/dojox/util (and follow the procedure of building Dojo).
// Refer to todomvc/architecture-examples/dojo/js/lib/dojo-1.8 and todomvc/architecture-examples/dojo/js/lib/dijit-1.8 to see what built files need to be copied.