(function(){vart=this;vare=t.Backbone;vari=[];varr=i.push;vars=i.slice;varn=i.splice;vara;if(typeofexports!=="undefined"){a=exports}else{a=t.Backbone={}}a.VERSION="1.0.0";varh=t._;if(!h&&typeofrequire!=="undefined")h=require("underscore");a.$=t.jQuery||t.Zepto||t.ender||t.$;a.noConflict=function(){t.Backbone=e;returnthis};a.emulateHTTP=false;a.emulateJSON=false;varo=a.Events={on:function(t,e,i){if(!l(this,"on",t,[e,i])||!e)returnthis;this._events||(this._events={});varr=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});returnthis},once:function(t,e,i){if(!l(this,"once",t,[e,i])||!e)returnthis;varr=this;vars=h.once(function(){r.off(t,s);e.apply(this,arguments)});s._callback=e;returnthis.on(t,s,i)},off:function(t,e,i){varr,s,n,a,o,u,c,f;if(!this._events||!l(this,"off",t,[e,i]))returnthis;if(!t&&!e&&!i){this._events={};returnthis}a=t?[t]:h.keys(this._events);for(o=0,u=a.length;o<u;o++){t=a[o];if(n=this._events[t]){this._events[t]=r=[];if(e||i){for(c=0,f=n.length;c<f;c++){s=n[c];if(e&&e!==s.callback&&e!==s.callback._callback||i&&i!==s.context){r.push(s)}}}if(!r.length)deletethis._events[t]}}returnthis},trigger:function(t){if(!this._events)returnthis;vare=s.call(arguments,1);if(!l(this,"trigger",t,e))returnthis;vari=this._events[t];varr=this._events.all;if(i)c(i,e);if(r)c(r,arguments);returnthis},stopListening:function(t,e,i){varr=this._listeners;if(!r)returnthis;vars=!e&&!i;if(typeofe==="object")i=this;if(t)(r={})[t._listenerId]=t;for(varninr){r[n].off(e,i,this);if(s)deletethis._listeners[n]}returnthis}};varu=/\s+/;varl=function(t,e,i,r){if(!i)returntrue;if(typeofi==="object"){for(varsini){t[e].apply(t,[s,i[s]].concat(r))}returnfalse}if(u.test(i)){varn=i.split(u);for(vara=0,h=n.length;a<h;a++){t[e].apply(t,[n[a]].concat(r))}returnfalse}returntrue};varc=function(t,e){vari,r=-1,s=t.length,n=e[0],a=e[1],h=e[2];switch(e.length){case0:while(++r<s)(i=t[r]).callback.call(i.ctx);return;case1:while(++r<s)(i=t[r]).callback.call(i.ctx,n);return;case2:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a);return;case3:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a,h);return;default:while(++r<s)(i=t[r]).callback.apply(i.ctx,e)}};varf={listenTo:"on",listenToOnce:"once"};h.each(f,function(t,e){o[e]=function(e,i,r){vars=this._listeners||(this._listeners={});varn=e._listenerId||(e._listenerId=h.uniqueId("l"));s[n]=e;if(typeofi==="object")r=this;e[t](i,r,this);returnthis}});o.bind=o.on;o.unbind=o.off;h.extend(a,o);vard=a.Model=function(t,e){vari;varr=t||{};e||(e={});this.cid=h.uniqueId("c");this.attributes={};h.extend(this,h.pick(e,p));if(e.parse)r=this.parse(r,e)||{};if(i=h.result(this,"defaults")){r=h.defaults({},r,i)}this.set(r,e);this.changed={};this.initialize.apply(this,arguments)};varp=["url","urlRoot","collection"];h.extend(d.prototype,o,{changed:null,validationError:null,idAttribute:"id",initialize:function(){},toJSON:function(t){returnh.clone(this.attributes)},sync:function(){returna.sync.apply(this,arguments)},get:function(t){returnthis.attributes[t]},escape:function(t){returnh.escape(this.get(t))},has:function(t){returnthis.get(t)!=null},set:function(t,e,i){varr,s,n,a,o,u,l,c;if(t==null)returnthis;if(typeoft==="object"){s=t;i=e}else{(s={})[t]=e}i||(i={});if(!this._validate(s,i))returnfalse;n=i.unset;o=i.silent;a=[];u=this._changing;this._changing=true;if(!u){this._previousAttributes=h.clone(this.attributes);this.changed={}}c=this.attributes,l=this._previousAttributes;if(this.idAttributeins)this.id=s[this.idAttribute];for(rins){e=s[r];if(!h.isEqual(c[r],e))a.push(r);if(!h.isEqual(l[r],e)){this.changed[r]=e}else{deletethis.changed[r]}n?deletec[r]:c[r]=e}if(!o){if(a.length)this._pending=true;for(varf=0,d=a.length;f<d;f++){this.trigger("change:"+a[f],this,c[a[f]],i)}}if(u)returnthis;if(!o){while(this._pending){this._pending=false;this.trigger("change",this,i)}}this._pending=false;this._changing=false;returnthis},unset:function(t,e){returnthis.set(t,void0,h.extend({},e,{unset:true}))},clear:function(t){vare={};for(variinthis.attributes)e[i]=void0;returnthis.set(e,h.extend({},t,{unset:true}))},hasChanged:function(t){if(t==null)return!h.isEmpty(this.changed);returnh.has(this.changed,t)},changedAttributes:function(t){if(!t)returnthis.hasChanged()?h.clone(this.changed):false;vare,i=false;varr=this._changing?this._previousAttributes:this.attributes;for(varsint){if(h.isEqual(r[s],e=t[s]))continue;(i||(i={}))[s]=e}returni},previous:function(t){if(t==null||!this._previousAttributes)returnnull;returnthis._previousAttributes[t]},previousAttributes:function(){returnh.clone(this._previousAttributes)},fetch:function(t){t=t?h.clone(t):{};if(t.parse===void0)t.parse=true;vare=this;vari=t.success;t.success=function(r){if(!e.set(e.parse(r,t),t))returnfalse;if(i)i(e,r,t);e.trigger("sync",e,r,t)};R(this,t);returnthis.sync("read",this,t)},save:function(t,e,i){varr,s,n,a=this.attributes;if(t==null||typeoft==="object"){r=t;i=e}else{(r={})[t]=e}if(r&&(!i||!i.wait)&&!this.set(r,i))returnfalse;i=h.extend({validate:true},i);if(!this._validate(r,i))returnfalse;if(r&&i.wait){this.attributes=h.extend({},a,r)}if(i.parse===void0)i.parse=true;varo=this;varu=i.success;i.success=function(t){o.attributes=a;vare=o.parse(t,i);if(i.wait)e=h.extend(r||{},e);if(h.isObject(e)&&!o.set(e,i)){returnfalse}if(u)u(o,t,i);o.trigger("sync",o,t,i)};R(this,i);s=this.isNew()?"create":i.patch?"patch":"update";if(s==="patch")i.attrs=r;n=this.sync(s,this,i);if(r&&i.wait)this.attributes=a;returnn},destroy:function(t){t=t?h.clone(t):{};vare=this;vari=t.success;varr=function(){e.trigger("destroy",e,e.collection,t)};t.success=function(s){if(t.wait||e.isNew())r();if(i)i(e,s,t);if(!e.isNew())e.trigger("sync",e,s,t)};if(this.isNew()){t.success();returnfalse}R(this,t);vars=this.sync("delete",this,t);if(!t.wait)r();returns},url:function(){vart=h.result(this,"urlRoot")||h.result(this.collection,"url")||U();if(this.isNew())returnt;returnt+(t.charAt(t.length-1)==="/"?"":"/")+encodeURIComponent(this.id)},parse:function(t,e){returnt},clone:function(){returnnewthis.constructor(this.attributes)},isNew:function(){returnthis.id==null},isValid:function(t){returnthis._validate({},h.extend(t||{},{validate:true}))},_validate:function(t,e){if(!e.validate||!this.validate)returntrue;t=h.extend({},this.attributes,t);vari=this.validationError=this.validate(t,e)||null;if(!i)returntrue;this.trigger("invalid",this,i,h.extend(e||{},{validationError:i}));returnfalse}});varv=["keys","values","pairs","invert","pick","omit"];h.each(v,function(t){d.prototype[t]=function(){vare=s.call(arguments);e.unshift(this.attributes);returnh[t].apply(h,e)}});varg=a.Collection=function(t,e){e||(e={});if(e.url)this.url=e.url;if(e.model)this.model=e.model;if(e.comparator!==void0)this.comparator=e.comparator;this._reset();this.initialize.apply(this,arguments);if(t)this.reset(t,h.extend({silent:true},e))};varm={add:true,remove:true,merge:true};vary={add:true,merge:false,remove:false};h.extend(g.prototype,o,{model:d,initialize:function(){},toJSON:function(t){returnthis.map(function(e){returne.toJSON(t)})},sync:function(){returna.sync.apply(this,arguments)},add:function(t,e){returnthis.set(t,h.defaults(e||{},y))},remove:function(t,e){t=h.isArray(t)?t.slice():[t];e||(e={});vari,r,s,n;for(i=0,r=t.length;i<r;i++){n=this.get(t[i]);if(!n)continue;deletethis._byId[n.id];deletethis._byId[n.cid];s=this.indexOf(n);this.models.splice(s,1);this.length--;if(!e.silent){e.index=s;n.trigger("remove",n,this,e)}this._removeReference(n)}returnthis},set:function(t,e){e=h.defaults(e||{},m);if(e.parse)t=this.parse(t,e);if(!h.isArray(t))t=t?[t]:[];vari,s,a,o,u,l;varc=e.at;varf=this.comparator&&c==null&&e.sort!==false;vard=h.isString(this.comparator)?this.comparator:null;varp=[],v=[],g={};for(i=0,s=t.length;i<s;i++){if(!(a=this._prepareModel(t[i],e)))continue;if(u=this.get(a)){if(e.remove)g[u.cid]=true;if(e.merge){u.set(a.attributes,e);if(f&&!l&&u.hasChanged(d))l=true}}elseif(e.add){p.push(a);a.on("all",this._onModelEvent,this);this._byId[a.cid]=a;if(a.id!=null)this._byId[a.id]=a}}if(e.remove){for(i=0,s=this.length;i<s;++i){if(!g[(a=this.models[i]).cid])v.push(a)}if(v.length)this.remove(v,e)}if(p.length){if(f)l=true;this.length+=p.length;if(c!=null){n.apply(this.models,[c,0].concat(p))}else{r.apply(this.models,p)}}if(l)this.sort({silent:true});if(e.silent)returnthis;for(i=0,s=p.length;i<s;i++){(a=p[i]).trigger("add",a,this,e)}if(l)this.trigger("sort",this,e);returnthis},reset:function(t,e){e||(e={});for(vari=0,r=this.models.length;i<r;i++){this._removeReference(this.models[i])}e.previousModels=this.models;this._reset();this.add(t,h.extend({silent:true},e));if(!e.silent)this.trigger("reset",this,e);returnthis},push:function(t,e){t=this._prepareModel(t,e);this.add(t,h.extend({at:this.length},e));returnt},pop:function(t){vare=this.at(this.length-1);this.remove(e,t);returne},unshift:function(t,e){t=this._prepareModel(t,e);this.add(t,h.extend({at:0},e));returnt},shift:function(t){vare=this.at(0);this.remove(e,t);returne},slice:function(t,e){returnthis.models.slice(t,e)},get:function(t){if(t==null)returnvoid0;returnthis._byId[t.id!=null?t.id:t.cid||t]},at:function(t){returnthis.models[t]},where:function(t,e){if(h.isEmpty(t))returne?void0:[];returnthis[e?"find":"filter"](function(e){for(variint){if(t[i]!==e.get(i))returnfalse}returntrue})},findWhere:function(t){returnthis.where(t,true)},sort:function(t){if(!this.comparator)thrownewError("Cannot sort a set without a comparator");t||(t={});if(h.isString(this.comparator)||this.comparator.length===1){this.models=this.sortBy(this.comparator,this)}else{this.models.sort(h.bind(this.comparator,this))}if(!t.silent)this.trigger("sort",this,t);returnthis},sortedIndex:function(t,e,i){e||(e=this.comparator);varr=h.isFunction(e)?e:function(t){returnt.get(e)};returnh.sortedIndex(this.models,t,r,i)},pluck:function(t){returnh.invoke(this.models,"get",t)},fetch:function(t){t=t?h.clone(t):{};if(t.parse===void0)t.parse=true;vare=t.success;vari=this;t.success=function(r){vars=t.reset?"reset":"set";i[s](r,t);if(e)e(i,r,t);i.trigger("sync",i,r,t)};R(this,t);returnthis.sync("read",this,t)},create:function(t,e){e=e?h.clone(e):{};if(!(t=this._prepareModel(t,e)))returnfalse;if(!e.wait)this.add(t,e);vari=this;varr=e.success;e.success=function(s){if(e.wait)i.add(t,e);if(r)r(t,s,e)};t.save(null,e);returnt},parse:function(t,e){returnt},clone:function(){returnnewthis.constructor(this.models)},_reset:function(){this.length=0;this.models=[];this._byId={}},_prepareModel:function(t,e){if(tinstanceofd){if(!t.collection)t.collection=this;returnt}e||(e={});e.collection=this;vari=newthis.model(t,e);if(!i._validate(t,e)){this.trigger("invalid",this,t,e);returnfalse}returni},_removeReference:function(t){if(this===t.collection)deletet.collection;t.off("all",this._onModelEvent,this)},_onModelEvent:function(t,e,i,r){if((t==="add"||t==="remove")&&i!==this)return;if(t==="destroy")this.remove(e,r);if(e&&t==="change:"+e.idAttribute){deletethis._byId[e.previous(e.idAttribute)];if(e.id!=null)this._byId[e.id]=e}this.trigger.apply(this,arguments)}});var_=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","indexOf","shuffle","lastIndexOf","isEmpty","chain"];h.each(_,function(t){g.prototype[t]=function(){vare=s.call(arguments);e.unshift(this.models);returnh[t].apply(h,e)}});varw=["groupBy","countBy","sortBy"];h.each(w,function(t){g.prototype[t]=function(e,i){varr=h.isFunction(e)?e:function(t){returnt.get(e)};returnh[t](this.models,r,i)}});varb=a.View=function(t){this.cid=h.uniqueId("view");this._configure(t||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()};varx=/^(\S+)\s*(.*)$/;varE=["model","collection","el","id","attributes","className","tagName","events"];h.extend(b.prototype,o,{tagName:"div",$:function(t){returnthis.$el.find(t)},initialize:function(){},render:function(){returnthis},remove:function(){this.$el.remove();this.stopListening();returnthis},setElement:function(t,e){if(this.$el)this.undelegateEvents();this.$el=tinstanceofa.$?t:a.$(t);this.el=this.$el[0];if(e!==false)this.delegateEvents();returnthis},delegateEvents:function(t){if(!(t||(t=h.result(this,"events"))))returnthis;this.undelegateEvents();for(vareint){vari=t[e];if(!h.isFunction(i))i=this[t[e]];if(!i)continue;varr=e.match(x);vars=r[1],n=r[2];i=h.bind(i,this);s+=".delegateEvents"+this.cid;if(n===""){this.$el.on(s,i)}else{this.$el.on(s,n,i)}}returnthis},undelegateEvents:function(){this.$el.off(".delegateEvents"+this.cid);returnthis},_configure:function(t){if(this.options)t=h.extend({},h.result(this,"options"),t);h.extend(this,h.pick(t,E));this.options=t},_ensureElement:function(){if(!this.el){vart=h.extend({},h.result(this,"attributes"));if(this.id)t.id=h.result(this,"id");if(this.className)t["class"]=h.result(this,"className");vare=a.$("<"+h.result(this,"tagName")+">").attr(t);this.setElement(e,false)}else{this.setElement(h.result(this,"el"),false)}}});a.sync=function(t,e,i){varr=k[t];h.defaults(i||(i={}),{emulateHTTP:a.emulateHTTP,emulateJSON:a.emulateJSON});vars={type:r,dataType:"json"};if(!i.url){s.url=h.result(e,"url")||U()}if(i.data==null&&e&&(t==="create"||t==="update"||t==="patch")){s.contentType="application/json";s.data=JSON.stringify(i.attrs||e.toJSON(i))}if(i.emulateJSON){s.contentType="application/x-www-form-urlencoded";s.data=s.data?{model:s.data}:{}}if(i.emulateHTTP&&(r==="PUT"||r==="DELETE"||r==="PATCH")){s.type="POST";if(i.emulateJSON)s.data._method=r;varn=i.beforeSend;i.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",r);if(n)returnn.apply(this,arguments)}}if(s.type!=="GET"&&!i.emulateJSON){s.processData=false}if(s.type==="PATCH"&&window.ActiveXObject&&!(window.external&&window.external.msActiveXFilteringEnabled)){s.xhr=function(){returnnewActiveXObject("Microsoft.XMLHTTP")}}varo=i.xhr=a.ajax(h.extend(s,i));e.trigger("request",e,o,i);returno};vark={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};a.ajax=function(){returna.$.ajax.apply(a.$,arguments)};varS=a.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var$=/\((.*?)\)/g;varT=/(\(\?)?:\w+/g;varH=/\*\w+/g;varA=/[\-{}\[\]+?.,\\\^$|#\s]/g;h.extend(S.prototype,o,{initialize:function(){},route:function(t,e,i){if(!h.isRegExp(t))t=this._routeToRegExp(t);if(h.isFunction(e)){i=e;e=""}if(!i)i=this[e];varr=this;a.history.route(t,function(s){varn=r._extractParameters(t,s);i&&i.apply(r,n);r.trigger.apply(r,["route:"+e].concat(n));r.trigger("route",e,n);a.history.trigger("route",r,e,n)});returnthis},navigate:function(t,e){a.history.navigate(t,e);returnthis},_bindRoutes:function(){if(!this.routes)return;this.routes=h.result(this,"routes");vart,e=h.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(A,"\\$&").replace($,"(?:$1)?").replace(T,function(t,e){returne?t:"([^/]+)"}).replace(H,"(.*?)");returnnewRegExp("^"+t+"$")},_extractParameters:function(t,e){vari=t.exec(e).slice(1);returnh.map(i,function(t){returnt?decodeURIComponent(t):null})}});varI=a.History=function(){this.handlers=[];h.bindAll(this,"checkUrl");if(typeofwindow!=="undefined"){this.location=window.location;this.history=window.history}};varN=/^[#\/]|\s+$/g;varP=/^\/+|\/+$/g;varO=/msie [\w.]+/;varC=/\/$/;I.started=false;h.extend(I.prototype,o,{interval:50,getHash:function(t){vare=(t||this).location.href.match(/#(.*)$/);returne?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=this.location.pathname;vari=this.root.replace(C,"");if(!t.indexOf(i))t=t.substr(i.length)}else{t=this.getHash()}}returnt.replace(N,"")},start:function(t){if(I.started)thrownewError("Backbone.history has already been started");I.started=true;this.options=h.extend({},{root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);vare=this.getFragment();vari=document.documentMode;varr=O.exec(navigator.userAgent.toLowerCase())&&(!i||i<=7);this.root=("/"+this.root+"/").replace(P,"/");if(r&&this._wantsHashChange){this.iframe=a.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow;this.navigate(e)}if(this._hasPushState){a.$(window).on("popstate",this.checkUrl)}elseif(this._wantsHashChange&&"onhashchange"inwindow&&!r){a.$(window).on("hashchange",this.checkUrl)}elseif(this._wantsHashChange){this._checkUrlInterval=setInterval(this.checkUrl,this.interval)}this.fragment=e;vars=this.location;varn=s.pathname.replace(/[^\/]$/,"$&/")===this.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!n){this.fragment=this.getFragment(null,true);this.location.replace(this.root+this.location.search+"#"+this.fragment);returntrue}elseif(this._wantsPushState&&this._hasPushState&&n&&s.hash){this.fragment=this.getHash().replace(N,"");this.history.replaceState({},document.title,this.root+this.fragment+s.search)}if(!this.options.silent)returnthis.loadUrl()},stop:function(){a.$(window).off("popstate",this.checkUrl).off("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);I.started=false},route:function(t,e){this.handlers.unshift({route:t,callback:e})},checkUrl:function(t){vare=this.getFragment();if(e===this.fragment&&this.iframe){e=this.getFragment(this.getHash(this.iframe))}if(e===this.fragment)returnfalse;if(this.iframe)this.navigate(e);this.loadUrl()||this.loadUrl(this.getHash())},loadUrl:function(t){vare=this.fragment=this.getFragment(t);vari=h.any(this.handlers,function(t){if(t.route.test(e)){t.callback(e);returntrue}});returni},navigate:function(t,e){if(!I.started)returnfalse;if(!e||e===true)e={trigger:e};t=this.getFragment(t||"");if(this.fragment===t)return;this.fragment=t;vari=this.root+t;if(this._hasPushState){this.history[e.replace?"replaceState":"pushState"]({},document.title,i)}elseif(this._wantsHashChange){this._updateHash(this.location,t,e.replace);if(this.iframe&&t!==this.getFragment(this.getHash(this.iframe))){if(!e.replace)this.iframe.document.open().close();this._updateHash(this.iframe.location,t,e.replace)}}else{returnthis.location.assign(i)}if(e.trigger)this.loadUrl(t)},_updateHash:function(t,e,i){if(i){varr=t.href.replace(/(javascript:|#).*$/,"");t.replace(r+"#"+e)}else{t.hash="#"+e}}});a.history=newI;varj=function(t,e){vari=this;varr;if(t&&h.has(t,"constructor")){r=t.constructor}else{r=function(){returni.apply(this,arguments)}}h.extend(r,i,e);vars=function(){this.constructor=r};s.prototype=i.prototype;r.prototype=news;if(t)h.extend(r.prototype,t);r.__super__=i.prototype;returnr};d.extend=g.extend=S.extend=b.extend=I.extend=j;varU=function(){thrownewError('A "url" property or function must be specified')};varR=function(t,e){vari=e.error;e.error=function(r){if(i)i(t,r,e);t.trigger("error",t,r,e)}}}).call(this);
Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
Licensed under the MIT @license.
*/
!function(a){if("object"==typeofexports&&"function"==typeofrequire)module.exports=a(require("underscore"),require("backbone"));elseif("function"==typeofdefine&&define.amd)define(["underscore","backbone"],a);elseif("undefined"!=typeof_&&"undefined"!=typeofBackbone){varb=Backbone.PageableCollection,c=a(_,Backbone);Backbone.PageableCollection.noConflict=function(){returnBackbone.PageableCollection=b,c}}}(function(a,b){"use strict";functionc(b,c){if(!a.isNumber(b)||a.isNaN(b)||!a.isFinite(b)||~~b!==b)thrownewTypeError("`"+c+"` must be a finite integer");returnb}functiond(a){for(varb,c,d,e,f={},g=decodeURIComponent,h=a.split("&"),i=0,j=h.length;j>i;i++){vark=h[i];b=k.split("="),c=b[0],d=b[1]||!0,c=g(c),d=g(d),e=f[c],o(e)?e.push(d):f[c]=e?[e,d]:d}returnf}functione(a,b,c){vard=a._events[b];if(d&&d.length){vare=d[d.length-1],f=e.callback;e.callback=function(){try{f.apply(this,arguments),c()}catch(a){throwa}finally{e.callback=f}}}elsec()}varf=a.extend,g=a.omit,h=a.clone,i=a.each,j=a.pick,k=a.contains,l=a.isEmpty,m=a.pairs,n=a.invert,o=a.isArray,p=a.isFunction,q=a.isObject,r=a.keys,s=a.isUndefined,t=Math.ceil,u=Math.floor,v=Math.max,w=b.Collection.prototype,x=/[\s'"]/g,y=/[<>\s'"]/g,z=b.PageableCollection=b.Collection.extend({state:{firstPage:1,lastPage:null,currentPage:null,pageSize:25,totalPages:null,totalRecords:null,sortKey:null,order:-1},mode:"server",queryParams:{currentPage:"page",pageSize:"per_page",totalPages:"total_pages",totalRecords:"total_entries",sortKey:"sort_by",order:"order",directions:{"-1":"asc",1:"desc"}},constructor:function(a,b){w.constructor.apply(this,arguments),b=b||{};varc=this.mode=b.mode||this.mode||A.mode,d=f({},A.queryParams,this.queryParams,b.queryParams||{});d.directions=f({},A.queryParams.directions,this.queryParams.directions,d.directions||{}),this.queryParams=d;vare=this.state=f({},A.state,this.state,b.state||{});e.currentPage=null==e.currentPage?e.firstPage:e.currentPage,o(a)||(a=a?[a]:[]),a=a.slice(),"server"==c||null!=e.totalRecords||l(a)||(e.totalRecords=a.length),this.switchMode(c,f({fetch:!1,resetState:!1,models:a},b));varg=b.comparator;if(e.sortKey&&!g&&this.setSorting(e.sortKey,e.order,b),"server"!=c){vari=this.fullCollection;g&&b.full&&(this.comparator=null,i.comparator=g),b.full&&i.sort(),a&&!l(a)&&(this.reset(a,f({silent:!0},b)),this.getPage(e.currentPage),a.splice.apply(a,[0,a.length].concat(this.models)))}this._initState=h(this.state)},_makeFullCollection:function(a,c){vard,e,f,g=["url","model","sync","comparator"],h=this.constructor.prototype,i={};for(d=0,e=g.length;e>d;d++)f=g[d],s(h[f])||(i[f]=h[f]);varj=new(b.Collection.extend(i))(a,c);for(d=0,e=g.length;e>d;d++)f=g[d],this[f]!==h[f]&&(j[f]=this[f]);returnj},_makeCollectionEventHandler:function(a,b){returnfunction(c,d,g,j){vark=a._handlers;i(r(k),function(c){vard=k[c];a.off(c,d),b.off(c,d)});varl=h(a.state),m=l.firstPage,n=0===m?l.currentPage:l.currentPage-1,o=l.pageSize,p=n*o,q=p+o;if("add"==c){varu,v,w,x,j=j||{};if(g==b)v=b.indexOf(d),v>=p&&q>v&&(x=a,u=w=v-p);else{u=a.indexOf(d),v=p+u,x=b;varw=s(j.at)?v:j.at+p}if(j.onRemove||(++l.totalRecords,deletej.onRemove),a.state=a._checkState(l),x){x.add(d,f({},j||{},{at:w}));vary=u>=o?d:!s(j.at)&&q>w&&a.length>o?a.at(o):null;y&&e(g,c,function(){a.remove(y,{onAdd:!0})})}}if("remove"==c)if(j.onAdd)deletej.onAdd;else{if(--l.totalRecords){varz=l.totalPages=t(l.totalRecords/o);l.lastPage=0===m?z-1:z||m,l.currentPage>z&&(l.currentPage=l.lastPage)}elsel.totalRecords=null,l.totalPages=null;a.state=a._checkState(l);varA,B=j.index;g==a?((A=b.at(q))?e(a,c,function(){a.push(A,{onRemove:!0})}):!a.length&&l.totalRecords&&a.reset(b.models.slice(p-o,q-o),f({},j,{parse:!1})),b.remove(d)):B>=p&&q>B&&((A=b.at(q-1))&&e(a,c,function(){a.push(A,{onRemove:!0})}),a.remove(d),!a.length&&l.totalRecords&&a.reset(b.models.slice(p-o,q-o),f({},j,{parse:!1})))}if("reset"==c)if(j=g,g=d,g==a&&null==j.from&&null==j.to){varC=b.models.slice(0,p),D=b.models.slice(p+a.models.length);b.reset(C.concat(a.models).concat(D),j)}elseg==b&&((l.totalRecords=b.models.length)||(l.totalRecords=null,l.totalPages=null),"client"==a.mode&&(l.lastPage=l.currentPage=l.firstPage),a.state=a._checkState(l),a.reset(b.models.slice(p,q),f({},j,{parse:!1})));"sort"==c&&(j=g,g=d,g===b&&a.reset(b.models.slice(p,q),f({},j,{parse:!1}))),i(r(k),function(c){vard=k[c];i([a,b],function(a){a.on(c,d);varb=a._events[c]||[];b.unshift(b.pop())})})}},_checkState:function(a){varb=this.mode,d=this.links,e=a.totalRecords,f=a.pageSize,g=a.currentPage,h=a.firstPage,i=a.totalPages;if(null!=e&&null!=f&&null!=g&&null!=h&&("infinite"==b?d:!0)){if(e=c(e,"totalRecords"),f=c(f,"pageSize"),g=c(g,"currentPage"),h=c(h,"firstPage"),1>f)thrownewRangeError("`pageSize` must be >= 1");if(i=a.totalPages=t(e/f),0>h||h>1)thrownewRangeError("`firstPage must be 0 or 1`");if(a.lastPage=0===h?v(0,i-1):i||h,"infinite"==b){if(!d[g+""])thrownewRangeError("No link found for page "+g)}elseif(h>g||i>0&&(h?g>i:g>=i))thrownewRangeError("`currentPage` must be firstPage <= currentPage "+(h?">":">=")+" totalPages if "+h+"-based. Got "+g+".")}returna},setPageSize:function(a,b){a=c(a,"pageSize"),b=b||{first:!1};vard=this.state,e=t(d.totalRecords/a),h=e?v(d.firstPage,u(e*d.currentPage/d.totalPages)):d.firstPage;returnd=this.state=this._checkState(f({},d,{pageSize:a,currentPage:b.first?d.firstPage:h,totalPages:e})),this.getPage(d.currentPage,g(b,["first"]))},switchMode:function(b,c){if(!k(["server","client","infinite"],b))thrownewTypeError('`mode` must be one of "server", "client" or "infinite"');c=c||{fetch:!0,resetState:!0};vard=this.state=c.resetState?h(this._initState):this._checkState(f({},this.state));this.mode=b;vare,j=this,l=this.fullCollection,m=this._handlers=this._handlers||{};if("server"==b||l)"server"==b&&l&&(i(r(m),function(a){e=m[a],j.off(a,e),l.off(a,e)}),deletethis._handlers,this._fullComparator=l.comparator,deletethis.fullCollection);else{l=this._makeFullCollection(c.models||[],c),l.pageableCollection=this,this.fullCollection=l;varn=this._makeCollectionEventHandler(this,l);i(["add","remove","reset","sort"],function(b){m[b]=e=a.bind(n,{},b),j.on(b,e),l.on(b,e)}),l.comparator=this._fullComparator}if("infinite"==b)for(varo=this.links={},p=d.firstPage,q=t(d.totalRecords/d.pageSize),s=0===p?v(0,q-1):q||p,u=d.firstPage;s>=u;u++)o[u]=this.url;elsethis.links&&deletethis.links;returnc.fetch?this.fetch(g(c,"fetch","resetState")):this},hasPreviousPage:function(){vara=this.state,b=a.currentPage;return"infinite"!=this.mode?b>a.firstPage:!!this.links[b-1]},hasNextPage:function(){vara=this.state,b=this.state.currentPage;return"infinite"!=this.mode?b<a.lastPage:!!this.links[b+1]},getFirstPage:function(a){returnthis.getPage("first",a)},getPreviousPage:function(a){returnthis.getPage("prev",a)},getNextPage:function(a){returnthis.getPage("next",a)},getLastPage:function(a){returnthis.getPage("last",a)},getPage:function(a,b){vard=this.mode,e=this.fullCollection;b=b||{fetch:!1};varh=this.state,i=h.firstPage,j=h.currentPage,k=h.lastPage,m=h.pageSize,n=a;switch(a){case"first":n=i;break;case"prev":n=j-1;break;case"next":n=j+1;break;case"last":n=k;break;default:n=c(a,"index")}this.state=this._checkState(f({},h,{currentPage:n})),b.from=j,b.to=n;varo=(0===i?n:n-1)*m,p=e&&e.length?e.models.slice(o,o+m):[];return"client"!=d&&("infinite"!=d||l(p))||b.fetch?("infinite"==d&&(b.url=this.links[n]),this.fetch(g(b,"fetch"))):(this.reset(p,g(b,"fetch")),this)},getPageByOffset:function(a,b){if(0>a)thrownewRangeError("`offset must be > 0`");a=c(a);vard=u(a/this.state.pageSize);return0!==this.state.firstPage&&d++,d>this.state.lastPage&&(d=this.state.lastPage),this.getPage(d,b)},sync:function(a,c,d){vare=this;if("infinite"==e.mode){varg=d.success,h=e.state.currentPage;d.success=function(a,b,c){vari=e.links,j=e.parseLinks(a,f({xhr:c},d));j.first&&(i[e.state.firstPage]=j.first),j.prev&&(i[h-1]=j.prev),j.next&&(i[h+1]=j.next),g&&g(a,b,c)}}return(w.sync||b.sync).call(e,a,c,d)},parseLinks:function(a,b){varc={},d=b.xhr.getResponseHeader("Link");if(d){vare=["first","prev","next"];i(d.split(","),function(a){varb=a.split(";"),d=b[0].replace(y,""),f=b.slice(1);i(f,function(a){varb=a.split("="),f=b[0].replace(x,""),g=b[1].replace(x,"");"rel"==f&&k(e,g)&&(c[g]=d)})})}returnc},parse:function(a,b){varc=this.parseState(a,h(this.queryParams),h(this.state),b);returnc&&(this.state=this._checkState(f({},this.state,c))),this.parseRecords(a,b)},parseState:function(b,c,d){if(b&&2===b.length&&q(b[0])&&o(b[1])){vare=h(d),f=b[0];returni(m(g(c,"directions")),function(b){varc=b[0],d=b[1],g=f[d];s(g)||a.isNull(g)||(e[c]=f[d])}),f.order&&(e.order=1*n(c.directions)[f.order]),e}},parseRecords:function(a){returna&&2===a.length&&q(a[0])&&o(a[1])?a[1]:a},fetch:function(a){a=a||{};varb=this._checkState(this.state),c=this.mode;"infinite"!=c||a.url||(a.url=this.links[b.currentPage]);vare=a.data||{},i=a.url||this.url||"";p(i)&&(i=i.call(this));vark=i.indexOf("?");-1!=k&&(f(e,d(i.slice(k+1))),i=i.slice(0,k)),a.url=i,a.data=e;varl,n,o,q,t="client"==this.mode?j(this.queryParams,"sortKey","order"):g(j(this.queryParams,r(A.queryParams)),"directions"),u=m(t),v=h(this);for(l=0;l<u.length;l++)n=u[l],o=n[0],q=n[1],q=p(q)?q.call(v):q,null!=b[o]&&null!=q&&(e[q]=b[o]);if(b.sortKey&&b.order){varx=p(t.order)?t.order.call(v):t.order;e[x]=this.queryParams.directions[b.order+""]}elseb.sortKey||deletee[t.order];vary=m(g(this.queryParams,r(A.queryParams)));for(l=0;l<y.length;l++)n=y[l],q=n[1],q=p(q)?q.call(v):q,null!=q&&(e[n[0]]=q);if("server"!=c){varz=this,B=this.fullCollection,C=a.success;returna.success=function(b,d,e){e=e||{},s(a.silent)?deletee.silent:e.silent=a.silent;varg=b.models;"client"==c?B.reset(g,e):(B.add(g,f({at:B.length},f(e,{parse:!1}))),z.trigger("reset",z,e)),C&&C(b,d,e)},w.fetch.call(this,f({},a,{silent:!0}))}returnw.fetch.call(this,a)},_makeComparator:function(a,b,c){vard=this.state;returna=a||d.sortKey,b=b||d.order,a&&b?(c||(c=function(a,b){returna.get(b)}),function(d,e){varf,g=c(d,a),h=c(e,a);return1===b&&(f=g,g=h,h=f),g===h?0:h>g?-1:1}):void0},setSorting:function(a,b,c){vard=this.state;d.sortKey=a,d.order=b=b||d.order;vare=this.fullCollection,g=!1,h=!1;a||(g=h=!0);vari=this.mode;c=f({side:"client"==i?i:"server",full:!0},c);varj=this._makeComparator(a,b,c.sortValue),k=c.full,l=c.side;return"client"==l?k?(e&&(e.comparator=j),g=!0):(this.comparator=j,h=!0):"server"!=l||k||(this.comparator=j),g&&(this.comparator=null),h&&e&&(e.comparator=null),this}}),A=z.prototype;returnz});
a.reduce===A){e&&(c=b.bind(c,e));returnf?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,i){if(f)d=c.call(e,d,a,b,i);else{d=a;f=true}});if(!f)thrownewTypeError("Reduce of empty array with no initial value");returnd};b.reduceRight=b.foldr=function(a,c,d,e){varf=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));returnf?a.reduceRight(c,d):a.reduceRight(c)}varg=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));returnf?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=function(a,
<p>{% trans "You can export all student answers to multiple-choice questions and long-form answers to a CSV file here." %}</p>
<divclass="data-export-status"></div>
<divclass="data-export-actions">
<buttonclass="data-export-download">{% trans "Download result" %}</button>
<buttonclass="data-export-cancel">{% trans "Cancel current export" %}</button>
<buttonclass="data-export-delete">{% trans "Delete result" %}</button>
</div>
<divclass="data-export-options">
<divclass="data-export-options">
<divclass="data-export-header">
<h3>{% trans "Filters" %}</h3>
</div>
<divclass="data-export-row">
<divclass="data-export-field-container">
<divclass="data-export-field-container">
<divclass="data-export-field">
<divclass="data-export-field">
<label>
<label>
<span>{% trans "Problem types:" %}</span>
<span>{% trans "Username:" %}</span>
<selectmultiplename="block_types">
<inputtype="text"name="username"/>
{% for label, value in block_choices.items %}
<optionvalue="{{value}}">{{label}}</option>
{% endfor %}
</select>
</label>
</label>
</div>
</div>
<divclass="data-export-helptext">
{% trans "Select which types of problem to include (selecting none will grab all types)" %}
</div>
</div>
<divclass="data-export-field-container">
<divclass="data-export-field">
<label>
<span>{% trans "Text:" %}</span>
<inputtype="text"name="match_string"/>
</label>
</div>
</div>
</div>
</div>
<divclass="data-export-row">
<divclass="data-export-field-container">
<divclass="data-export-field-container">
<divclass="data-export-field">
<divclass="data-export-field">
<label>
<label>
...
@@ -34,22 +31,55 @@
...
@@ -34,22 +31,55 @@
<inputtype="text"name="root_block_id"/>
<inputtype="text"name="root_block_id"/>
</label>
</label>
</div>
</div>
<divclass="data-export-helptext">
{% trans "Input the ID of a chapter, section, or unit if you wish to only get results under it. Otherwise, it will grab all results for the course." %}
</div>
</div>
</div>
<divclass="data-export-field-container">
<divclass="data-export-field-container">
<divclass="data-export-field">
<divclass="data-export-field">
<label>
<label>
<span>{% trans "Username:" %}</span>
<span>{% trans "Problem types:" %}</span>
<inputtype="text"name="username"/>
<selectname="block_types">
<optionvalue="all">All</option>
{% for label, value in block_choices.items %}
<optionvalue="{{value}}">{{label}}</option>
{% endfor %}
</select>
</label>
</label>
</div>
</div>
<divclass="data-export-helptext">
{% trans "Input the username of a student if you wish to query for a specific one. Otherwise, it will grab all results for all students." %}