!function(){var moduleFactory=function($){var module=this;$.require().script("mvc/model").done(function(){var exports=function(){var getArgs=function(args){return args[0]&&$.isArray(args[0])?args[0]:args[0]instanceof $.Model.List?$.makeArray(args[0]):$.makeArray(args)},id=0,getIds=function(item){return item[item.constructor.id]},expando=$.expando,each=$.each,ajax=$.Model._ajax,ajaxMethods={update:function(str){return function(ids,attrs,success,error){return ajax(str,{ids:ids,attrs:attrs},success,error,"-updateAll","put")
}},destroy:function(str){return function(ids,success,error){return ajax(str,ids,success,error,"-destroyAll","post")}}};$.Class($.globalNamespace+".Model.List",{setup:function(){for(var name in ajaxMethods)"function"!=typeof this[name]&&(this[name]=ajaxMethods[name](this[name]))}},{init:function(instances){this.length=0,this._data={},this._namespace=".list"+ ++id,this.push.apply(this,$.makeArray(instances||[]))},slice:function(){return new this.Class(Array.prototype.slice.apply(this,arguments))},match:function(property,value){return this.grep(function(inst){return inst[property]==value
})},grep:function(callback,args){return new this.Class($.grep(this,callback,args))},_makeData:function(){var data=this._data={};this.each(function(i,inst){data[inst[inst.constructor.id]]=inst})},get:function(){if(!this.length)return new this.Class([]);this._changed&&this._makeData();for(var matches,val,list=[],constructor=this[0].constructor,underscored=constructor._fullName,idName=constructor.id,test=new RegExp(underscored+"_([^ ]+)"),args=getArgs(arguments),i=0;i<args.length;i++)val=args[i].nodeName&&(matches=args[i].className.match(test))?this._data[matches[1]]:this._data["string"==typeof args[i]||"number"==typeof args[i]?args[i]:args[i][idName]],val&&list.push(val);
return new this.Class(list)},remove:function(args){if(!this.length)return[];var matches,list=[],constructor=this[0].constructor,underscored=constructor._fullName,idName=constructor.id,test=new RegExp(underscored+"_([^ ]+)");args=getArgs(arguments);for(var i=0;i<this.length;){for(var inst=this[i],found=!1,a=0;a<args.length;a++){var id=args[a].nodeName&&(matches=args[a].className.match(test))&&matches[1]||("string"==typeof args[a]||"number"==typeof args[a]?args[a]:args[a][idName]);if(inst[idName]==id){list.push.apply(list,this.splice(i,1)),args.splice(a,1),found=!0;
break}}found||i++}var ret=new this.Class(list);return ret.length&&$([this]).trigger("remove",[ret]),ret},elements:function(context){return $(this.map(function(item){return"."+item.identity()}).join(","),context)},model:function(){return this.constructor.namespace},findAll:function(params,success,error){var self=this;this.model().findAll(params,function(items){self.push(items),success&&success(self)},error)},destroy:function(success,error){var ids=this.map(getIds),items=this.slice(0,this.length);return ids.length?this.constructor.destroy(ids,function(){each(items,function(){this.destroyed()
}),success&&success(items)},error):success&&success(this),this},update:function(attrs,success,error){var ids=this.map(getIds),items=this.slice(0,this.length);return ids.length?this.constructor.update(ids,attrs,function(newAttrs){var attributes=$.extend(attrs,newAttrs||{});each(items,function(){this.updated(attributes)}),success&&success(items)},error):success&&success(this),this},bind:function(){return void 0===this[expando]&&this.bindings(this),$.fn.bind.apply($([this]),arguments),this},unbind:function(){return $.fn.unbind.apply($([this]),arguments),void 0===this[expando]&&$(this).unbind(this._namespace),this
},bindings:function(items){var self=this;$(items).bind("destroyed"+this._namespace,function(){self.remove(this)}).bind("updated"+this._namespace,function(){$([self]).trigger("updated",this)})},push:function(){var args=getArgs(arguments);void 0!==this[expando]&&this.bindings(args),this._changed=!0;var res=push.apply(this,args);return this[expando]&&args.length&&$([this]).trigger("add",[args]),res},serialize:function(){return this.map(function(item){return item.serialize()})}});var push=[].push,modifiers={pop:[].pop,shift:[].shift,unshift:[].unshift,splice:[].splice,sort:[].sort,reverse:[].reverse};
each(modifiers,function(name,func){$.Model.List.prototype[name]=function(){return this._changed=!0,func.apply(this,arguments)}}),each(["each","map"],function(i,name){$.Model.List.prototype[name]=function(callback,args){return $[name](this,callback,args)}})};exports(),module.resolveWith(exports)})};dispatch("mvc/model.list").containing(moduleFactory).to("Foundry/2.1 Modules")}();