text: (function(){"use strict";function t(e,r){var o;if(!1==this instanceof t)throw new Error("new operator required");if("string"==typeof e){var n=e;e={},e.name=n,"string"==typeof r&&(e.type=r)}e=e||{},this.name=e.name||null,this.label=e.label||e.name,this.label&&(this.label=this.label.charAt(0).toUpperCase()+this.label.slice(1)),this.type=e.type||"String",o=function(t){var e=t.split("(");return e[1]=parseInt(e[1]),e}(this.type),this.type=o[0],this.hint=e.hint||{},void 0!==e.hidden&&(this.hidden=e.hidden),this.validationRule=e.validationRule||{};var i=[],s=["name","type","label","hint","hidden","value","validationRule"];switch(this.type){case"ID":i=_(e,s),this.value=e.value||null;break;case"String":i=_(e,s.concat(["placeHolder","quickPick","size"])),this.size=o[1]?o[1]:"number"==typeof e.size?e.size:e.size||50,this.value=e.value||null,e.quickPick&&(this.quickPick=e.quickPick),this.placeHolder=e.placeHolder||null;break;case"Date":i=_(e,s.concat("placeHolder")),this.value=e.value||null,this.placeHolder=e.placeHolder||null;break;case"Boolean":i=_(e,s),e.value===!1?this.value=!1:this.value=e.value||null;break;case"Number":i=_(e,s.concat("placeHolder")),0===e.value?this.value=0:this.value=e.value||null,this.placeHolder=e.placeHolder||null;break;case"Model":i=_(e,s),this.value=e.value||null,this.value instanceof t.ModelID&&(this.modelType=this.value.modelType);break;case"Group":i=_(e,s),this.value=e.value||null;break;case"Table":i=_(e,s.concat("group")),this.value=e.value||null,this.group=e.group||null;break;case"Object":i=_(e,s),this.value=e.value||null}for(var a=this.getObjectStateErrors(),c=0;c<i.length;c++)a.push("invalid property: "+i[c]);if(a.length>1)throw new Error("error creating Attribute: multiple errors");if(a.length)throw new Error("error creating Attribute: "+a[0]);this._eventListeners=[],this._errorConditions={}}function e(t){if(!1==this instanceof e)throw new Error("new operator required");"function"==typeof t&&(t={type:"Function",contents:t}),t instanceof w&&(t={type:"Procedure",contents:t}),t=t||{};var r,o=_(t,["name","description","type","contents","scope","timeout","theme","icon","bucket","presentationMode","location","images"]),n=[];for(r=0;r<o.length;r++)n.push("invalid property: "+o[r]);if(n.length>1)throw new Error("error creating Command: multiple errors");if(n.length)throw new Error("error creating Command: "+n[0]);for(r in t)this[r]=t[r];if(this.name=this.name||"a command","string"!=typeof this.name)throw new Error("name must be string");if("undefined"==typeof this.description&&(this.description=this.name+" Command"),"undefined"==typeof this.type&&(this.type="Stub"),!P(e.getTypes(),this.type))throw new Error("Invalid command type: "+this.type);switch(this.type){case"Stub":break;case"Menu":if(!(this.contents instanceof Array))throw new Error("contents must be array of menu items");if(!this.contents.length)throw new Error("contents must be array of menu items");for(r in this.contents)if(this.contents.hasOwnProperty(r)&&"string"!=typeof this.contents[r]&&!(this.contents[r]instanceof e))throw new Error("contents must be array of menu items");break;case"Presentation":if(!(this.contents instanceof b))throw new Error("contents must be a Presentation");if(this.presentationMode=this.presentationMode||"View",!P(e.getPresentationModes(),this.presentationMode))throw new Error("Invalid presentationMode: "+this.presentationMode);break;case"Function":if("function"!=typeof this.contents)throw new Error("contents must be a Function");break;case"Procedure":if(!(this.contents instanceof w))throw new Error("contents must be a Procedure");break;default:throw new TypeError}if("undefined"!=typeof this.scope&&!(this.scope instanceof d||this.scope instanceof f))throw new Error("optional scope property must be Model or List");if("undefined"!=typeof this.timeout&&"number"!=typeof this.timeout)throw new Error("timeout must be a Number");if("undefined"!=typeof this.timeout&&"number"!=typeof this.timeout)throw new Error("timeout must be a Number");if("undefined"!=typeof this.theme){if("string"!=typeof this.theme)throw new Error("invalid theme");if(!P(["default","primary","success","info","warning","danger","link"],this.theme))throw new Error("invalid theme")}if("undefined"!=typeof this.icon){if("string"!=typeof this.icon)throw new Error("invalid icon");if(!P(["fa","glyphicon"],this.icon.split("-")[0])||!this.icon.split("-")[1])throw new Error("invalid icon")}this._eventListeners=[]}function r(e){if(!1==this instanceof r)throw new Error("new operator required");if(!1==e instanceof t.ModelID)throw new Error("Attribute.ModelID required in constructor");this.dateCreated=new Date,this.modelID=e,this.attributeValues={}}function o(t){if(!1==this instanceof o)throw new Error("new operator required");t=t||{},t.name=t.name||"(unnamed)",t.description=t.description||"a Interface",t.vendor=t.vendor||null;var e,r=_(t,["name","description","vendor"]),n=[];for(e=0;e<r.length;e++)n.push("invalid property: "+r[e]);if(n.length>1)throw new Error("error creating Interface: multiple errors");if(n.length)throw new Error("error creating Interface: "+n[0]);this.startcallback=null,this.stopcallback=null,this.mocks=[],this.mockPending=!1;for(e in t)this[e]=t[e]}function n(t,e){if(!1==this instanceof n)throw new Error("new operator required");if("undefined"==typeof t)throw new Error("message type required");if(!P(n.getTypes(),t))throw new Error("Invalid message type: "+t);this.type=t,this.contents=e}function i(t){if(!1==this instanceof i)throw new Error("new operator required");if("string"==typeof t){var r=t;t={},t.type=r}if(t=t||{},this.type=t.type||null,t.value&&(this.value=t.value),!this.type||"string"!=typeof this.type)throw new Error("Request type required");switch(this.type){case"Command":if(this.command=t.command||null,!(this.command instanceof e))throw new Error("command object required")}}function s(t){if(!1==this instanceof s)throw new Error("new operator required");this.contents=t||"",this._eventListeners=[]}function a(t,e){if(!1==this instanceof a)throw new Error("new operator required");if("string"!=typeof t)throw new Error("argument must a url string");if("function"!=typeof e)throw new Error("argument must a callback");var r=this;r.connected=!1,r.initialConnect=!0,r.location=t,""===r.location&&(r.location="http host"),r.socket=io.connect(t,{reconnection:!1}),r.socket.on("connect",function(){r.connected=!0,r.initialConnect=!1,console.log("socket.io ("+r.location+") connected"),e.call(r,new n("Connected",""))}),r.socket.on("connecting",function(){console.log("socket.io ("+r.location+") connecting")}),r.socket.on("error",function(t){var o="general error with "+r.location+(t?", reason "+t:"");console.error(o),r.initialConnect&&e.call(r,new n("Error",o))}),r.socket.on("connect_error",function(t){var o="connect error with "+r.location+(t?", reason "+t:"");console.error(o),r.initialConnect&&e.call(r,new n("Error",o))}),r.socket.on("connect_failed",function(t){var o="connect failed with "+r.location+(t?", reason "+t:"");console.error(o),r.initialConnect&&e.call(r,new n("Error",o))}),r.socket.on("message",function(t){r.rawCallBack?r.rawCallBack(t):console.log("socket.io ("+r.location+") message: "+t)}),r.socket.on("disconnect",function(t){r.connected=!1,console.log("socket.io ("+r.location+") disconnect: "+t)})}function h(e,r,o){if(!1==this instanceof h)throw new Error("new operator required");if(!(e instanceof d))throw new Error("argument must be a Model");if("object"!=typeof r)throw new Error("object expected");if(!(o instanceof Array))throw new Error("array of attributes expected");this.primaryModel=e,this.relatedModels=r,this.attributes=o;var n=new t("id","ID");n.model=e,this.attributes.unshift(n);for(var i in r)if(r.hasOwnProperty(i)){var s=r[i];if("object"!=typeof s)throw new Error("relatedModel key values expect object");if(void 0===s.id)throw new Error("relatedModel key values expect object with id key");if(void 0===s.model)throw new Error("relatedModel key values expect object with model key");if(!(s.id instanceof t))throw new Error("relatedModel id must be a Attribute");if(!(s.model instanceof d))throw new Error("relatedModel model must be a Model")}for(var a=0;a<o.length;a++){var c=o[a];if(!(c instanceof t))throw new Error("attribute array must contain Attributes");if(!(c.model instanceof d))throw new Error("attribute array must contain Attributes with model references")}}function u(e){if(!1==this instanceof u)throw new Error("new operator required");e=e||{},e.attributes||(e.attributes=[]);var r=new t.ModelID(new k);e.attributes.push(new t({name:"user",type:"Model",value:r})),e.attributes.push(new t({name:"deltas",type:"Object",value:{}})),d.call(this,e),this.modelType="Workspace"}var l=this,p={CORE:function(){return{version:"0.4.43",Application:v,Attribute:t,Command:e,Delta:r,Interface:o,List:f,Log:g,MemoryStore:q,Message:n,Model:d,Presentation:b,Procedure:w,REPLInterface:y,Request:i,Session:E,Store:m,Text:s,Transport:a,User:k,View:h,Workspace:u,inheritPrototype:M,getInvalidProperties:_,getConstructorFromModelType:C,createModelFromModelType:S,trim:x,ltrim:A,rtrim:R,left:O,center:T,right:I,lpad:L,rpad:D,cpad:j,contains:P}}};t.ModelID=function(e){if(!1==this instanceof t.ModelID)throw new Error("new operator required");if(!1==e instanceof d)throw new Error("must be constructed with Model");var r=e.getShortName();r&&(this.name=r),this.value=e.get("id"),this.constructorFunction=e.constructor,this.modelType=e.modelType},t.ModelID.prototype.toString=function(){return this.name?this.modelType+" "+this.name:this.modelType+" "+this.value},t.prototype.toString=function(){return null===this.name?"new Attribute":"Attribute: "+this.name+" = "+this.value},t.prototype.onEvent=function(t,e){if(!(t instanceof Array)){if("string"!=typeof t)throw new Error("subscription string or array required");t=[t]}if("function"!=typeof e)throw new Error("callback is required");for(var r in t)if(t.hasOwnProperty(r)&&"*"!=t[r]&&!P(["StateChange","Validate"],t[r]))throw new Error("Unknown command event: "+t[r]);return this._eventListeners.push({events:t,callback:e}),this},t.prototype.offEvent=function(){this._eventListeners=[]},t.prototype._emitEvent=function(t){var e;for(e in this._eventListeners)if(this._eventListeners.hasOwnProperty(e)){var r=this._eventListeners[e];(r.events.length&&"*"===r.events[0]||P(r.events,t))&&r.callback.call(this,t)}},t.prototype.get=function(){return this.value},t.prototype.set=function(e){switch(this.type){case"Model":if(!(e instanceof t.ModelID))throw new Error("set error: value must be Attribute.ModelID");this.value=e;break;default:this.value=e}return this._emitEvent("StateChange"),this.value},t.prototype.coerce=function(t){var e,r=t;switch(this.type){case"String":return"undefined"==typeof r?"":"boolean"!=typeof r||r?r?(r=t.toString(),r.length>this.size?r.substring(0,this.size):r):"":"false";case"Number":return"undefined"==typeof r?0:r?("string"==typeof r?(r=r.replace(/^\s+|\s+$/g,""),e=r.split(" "),r=e.length?e[0]:"",r=Number(r.replace(/[^\/0-9\ \.]+/g,""))):r=Number(r),r?r:0):0;case"Boolean":return"undefined"!=typeof r&&("string"==typeof r?(r=r.toUpperCase(),"Y"===r||"YES"===r||"T"===r||"TRUE"===r||"1"===r):!!r);case"Date":return"string"==typeof r&&2==r.split("/").length&&(r=r+"/"+(new Date).getFullYear()),new Date(r)}throw Error("coerce cannot determine appropriate value")},t.prototype.getObjectStateErrors=function(){var e;switch(this.validationErrors=[],this.name||this.validationErrors.push("name required"),P(["ID","String","Date","Boolean","Number","Model","Group","Table","Object"],this.type)||this.validationErrors.push("Invalid type: "+this.type),this.type){case"ID":break;case"String":"number"!=typeof this.size&&this.validationErrors.push("size must be a number from 1 to 255"),(this.size<1||this.size>255)&&this.validationErrors.push("size must be a number from 1 to 255"),null!==this.value&&"string"!=typeof this.value&&this.validationErrors.push("value must be null or a String");break;case"Date":null===this.value||this.value instanceof Date||this.validationErrors.push("value must be null or a Date");break;case"Boolean":null!==this.value&&"boolean"!=typeof this.value&&this.validationErrors.push("value must be null or a Boolean");break;case"Number":null!==this.value&&"number"!=typeof this.value&&this.validationErrors.push("value must be null or a Number");break;case"Model":this.value instanceof t.ModelID||this.validationErrors.push("value must be Attribute.ModelID");break;case"Group":if(null===this.value||this.value instanceof Array)for(e in this.value)this.value.hasOwnProperty(e)&&(this.value[e]instanceof t||this.validationErrors.push("each element in group must be instance of Attribute"),this.value[e].getObjectStateErrors().length&&this.validationErrors.push("group contains invalid members"));else this.validationErrors.push("value must be null or an array");break;case"Table":if(this.group instanceof t)if(this.group.value instanceof Array)if(this.group.value.length<1)this.validationErrors.push("group property value must contain at least one Attribute");else for(e in this.group.value)this.group.value.hasOwnProperty(e)&&(this.group.value[e]instanceof t||this.validationErrors.push("each element in group must be instance of Attribute"),this.group.value[e].getObjectStateErrors().length&&this.validationErrors.push("group contains invalid members"));else this.validationErrors.push("group.value must be an array");else this.validationErrors.push("group property required")}var r=_(this.validationRule,["required","range","isOneOf","isValidModel"]);return r.length&&this.validationErrors.push("invalid validationRule: "+r),this.validationMessage=this.validationErrors.length>0?this.validationErrors[0]:"",this.validationErrors},t.prototype.validate=function(t){if("function"!=typeof t)throw new Error("callback is required");this.getObjectStateErrors(),this._emitEvent("Validate");var e;for(e in this._errorConditions)this._errorConditions.hasOwnProperty(e)&&this.validationErrors.push(this._errorConditions[e]);this.validationRule.required&&!this.value&&("Number"==this.type?0!==this.value&&this.validationErrors.push(this.label+" required"):"Boolean"==this.type?this.value!==!1&&this.validationErrors.push(this.label+" required"):this.validationErrors.push(this.label+" required")),this.validationRule.range&&(this.validationRule.range instanceof Array||(this.validationRule.range=[this.validationRule.range]),(this.validationRule.range[0]||0===this.validationRule.range[0])&&this.value<this.validationRule.range[0]&&this.validationErrors.push(this.label+" must be at least "+this.validationRule.range[0]),(this.validationRule.range[1]||0===this.validationRule.range[1])&&this.value>this.validationRule.range[1]&&this.validationErrors.push(this.label+" must be no more than "+this.validationRule.range[1])),this.validationRule.isOneOf&&(this.validationRule.isOneOf instanceof Array||(this.validationRule.isOneOf=[this.validationRule.isOneOf]),this.validationRule.isOneOf.indexOf(this.value)==-1&&this.validationErrors.push(this.label+" invalid")),this.validationMessage=this.validationErrors.length>0?this.validationErrors[0]:"",this._emitEvent("StateChange"),t.call(this)},t.prototype.setError=function(t,e){if(t=t||"",e=e||"",!t)throw new Error("condition required");if(!e)throw new Error("description required");this._errorConditions[t]=e},t.prototype.clearError=function(t){if(t=t||"",!t)throw new Error("condition required");delete this._errorConditions[t]},t.getTypes=function(){return["ID","String","Date","Boolean","Number","Model","Group","Table","Object"].slice(0)},t.getEvents=function(){return["StateChange","Validate"].slice(0)},e.prototype.toString=function(){return this.type+" Command: "+this.name},e.prototype.onEvent=function(t,e){if(!(t instanceof Array)){if("string"!=typeof t)throw new Error("subscription string or array required");t=[t]}if("function"!=typeof e)throw new Error("callback is required");for(var r in t)if(t.hasOwnProperty(r)&&"*"!=t[r]&&!P(["BeforeExecute","AfterExecute","Error","Aborted","Completed"],t[r]))throw new Error("Unknown command event: "+t[r]);this._eventListeners.push({events:t,callback:e})},e.prototype._emitEvent=function(t,e){var r;for(r in this._eventListeners)if(this._eventListeners.hasOwnProperty(r)){var o=this._eventListeners[r];(o.events.length&&"*"===o.events[0]||P(o.events,t))&&o.callback.call(this,t,e)}},e.prototype.execute=function(t){function r(){a.status=0;try{a.contents.apply(a,c)}catch(t){a.error=t,a._emitEvent("Error",t),a._emitEvent("Completed"),a.status=-1}}function n(){a.status=0;for(var t=a.contents.tasks||[],r=0;r<t.length;r++){if("function"==typeof t[r]){var o=t[r];t[r]={requires:[-1],command:new e({type:"Function",contents:o})}}t[r].command._parentProcedure||(t[r].command._taskIndex=r,t[r].command._parentProcedure=a,t[r].command.onEvent("*",s)),t[r].command.status=void 0}i()}function i(){for(var t=a.contents.tasks||[],e=0;e<t.length;e++){var r=!0;if("undefined"==typeof t[e].command.status){for(var o in t[e].requires){if("string"==typeof t[e].requires[o])for(var n=0;n<t.length;n++)t[n].label==t[e].requires[o]&&(!t[n].command.status||t[n].command.status<=0)&&(r=!1);if("number"==typeof t[e].requires[o])if(t[e].requires[o]==-1)"0"!=e&&(!t[e-1].command.status||t[e-1].command.status<=0)&&(r=!1);else{var i=t[e].requires[o];(!t[i].command.status||t[i].command.status<=0)&&(r=!1)}}r&&t[e].command.execute()}}}function s(t,e){var r=a.contents.tasks,o=!0;switch(t){case"Error":a._emitEvent("Error",e);break;case"Aborted":a.abort();break;case"Completed":for(var n in r)r.hasOwnProperty(n)&&(r[n].command.status&&0!==r[n].command.status||(o=!1));o?a.complete():i()}}var a=this,c=arguments;if(!a.type)throw new Error("command not implemented");if(!P(["Function","Procedure","Menu","Presentation"],a.type))throw new Error("command type "+a.type+" not implemented");var h;switch(a.type){case"Presentation":if(!(a.contents instanceof b))throw new Error("contents must be a Presentation");if(h=a.contents.getObjectStateErrors(),h.length)throw h.length>1?new Error("error executing Presentation: multiple errors"):new Error("error executing Presentation: "+h[0]);if(!(t instanceof o))throw new Error("interface param required")}a._emitEvent("BeforeExecute");try{switch(a.type){case"Function":setTimeout(r,0);break;case"Procedure":setTimeout(n,0);break;case"Menu":t.render(a,"View");break;case"Presentation":a.contents.preRenderCallback?a.contents.preRenderCallback(a,function(){t.render(a)}):t.render(a)}}catch(u){a.error=u,a._emitEvent("Error",u),a._emitEvent("Completed"),a.status=-1}a._emitEvent("AfterExecute")},e.prototype.abort=function(){this._emitEvent("Aborted"),this.status=-1,this._emitEvent("Completed")},e.prototype.complete=function(){this.status=1,this._emitEvent("Completed")},e.prototype.restart=function(){this.status=void 0,this._emitEvent("Restarted"),this.execute()},e.getTypes=function(){return["Stub","Menu","Presentation","Function","Procedure"].slice(0)},e.getEvents=function(){return["BeforeExecute","AfterExecute","Error","Aborted","Completed"].slice(0)},e.getPresentationModes=function(){return["View","Edit","List"].slice(0)},o.prototype.toString=function(){return this.description},o.prototype.canMock=function(){return!0},o.prototype.doMock=function(){var t,e;if(this.mockPending=!1,!(this.mocks.length<1)){var r=this.mocks.shift();if("ok"==r.type)return void(this.okcallback?(t=this.okcallback,delete this.okcallback,t()):this.okPending=!0);if("yes"==r.type||"no"==r.type||"cancel"==r.type){switch(r.type){case"yes":e=!0;break;case"no":e=!1;break;case"cancel":e=void 0}return void(this.yesnocallback?(t=this.yesnocallback,delete this.yesnocallback,t(e)):(this.yesnoPending=!0,this.yesnoResponse=e))}if("ask"==r.type)return void(this.askcallback?(t=this.askcallback,delete this.askcallback,t(r.value)):(this.askPending=!0,this.askResponse=r.value));if("choose"==r.type)return void(this.choosecallback?(t=this.choosecallback,delete this.choosecallback,t(o.firstMatch(r.value,this.chooseChoices))):(this.choosePending=!0,this.chooseResponse=r.value));this.dispatch(r),this.mockPending=!0;var n=this;setTimeout(function(){n.doMock()},0)}},o.prototype.mockRequest=function(t){if(!(t instanceof Array||t instanceof i))throw new Error("missing request parameter");t instanceof Array||(t=[t]);var e;for(e=0;e<t.length;e++)if(!1==t[e]instanceof i)throw new Error("invalid request parameter");for(e=0;e<t.length;e++)this.mocks.push(t[e]);this.mockPending||this.doMock()},o.prototype.start=function(t,e,r){if(!(t instanceof v))throw new Error("Application required");if(!(e instanceof b))throw new Error("presentation required");if("function"!=typeof r)throw new Error("callback required");this.application=t,this.presentation=e,this.startcallback=r},o.prototype.stop=function(t){if("function"!=typeof t)throw new Error("callback required")},o.prototype.dispatch=function(t,e){if(!1==t instanceof i)throw new Error("Request required");if(e&&"function"!=typeof e)throw new Error("response callback is not a function");this.application&&this.application.dispatch(t)||this.startcallback&&this.startcallback(t)},o.prototype.notify=function(t){if(!1==t instanceof n)throw new Error("Message required")},o.prototype.render=function(t,r){if(!1==t instanceof e)throw new Error("Command object required")},o.prototype.info=function(t){if(!t||"string"!=typeof t)throw new Error("text required")},o.prototype.done=function(t){if(!t||"string"!=typeof t)throw new Error("text required")},o.prototype.warn=function(t){if(!t||"string"!=typeof t)throw new Error("text required")},o.prototype.err=function(t){if(!t||"string"!=typeof t)throw new Error("text required")},o.prototype.ok=function(t,e){if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.okPending?(delete this.okPending,e()):this.okcallback=e},o.prototype.yesno=function(t,e){if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.yesnoPending?(delete this.yesnoPending,e(this.yesnoResponse)):this.yesnocallback=e},o.prototype.ask=function(e,r,o){if(!e||"string"!=typeof e)throw new Error("prompt required");if(!1==r instanceof t)throw new Error("attribute or callback expected");if("function"!=typeof o)throw new Error("callback required");this.askPending?(delete this.askPending,o(this.askResponse)):this.askcallback=o},o.prototype.choose=function(t,e,r){if(!t||"string"!=typeof t)throw new Error("prompt required");if(!1==e instanceof Array)throw new Error("choices array required");if(!e.length)throw new Error("choices array empty");if("function"!=typeof r)throw new Error("callback required");this.choosePending?(delete this.choosePending,r(o.firstMatch(this.chooseResponse,e))):(this.choosecallback=r,this.chooseChoices=e)},o.firstMatch=function(t,e){if(void 0!==t)for(var r=0;r<e.length;r++){var o=e[r].toLowerCase();if(O(o,t.length)==t.toLowerCase())return r}};var f=function(t){if(!1==this instanceof f)throw new Error("new operator required");if(t instanceof d)this.model=t;else{if(!(t instanceof h))throw new Error("argument required: model");this.view=t,this.model=this.view.primaryModel}this.attributes=t.attributes,this._items=[],this._itemIndex=-1};f.prototype.length=function(){return this._items.length},f.prototype.clear=function(){return this._items=[],this._itemIndex=-1,this},f.prototype.get=function(t){if(this._items.length<1)throw new Error("list is empty");for(var e=0;e<this.attributes.length;e++){var r=this.attributes[e].name.toUpperCase(),o=t.toUpperCase(),n=o.split("."),i=r==o;if(2==n.length){o=n[1];var s=n[0],a=this.attributes[e].model.modelType.toUpperCase();i=r==o&&s==a}if(i)return"Date"!=this.attributes[e].type||this._items[this._itemIndex][e]instanceof Date?this._items[this._itemIndex][e]:null===this._items[this._itemIndex][e]||void 0===this._items[this._itemIndex][e]?null:new Date(this._items[this._itemIndex][e])}},f.prototype.set=function(t,e){if(this._items.length<1)throw new Error("list is empty");for(var r=0;r<this.attributes.length;r++){var o=this.attributes[r].name.toUpperCase(),n=t.toUpperCase(),i=n.split("."),s=o==n;if(2==i.length){n=i[1];var a=i[0],c=this.attributes[r].model.modelType.toUpperCase();s=o==n&&a==c}if(s)return void(this._items[this._itemIndex][r]=e)}throw new Error("attribute not valid for list model")},f.prototype.addItem=function(t){var e,r=[];if(t)for(e in t.attributes)r.push(t.attributes[e].value);else for(e in this.attributes)r.push(void 0);return this._items.push(r),this._itemIndex=this._items.length-1,this},f.prototype.removeItem=function(){return this._items.splice(this._itemIndex,1),this._itemIndex--,this},f.prototype.findItemByID=function(t){for(var e=this.moveFirst();e;){if(t==this._items[this._itemIndex][0])return!0;e=this.moveNext()}return!1},f.prototype.indexedItem=function(t){return!(this._items.length<1)&&(!(t<0)&&(!(t>=this._items.length)&&(this._itemIndex=t,!0)))},f.prototype.moveNext=function(){return!(this._items.length<1)&&this.indexedItem(this._itemIndex+1)},f.prototype.movePrevious=function(){return!(this._items.length<1)&&this.indexedItem(this._itemIndex-1)},f.prototype.moveFirst=function(){return!(this._items.length<1)&&this.indexedItem(0)},f.prototype.moveLast=function(){return!(this._items.length<1)&&this.indexedItem(this._items.length-1)},f.prototype.sort=function(t){var e,r=0;for(var o in t)e||(e=o);if(!e)throw new Error("sort order required");for(var n=1==t[e];r<this.attributes.length&&this.attributes[r].name!=e;)r++;this._items.sort(function(t,e){if(n){if(t[r]<e[r])return-1;if(t[r]>e[r])return 1}else{if(t[r]>e[r])return-1;if(t[r]<e[r])return 1}return 0})},n.prototype.toString=function(){switch(this.type){case"Null":return this.type+" Message";default:return this.type+" Message: "+this.contents}},n.getTypes=function(){return["Null","Connected","Error","Sent","Ping","PutModel","PutModelAck","GetModel","GetModelAck","DeleteModel","DeleteModelAck","GetList","GetListAck"].slice(0)};var d=function(e){var r;if(!1==this instanceof d)throw new Error("new operator required");if(this.attributes=[new t("id","ID")],e=e||{},this.modelType=e.modelType||"Model",e.attributes)for(r in e.attributes)e.attributes.hasOwnProperty(r)&&this.attributes.push(e.attributes[r]);var o=_(e,["modelType","attributes"]),n=this.getObjectStateErrors();for(r=0;r<o.length;r++)n.push("invalid property: "+o[r]);if(n.length>1)throw new Error("error creating Model: multiple errors");if(n.length)throw new Error("error creating Model: "+n[0]);this._eventListeners=[],this._errorConditions={}};d._ModelConstructor={},d.prototype.toString=function(){return"a "+this.modelType},d.prototype.copy=function(t){for(var e=0;e<this.attributes.length;e++)this.attributes[e].value=t.attributes[e].value},d.prototype.getObjectStateErrors=function(){if(this.validationErrors=[],this.attributes instanceof Array)if(this.attributes.length<1)this.validationErrors.push("attributes must not be empty");else for(var e=0;e<this.attributes.length;e++)0!==e||this.attributes[e]instanceof t&&"ID"==this.attributes[e].type||this.validationErrors.push("first attribute must be ID"),this.attributes[e]instanceof t||this.validationErrors.push("attribute must be Attribute");else this.validationErrors.push("attributes must be Array");return void 0===this.tags||this.tags instanceof Array||this.validationErrors.push("tags must be Array or null"),this.validationErrors},d.prototype.attribute=function(t){for(var e=0;e<this.attributes.length;e++)if(this.attributes[e].name.toUpperCase()==t.toUpperCase())return this.attributes[e];throw new Error("attribute not found in model: "+t)},d.prototype.get=function(t){for(var e=0;e<this.attributes.length;e++)if(this.attributes[e].name.toUpperCase()==t.toUpperCase())return this.attributes[e].get()},d.prototype.getShortName=function(){for(var t=0;t<this.attributes.length;t++)if("String"==this.attributes[t].type)return this.attributes[t].get();return""},d.prototype.getLongName=function(){return this.getShortName()},d.prototype.getAttributeType=function(t){for(var e=0;e<this.attributes.length;e++)if(this.attributes[e].name.toUpperCase()==t.toUpperCase())return this.attributes[e].type},d.prototype.set=function(t,e){for(var r=0;r<this.attributes.length;r++)if(this.attributes[r].name.toUpperCase()==t.toUpperCase())return this.attributes[r].set(e),void this._emitEvent("StateChange");throw new Error("attribute not valid for model")},d.prototype.validate=function(t){var e,r,o=this,n=0;if("function"!=typeof t)throw new Error("callback is required");o.getObjectStateErrors();for(r in o._errorConditions)o._errorConditions.hasOwnProperty(r)&&o.validationErrors.push(o._errorConditions[r]);if(o.validationErrors.length)return o.validationMessage=o.validationErrors.length>0?o.validationErrors[0]:"",o._emitEvent("StateChange"),void t.call(o);for(e=0;e<o.attributes.length;e++)n++,function(e){setTimeout(function(){e.validate(function(){e.validationErrors.length&&o.validationErrors.push("bush"),0===--n&&(o.validationErrors.length||o._emitEvent("Validate"),o.validationMessage=o.validationErrors.length>0?o.validationErrors[0]:"",o._emitEvent("StateChange"),t.call(o))})},0)}(o.attributes[e])},d.prototype.onEvent=function(t,e){if(!(t instanceof Array)){if("string"!=typeof t)throw new Error("subscription string or array required");t=[t]}if("function"!=typeof e)throw new Error("callback is required");for(var r in t)if(t.hasOwnProperty(r)&&"*"!=t[r]&&!P(["StateChange","Validate"],t[r]))throw new Error("Unknown command event: "+t[r]);return this._eventListeners.push({events:t,callback:e}),this},d.prototype._emitEvent=function(t,e){var r;for(r in this._eventListeners)if(this._eventListeners.hasOwnProperty(r)){var o=this._eventListeners[r];(o.events.length&&"*"===o.events[0]||P(o.events,t))&&o.callback.call(this,t,e)}},d.prototype.setError=function(t,e){if(t=t||"",e=e||"",!t)throw new Error("condition required");if(!e)throw new Error("description required");this._errorConditions[t]=e},d.prototype.clearError=function(t){if(t=t||"",!t)throw new Error("condition required");delete this._errorConditions[t]};var w=function(t){if(!1==this instanceof w)throw new Error("new operator required");t instanceof Array&&(t={tasks:t}),t=t||{};var e,r=_(t,["tasks","tasksNeeded","tasksCompleted"]),o=[];for(e=0;e<r.length;e++)o.push("invalid property: "+r[e]);if(o.length>1)throw new Error("error creating Procedure: multiple errors");if(o.length)throw new Error("error creating Procedure: "+o[0]);for(e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);if(o=this.getObjectStateErrors()){if(o.length>1)throw new Error("error creating Procedure: multiple errors");if(o.length)throw new Error("error creating Procedure: "+o[0])}};w.prototype.getObjectStateErrors=function(){var t,r,o,n;if(this.tasks&&!(this.tasks instanceof Array))return["tasks is not an array"];var i=[];for(t in this.tasks)if(this.tasks.hasOwnProperty(t)){var s=this.tasks[t];for(n=_(s,["label","command","requires","timeout"]),r=0;r<n.length;r++)i.push("invalid task["+t+"] property: "+n[r]);"undefined"!=typeof s.label&&"string"!=typeof s.label&&i.push("task["+t+"].label must be string"),"undefined"==typeof s.command||s.command instanceof e||i.push("task["+t+"].command must be a Command object"),"undefined"==typeof s.requires&&(s.requires=-1),s.requires instanceof Array||(s.requires=[s.requires]);for(r in s.requires)if(s.requires.hasOwnProperty(r)&&null!==s.requires[r])switch(typeof s.requires[r]){case"string":var a=!1;for(o=0;!a&&o<this.tasks.length;o++)s.requires[r]==this.tasks[o].label&&(a=!0);if(!a)throw new Error("missing label: "+s.requires[r]);break;case"number":if(s.requires[r]>=this.tasks.length)throw new Error("missing task #"+s.requires[r]+" for requires in task["+t+"]");if(s.requires[r]<-1)throw new Error("task #"+s.requires[r]+" invalid requires in task["+t+"]");break;default:throw new Error("invalid type for requires in task["+t+"]")}}return i.length?i:null},i.prototype.toString=function(){
  switch(this.type){case"Command":return this.type+" Request: "+this.command;default:return this.type+" Request"}};var m=function(t){if(!1==this instanceof m)throw new Error("new operator required");t=t||{},this.storeType=t.storeType||"Store",this.name=t.name||"a "+this.storeType,this.storeProperty={isReady:!1,canGetModel:!1,canPutModel:!1,canDeleteModel:!1,canGetList:!1};for(var e=_(t,["name","storeType"]),r=[],o=0;o<e.length;o++)r.push("invalid property: "+e[o]);if(r.length>1)throw new Error("error creating Store: multiple errors");if(r.length)throw new Error("error creating Store: "+r[0])};m.prototype.toString=function(){return this.name=="a "+this.storeType?this.name:this.storeType+": "+this.name},m.prototype.getServices=function(){return this.storeProperty},m.prototype.onConnect=function(t,e){if("string"!=typeof t)throw new Error("argument must a url string");if("function"!=typeof e)throw new Error("argument must a callback");e(this,void 0)},m.prototype.getModel=function(){throw new Error(this.storeType+" does not provide getModel")},m.prototype.putModel=function(){throw new Error("Store does not provide putModel")},m.prototype.deleteModel=function(){throw new Error("Store does not provide deleteModel")},m.prototype.getList=function(){throw new Error("Store does not provide getList")},m.prototype.getViewList=function(t,e,r,o){function n(e,r){function o(){if(!s)return void i(t);for(t.addItem(),a=0;a<t.attributes.length;a++){var e=t.attributes[a];e.model==t.model&&t.set(e.name,h.get(e.name))}u=[];for(var r in t.view.relatedModels)t.view.relatedModels.hasOwnProperty(r)&&u.push(r);n()}function n(){if(!u.length)return s=h.moveNext(),void o();var e=u.shift(),r=t.view.relatedModels[e],a=h.get(r.id.name);r.model.set("id",a),c.getModel(r.model,function(e,r){if("undefined"!=typeof r)return void i(r);for(var o=0;o<t.attributes.length;o++){var s=t.attributes[o];s.model==e&&t.set(e.modelType+"."+s.name,e.get(s.name))}n()})}if(t.clear(),"undefined"!=typeof r)return void i(t,r);var s=h.moveFirst(),u=[];o()}var i,s,a,c=this;if("function"==typeof o?(i=o,s=r):i=r,!(t instanceof f))throw new Error("argument must be a List");if(!t.view)throw new Error("List is Model type use getList");if(!(e instanceof Object))throw new Error("filter argument must be Object");if("function"!=typeof i)throw new Error("callback required");var h=new f(t.model);s?this.getList(h,e,s,n):this.getList(h,e,n)},s.prototype.toString=function(){return"Text: '"+(this.contents||"")+"'"},s.prototype.get=function(){return this.contents},s.prototype.set=function(t){return this.contents=t,this._emitEvent("StateChange"),this.contents},s.prototype._emitEvent=function(t){var e;for(e in this._eventListeners)if(this._eventListeners.hasOwnProperty(e)){var r=this._eventListeners[e];(r.events.length&&"*"===r.events[0]||P(r.events,t))&&r.callback.call(this,t)}},s.prototype.onEvent=function(t,e){if(!(t instanceof Array)){if("string"!=typeof t)throw new Error("subscription string or array required");t=[t]}if("function"!=typeof e)throw new Error("callback is required");for(var r in t)if(t.hasOwnProperty(r)&&"*"!=t[r]&&!P(["StateChange"],t[r]))throw new Error("Unknown command event: "+t[r]);return this._eventListeners.push({events:t,callback:e}),this},s.prototype.offEvent=function(){this._eventListeners=[]},a.showLog=!1,a.messageHandlers={},a.setMessageHandler=function(t,e){a.messageHandlers[t]=e},a.hostMessageProcess=function(t,e){a.showLog&&console.log("Transport.hostMessageProcess "+JSON.stringify(t)),a.messageHandlers[t.type]?a.messageHandlers[t.type](t.contents,e):e(!0)},a.prototype.sendRaw=function(t){this.socket.send(t)},a.prototype.onRaw=function(t){this.rawCallBack=t},a.prototype.send=function(t,e){var r=this;if("undefined"==typeof t)throw new Error("message required");if(!(t instanceof n))throw new Error("parameter must be instance of Message");if("undefined"!=typeof e&&"function"!=typeof e)throw new Error("argument must a callback");return this.connected?void("undefined"!=typeof e?(a.showLog&&console.log("Transport emit "+JSON.stringify(t)),r.socket.emit("ackmessage",t,function(t){e.call(r,t)})):(a.showLog&&console.log("Transport send "+JSON.stringify(t)),r.socket.send(t))):void e.call(r,new n("Error","not connected"))},a.prototype.close=function(){if(!this.connected)throw new Error("not connected");this.socket.disconnect()},h.prototype.toString=function(){return this.primaryModel+" View"};var y=function(t){if(!1==this instanceof o)throw new Error("new operator required");t=t||{},t.name=t.name||"(unnamed)",t.description=t.description||"a REPLInterface",t.vendor=t.vendor||null;var e,r=_(t,["name","description","vendor"]),n=[];for(e=0;e<r.length;e++)n.push("invalid property: "+r[e]);if(n.length>1)throw new Error("error creating Interface: multiple errors");if(n.length)throw new Error("error creating Interface: "+n[0]);this.startcallback=null,this.stopcallback=null,this.mocks=[],this.mockPending=!1,this.navStack=[];for(e in t)this[e]=t[e]};y.prototype=Object.create(o.prototype),y.prototype.toString=function(){return this.description},y.prototype.canMock=function(){return!0},y.prototype.doMock=function(){var t,e;if(this.mockPending=!1,!(this.mocks.length<1)){var r=this.mocks.shift();if("ok"==r.type)return void(this.okcallback?(t=this.okcallback,delete this.okcallback,t()):this.okPending=!0);if("yes"==r.type||"no"==r.type||"cancel"==r.type){switch(r.type){case"yes":e=!0;break;case"no":e=!1;break;case"cancel":e=void 0}return void(this.yesnocallback?(t=this.yesnocallback,delete this.yesnocallback,t(e)):(this.yesnoPending=!0,this.yesnoResponse=e))}if("ask"==r.type)return void(this.askcallback?(t=this.askcallback,delete this.askcallback,t(r.value)):(this.askPending=!0,this.askResponse=r.value));if("choose"==r.type)return void(this.choosecallback?(t=this.choosecallback,delete this.choosecallback,t(o.firstMatch(r.value,this.chooseChoices))):(this.choosePending=!0,this.chooseResponse=r.value));this.dispatch(r),this.mockPending=!0;var n=this;setTimeout(function(){n.doMock()},0)}},y.prototype.mockRequest=function(t){if(!(t instanceof Array||t instanceof i))throw new Error("missing request parameter");t instanceof Array||(t=[t]);var e;for(e=0;e<t.length;e++)if(!1==t[e]instanceof i)throw new Error("invalid request parameter");for(e=0;e<t.length;e++)this.mocks.push(t[e]);this.mockPending||this.doMock()},y.prototype.start=function(t,e,r){if(!(t instanceof v))throw new Error("Application required");if(!(e instanceof b))throw new Error("presentation required");if("function"!=typeof r)throw new Error("callback required");this.application=t,this.presentation=e,this.startcallback=r,this.evaluateInput()},y.prototype.stop=function(t){if("function"!=typeof t)throw new Error("callback required")},y.prototype.dispatch=function(t,e){if(!1==t instanceof i)throw new Error("Request required");if(e&&"function"!=typeof e)throw new Error("response callback is not a function");this.application&&this.application.dispatch(t)||this.startcallback&&this.startcallback(t)},y.prototype.notify=function(t){if(!1==t instanceof n)throw new Error("Message required");this._Output(t)},y.prototype.render=function(r,o,n){if(!1==r instanceof b)throw new Error("Presentation object required");if("string"!=typeof o)throw new Error("presentationMode required");if(!P(e.getPresentationModes(),o))throw new Error("Invalid presentationMode: "+o);if(n&&"function"!=typeof n)throw new Error("optional second argument must a commandRequest callback function");var i,s,a=r.get("contents"),c=0;switch(o){case"View":for(i=0;i<a.length;i++)a[i]instanceof t&&a[i].label.length>c&&(c=a[i].label.length);for(i=0;i<a.length;i++)s=a[i],s instanceof t?this._Output(L(s.label,c)+": "+s.value):this._Output(s);break;case"Edit":for(this.editPresentationContents=a.slice();this.editPresentationContents.length&&!(this.editPresentationContents[0]instanceof t);){var h=this.editPresentationContents.shift();h instanceof e||this._Output(h)}this.editPresentationContents.length&&this.editPresentationContents[0]instanceof t&&this._setPrompt(this.editPresentationContents[0].label+": "),this.editPresentationContents.length||delete this.editPresentationContents;break;default:throw new Error("presentationMode not handled: "+o)}},y.prototype.info=function(t){if(!t||"string"!=typeof t)throw new Error("text required");this._Output(t)},y.prototype.ok=function(t,e){if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this._Output(t),this.okPending?(delete this.okPending,e()):this.okcallback=e},y.prototype.yesno=function(t,e){if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.yesnoPrompt=t,this._setPrompt(this.yesnoPrompt),this.yesnoPending?(delete this.yesnoPending,e(this.yesnoResponse)):this.yesnocallback=e},y.prototype.ask=function(e,r,o){if(!e||"string"!=typeof e)throw new Error("prompt required");if(!1==r instanceof t)throw new Error("attribute or callback expected");if("function"!=typeof o)throw new Error("callback required");this.askPrompt=e,this._setPrompt(e),this.askPending?(delete this.askPending,o(this.askResponse)):this.askcallback=o},y.prototype.choose=function(t,e,r){if(!t||"string"!=typeof t)throw new Error("prompt required");if(!1==e instanceof Array)throw new Error("choices array required");if(!e.length)throw new Error("choices array empty");if("function"!=typeof r)throw new Error("callback required");this.choosePrompt=t,this._Output(t);for(var n=0;n<e.length;n++)this._Output("  "+e[n]);this._setPrompt("Choice? "),this.choosePending?(delete this.choosePending,r(o.firstMatch(this.chooseResponse,e))):(this.choosecallback=r,this.chooseChoices=e)},y.prototype.evaluateInput=function(t){var e=this;void 0===t&&(t=""),this._evaluateInput(t),setTimeout(function(){var t=e.application?e.application.get("brand"):"?";!e.promptText&&e.application&&e.application.primaryInterface&&e._ShowNav(),e.promptText&&(t=e.promptText,delete e.promptText),e.capturePromptcallback&&e.capturePromptcallback(t)},10)},y.prototype._evaluateInput=function(r){var n,i,s,a=(""+r).toUpperCase();if(this.okcallback)return n=this.okcallback,delete this.okcallback,void n();if(this.yesnocallback)return"Y"==a||"YES"==a?(n=this.yesnocallback,delete this.yesnocallback,void n(!0)):"N"==a||"NO"==a?(n=this.yesnocallback,delete this.yesnocallback,void n(!1)):0===r.length?(n=this.yesnocallback,delete this.yesnocallback,void n()):(this._Output("yes or no response required"),void this._setPrompt(this.yesnoPrompt));if(this.askcallback)return n=this.askcallback,delete this.askcallback,void n(r);if(this.choosecallback){n=this.choosecallback;var c=o.firstMatch(r,this.chooseChoices);if(c)delete this.choosecallback,n(c);else if(r.length>0){for(this.application.info('"'+r+'" not valid'),this._Output(this.choosePrompt),i=0;i<this.chooseChoices.length;i++)this._Output("  "+this.chooseChoices[i]);this._setPrompt("Choice? ")}else delete this.choosecallback,n()}else{if(this.editPresentationContents){if(!(this.editPresentationContents.length&&this.editPresentationContents[0]instanceof t))throw this.editPresentationContents.length||delete this.editPresentationContents,new Error("editPresentationContents expected attribute");for(s=this.editPresentationContents.shift(),r.length&&(s.value=r);this.editPresentationContents.length&&!(this.editPresentationContents[0]instanceof t);)s=this.editPresentationContents.shift(),s instanceof e||this._Output(s);return this.editPresentationContents.length&&this.editPresentationContents[0]instanceof t&&this._setPrompt(this.editPresentationContents[0].label+": "),void(this.editPresentationContents.length||delete this.editPresentationContents)}if(this.presentation){var h=this.presentation.get("contents");if(this.navStack.length>0){var u=this.navStack[this.navStack.length-1];h=u.contents}for(i=0;i<h.length;i++){var l=h[i];if(l instanceof e){var p=l.name.toUpperCase();if(r.length&&O(p,a.length)==a){switch(l.type){case"Stub":this.info(l.description+" not available.");break;case"Menu":this.navStack.push(l);break;case"Presentation":l.presentationMode="Edit",l.execute(this);break;default:l.execute()}return}}}return void(r.length>0?this.application.info('"'+r+'" not valid'):this.navStack.pop())}this._Output("input ignored: "+r)}},y.prototype._ShowNav=function(){var t,r=this.application?this.application.get("brand"):"?",o=this.presentation.get("contents"),n="",i="",s="";if(this.navStack.length>0){var a=this.navStack[this.navStack.length-1];for(n=a.name.replace(/\s/g,"")+": ",o=a.contents,t=0;t<this.navStack.length;t++)r+=" / "+this.navStack[t].name.replace(/\s/g,"")}for(t=0;t<o.length;t++){var c=o[t];c instanceof e&&(i+=s+c.name.replace(/\s/g,""),s=", ")}this.application.info(n+i),this._setPrompt(r+">")},y.prototype.captureOutput=function(t){this.captureOutputcallback=t},y.prototype.capturePrompt=function(t){this.capturePromptcallback=t},y.prototype._setPrompt=function(t){this.promptText=t},y.prototype._Output=function(t){this.captureOutputcallback&&this.captureOutputcallback(t)};var v=function(e){if(!1==this instanceof v)throw new Error("new operator required");e=e||{},e.attributes||(e.attributes=[]),e.attributes.push(new t({name:"name",type:"String(20)"})),e.attributes.push(new t({name:"brand",type:"String"})),e["interface"]&&(this.setInterface(e["interface"]),delete e["interface"]),d.call(this,e),this.modelType="Application",this.set("name","newApp"),this.set("brand","NEW APP")};v.prototype=Object.create(d.prototype),d._ModelConstructor.Application=v,v.prototype.start=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("error starting application: interface not set");if("function"!=typeof t)throw new Error("callback required");var e=this;this.startcallback=t,this.presentation||(this.presentation=new b),this.primaryInterface.start(e,this.presentation,function(t){"Command"==t.type?t.command.execute():e.startcallback&&e.startcallback(t)})},v.prototype.dispatch=function(t,e){if(!1==t instanceof i)throw new Error("Request required");if(e&&"function"!=typeof e)throw new Error("response callback is not a function");return"Command"==t.type?(t.command.execute(),!0):!!this.startcallback&&(this.startcallback(t),!0)},v.prototype.setInterface=function(t){if(!1==t instanceof o)throw new Error("instance of Interface a required parameter");this.primaryInterface=t},v.prototype.getInterface=function(){return this.primaryInterface},v.prototype.setPresentation=function(t){if(!1==t instanceof b)throw new Error("instance of Presentation a required parameter");this.presentation=t},v.prototype.getPresentation=function(){return this.presentation},v.prototype.info=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("text parameter required");this.primaryInterface.info(t)},v.prototype.done=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("text parameter required");this.primaryInterface.done(t)},v.prototype.warn=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("text parameter required");this.primaryInterface.warn(t)},v.prototype.err=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("text parameter required");this.primaryInterface.err(t)},v.prototype.ok=function(t,e){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.primaryInterface.ok(t,e)},v.prototype.yesno=function(t,e){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.primaryInterface.yesno(t,e)},v.prototype.ask=function(e,r,n){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!e||"string"!=typeof e)throw new Error("prompt required");if("function"==typeof r)return void this.primaryInterface.ask(e,new t({name:"default"}),r);if(!1==r instanceof t)throw new Error("attribute or callback expected");if("function"!=typeof n)throw new Error("callback required");this.primaryInterface.ask(e,r,n)},v.prototype.choose=function(t,e,r){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("prompt required");if(!1==e instanceof Array)throw new Error("choices array required");if(!e.length)throw new Error("choices array empty");if("function"!=typeof r)throw new Error("callback required");this.primaryInterface.choose(t,e,r)};var g=function(e){if(!1==this instanceof g)throw new Error("new operator required");if("string"==typeof e){var r=e;e={},e.contents=r}e=e||{},e.attributes||(e.attributes=[]);var o=e.logType||"Text",n=e.importance||"Info",i=e.contents||"(no text)";if(!P(["Text","Delta"],o))throw new Error("Unknown log type: "+o);"undefined"!=typeof e.logType&&delete e.logType,"undefined"!=typeof e.importance&&delete e.importance,"undefined"!=typeof e.contents&&delete e.contents,e.attributes.push(new t({name:"dateLogged",type:"Date",value:new Date})),e.attributes.push(new t({name:"logType",type:"String",value:o})),e.attributes.push(new t({name:"importance",type:"String",value:n})),"Delta"==o?e.attributes.push(new t({name:"contents",type:"Object",value:i})):e.attributes.push(new t({name:"contents",type:"String",value:i})),d.call(this,e),this.modelType="Log"};g.prototype=Object.create(d.prototype),d._ModelConstructor.Log=g,g.prototype.toString=function(){return"Delta"==this.get("logType")?this.get("importance")+": (delta)":this.get("importance")+": "+this.get("contents")};var b=function(e){if(!1==this instanceof b)throw new Error("new operator required");e=e||{},e.attributes||(e.attributes=[]),e.attributes.push(new t({name:"name",type:"String"})),e.attributes.push(new t({name:"modelName",type:"String"})),e.attributes.push(new t({name:"contents",type:"Object",value:[]})),d.call(this,e),this.modelType="Presentation"};b.prototype=Object.create(d.prototype),d._ModelConstructor.Presentation=b,b.prototype.getObjectStateErrors=function(r){var o;if(this.validationErrors=d.prototype.getObjectStateErrors.call(this),!r&&0===this.validationErrors.length){var n=this.get("contents"),i=!1;if(n instanceof Array){for(o=0;o<n.length;o++)n[o]instanceof s||n[o]instanceof e||n[o]instanceof t||n[o]instanceof f||"string"==typeof n[o]||(i=!0);i&&this.validationErrors.push("contents elements must be Text, Command, Attribute, List or string")}else this.validationErrors.push("contents must be Array")}return this.validationMessage=this.validationErrors.length>0?this.validationErrors[0]:"",this.validationErrors},b.prototype.validate=function(e){function r(){h++,this.validationMessage&&(a=!0),c==h&&(a&&n.validationErrors.push("contents has validation errors"),o())}function o(){n.validationMessage=n.validationErrors.length>0?n.validationErrors[0]:"",e()}var n=this;if("function"!=typeof e)throw new Error("callback is required");this.getObjectStateErrors();var i;for(i in this._errorConditions)this._errorConditions.hasOwnProperty(i)&&this.validationErrors.push(this._errorConditions[i]);var s,a=!1,c=0,h=0,u=this.get("contents");for(u instanceof Array||(u=[]),s=0;s<u.length;s++)u[s]instanceof t&&c++;for(s=0;s<u.length;s++)u[s]instanceof t&&u[s].validate(r);u.length<1&&o()};var E=function(e){if(!1==this instanceof E)throw new Error("new operator required");e=e||{},e.attributes||(e.attributes=[]);var r=new t.ModelID(new k);e.attributes.push(new t({name:"userID",type:"Model",value:r})),e.attributes.push(new t({name:"dateStarted",type:"Date",value:new Date})),e.attributes.push(new t({name:"passCode",type:"String(20)"})),e.attributes.push(new t({name:"active",type:"Boolean"})),e.attributes.push(new t({name:"ipAddress",type:"String"})),d.call(this,e),this.modelType="Session",this.set("active",!1)};E.prototype=Object.create(d.prototype),d._ModelConstructor.Session=E,E.prototype.startSession=function(e,r,o,n,i){if(!1==e instanceof m)throw new Error("store required");if("string"!=typeof r)throw new Error("userName required");if("string"!=typeof o)throw new Error("password required");if("string"!=typeof n)throw new Error("ip required");if("function"!=typeof i)throw new Error("callback required");var s=this,a=new k;e.getList(new f(a),{name:r,password:o},function(r,o){if(o)return void i(o);if(1!=r.length())return void i(new Error("login not found"));for(var a="",c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",h=0;h<20;h++)a+=c.charAt(Math.floor(Math.random()*c.length));r.moveFirst(),r.model.set("id",r.get("id")),r.model.set("name",r.get("name")),s.set("userID",new t.ModelID(r.model)),s.set("active",!0),s.set("passCode",a),s.set("ipAddress",n),e.putModel(s,function(t,e){i(e,t)})})},E.prototype.resumeSession=function(t,e,r,o){if(!1==t instanceof m)throw new Error("store required");if("string"!=typeof e)throw new Error("ip required");if("string"!=typeof r)throw new Error("passCode required");if("function"!=typeof o)throw new Error("callback required");var n=this;t.getList(new f(n),{ipAddress:e,passCode:r},function(t,e){return e?void o(e):1!=t.length()?void o(new Error("session not resumed")):(t.moveFirst(),n.set("id",t.get("id")),n.set("userID",t.get("userID")),n.set("dateStarted",t.get("dateStarted")),n.set("passCode",t.get("passCode")),n.set("active",t.get("active")),n.set("ipAddress",t.get("ipAddress")),void o(e,n))})},E.prototype.endSession=function(t,e){if(!1==t instanceof m)throw new Error("store required");if("function"!=typeof e)throw new Error("callback required");this.get("active")&&this.get("id")||e(this),this.set("active",!1),t.putModel(this,function(t,r){e(r,t)})};var k=function(e){if(!1==this instanceof k)throw new Error("new operator required");e=e||{},e.attributes||(e.attributes=[]),e.attributes.push(new t({name:"name",type:"String(20)"})),e.attributes.push(new t({name:"active",type:"Boolean"})),e.attributes.push(new t({name:"password",type:"String(20)"})),e.attributes.push(new t({name:"firstName",type:"String(35)"})),e.attributes.push(new t({name:"lastName",type:"String(35)"})),e.attributes.push(new t({name:"email",type:"String(20)"})),d.call(this,e),this.modelType="User",this.set("active",!1)};k.prototype=Object.create(d.prototype),d._ModelConstructor.User=k,u.prototype=Object.create(d.prototype),d._ModelConstructor.Workspace=u;var q=function(t){if(!1==this instanceof q)throw new Error("new operator required");t=t||{},this.storeType=t.storeType||"MemoryStore",this.name=t.name||"a "+this.storeType,this.storeProperty={isReady:!0,canGetModel:!0,canPutModel:!0,canDeleteModel:!0,canGetList:!0},this.data=[],this.idCounter=0;for(var e=_(t,["name","storeType"]),r=[],o=0;o<e.length;o++)r.push("invalid property: "+e[o]);if(r.length>1)throw new Error("error creating Store: multiple errors");if(r.length)throw new Error("error creating Store: "+r[0])};q.prototype=Object.create(m.prototype),q.prototype.getModel=function(t,e){var r,o;if(!(t instanceof d))throw new Error("argument must be a Model");if(t.getObjectStateErrors().length)throw new Error("model has validation errors");if(!t.attributes[0].value)throw new Error("ID not set");if("function"!=typeof e)throw new Error("callback required");var n=-1;for(r=0;r<this.data.length;r++)this.data[r][0]==t.modelType&&(n=r);if(n<0)return void e(t,new Error("model not found in store"));var i=t.get("id"),s=this.data[n][1],a=-1;for(r=0;a<0&&r<s.length;r++)s[r][0]==i&&(a=r);if(a<0)return void e(t,new Error("id not found in store"));var c=s[a][1];for(o in t.attributes)t.attributes[o].value=c[t.attributes[o].name];e(t,void 0)},q.prototype.putModel=function(t,e){var r,o,n,i,s,a,c;if(!(t instanceof d))throw new Error("argument must be a Model");if(t.getObjectStateErrors().length)throw new Error("model has validation errors");if("function"!=typeof e)throw new Error("callback required");if(n=t.get("ID")){for(i=-1,r=0;r<this.data.length;r++)this.data[r][0]==t.modelType&&(i=r);if(i<0)return void e(t,new Error("model not found in store"));var h=-1;n=t.get("id");var u=this.data[i][1];for(r=0;h<0&&r<u.length;r++)u[r][0]==n&&(h=r);if(h<0)return void e(t,new Error("id not found in store"));s={};for(o in t.attributes)a=t.attributes[o].name,c=t.attributes[o].value,s[a]=c;u[h][1]=s,e(t,void 0)}else{for(i=-1,r=0;r<this.data.length;r++)this.data[r][0]==t.modelType&&(i=r);i<0&&(this.data.push([t.modelType,[]]),i=this.data.length-1);var l=++this.idCounter;t.set("id",l),s={};for(o in t.attributes)a=t.attributes[o].name,c=t.attributes[o].value,s[a]=c;this.data[i][1].push([l,s]),e(t,void 0)}},q.prototype.deleteModel=function(t,e){var r,o;if(!(t instanceof d))throw new Error("argument must be a Model");if(t.getObjectStateErrors().length)throw new Error("model has validation errors");if("function"!=typeof e)throw new Error("callback required");var n=-1;for(r=0;r<this.data.length;r++)this.data[r][0]==t.modelType&&(n=r);if(n<0)return void e(t,new Error("model not found in store"));var i=-1,s=t.get("id"),a=this.data[n][1];for(r=0;i<0&&r<a.length;r++)a[r][0]==s&&(i=r);if(i<0)return void e(t,new Error("id not found in store"));var c=a.splice(i,1)[0][1];for(o in t.attributes)"id"==t.attributes[o].name?t.attributes[o].value=void 0:t.attributes[o].value=c[t.attributes[o].name];e(t,void 0)},q.prototype.getList=function(t,e,r,o){var n,i,s;if("function"==typeof o?(n=o,i=r):n=r,!(t instanceof f))throw new Error("argument must be a List");if(t.view)throw new Error("List is View type use getViewList");if(!(e instanceof Object))throw new Error("filter argument must be Object");if("function"!=typeof n)throw new Error("callback required");var a=-1;for(s=0;s<this.data.length;s++)this.data[s][0]==t.model.modelType&&(a=s);if(a<0)return void n(t);t.clear();var c=this.data[a][1];for(s=0;s<c.length;s++){var h=!0;for(var u in e)e.hasOwnProperty(u)&&(e[u]instanceof RegExp?e[u].test(c[s][1][u])||(h=!1):e[u]!=c[s][1][u]&&(h=!1));if(h){var l=[];for(var p in c[s][1])l.push(c[s][1][p]);t._items.push(l)}}t._itemIndex=t._items.length-1,i&&t.sort(i),n(t)};var P=function(t,e){for(var r=0;r<t.length;r++)if(t[r]===e)return!0;return!1},M=function(t){function e(){}if(null===t)throw new TypeError;if(Object.create)return Object.create(t);var r=typeof t;if("object"!==r&&"function"!=typeof r)throw new TypeError;return e.prototype=t,new e},_=function(t,e){var r=[];for(var o in t)t.hasOwnProperty(o)&&(P(e,o)||r.push(o));return r},C=function(t){return d._ModelConstructor[t]||d},S=function(t){var e=C(t);return new e},O=function(t,e){return t.substring(0,e)},I=function(t,e){return t.substring(t.length-e,t.length)},T=function(t,e){var r=(t.length-e)/2;return t.substring(r,r+e)},x=function(t){return t.replace(/^\s+|\s+$/g,"")},A=function(t){return t.replace(/^\s+/,"")},R=function(t){return t.replace(/\s+$/,"")},L=function(t,e,r){r=r||" ";var o=""+t;if(o.length>e)return O(o,e);for(;o.length<e;)o=r+o;return o},D=function(t,e,r){r=r||" ";var o=""+t;if(o.length>e)return I(o,e);for(;o.length<e;)o+=r;return o},j=function(t,e,r){r=r||" ";var o=""+t,n=e-o.length;if(o.length>e)return T(o,e);var i=o.length+Math.floor(n/2);return o=L(o,i,r),o=D(o,e,r)};p.STORE=p.STORE||{},p.STORE.REMOTE=function(){return{version:"0.0.26",RemoteStore:N}};var N=function(t){if(!1==this instanceof N)throw new Error("new operator required");t=t||{},this.storeType=t.storeType||"RemoteStore",this.name=t.name||"a "+this.storeType,this.storeProperty={isReady:!1,canGetModel:!0,canPutModel:!0,canDeleteModel:!0,canGetList:!0};for(var e=_(t,["name","storeType"]),r=[],o=0;o<e.length;o++)r.push("invalid property: "+e[o]);if(r.length>1)throw new Error("error creating Store: multiple errors");if(r.length)throw new Error("error creating Store: "+r[0]);N.transport&&(this.storeProperty.isReady=!0,this.transport=N.transport)};N.prototype=Object.create(m.prototype),N.stripModel=function(t){var e={};for(var r in t)if(t.hasOwnProperty(r))if("modelType"==r)e[r]=t[r];else if("attributes"==r){var o=t[r],n=[];for(var i in o)if(o.hasOwnProperty(i)){var s=o[i],a={};a.name=s.name,a.type=s.type,a.value=s.value,n.push(a)}e[r]=n}return e},N.prototype.onConnect=function(t,e,r){if("string"!=typeof t)throw new Error("argument must a url string");if("function"!=typeof e)throw new Error("argument must a callback");var o=this;try{o.transport=new a(t,function(t){return"Error"==t.type?(console.log("Transport connect error: "+o.name),void e(void 0,new Error(t.contents))):"Connected"==t.type?(o.storeProperty.isReady=!0,N.transport=o.transport,void e(o)):(console.log("Transport unexpected message type: "+o.name),void e(void 0,new Error("unexpected message type: "+t.type)))})}catch(n){e(void 0,n)}},N.prototype.getModel=function(t,e){if(!(t instanceof d))throw new Error("argument must be a Model");if(t.getObjectStateErrors().length)throw new Error("model has validation errors");if(!t.attributes[0].value)throw new Error("ID not set");if("function"!=typeof e)throw new Error("callback required");this.transport.send(new n("GetModel",N.stripModel(t)),function(r){if("GetModelAck"==r.type){if("string"==typeof r.contents)return void e(t,r.contents);for(var o=r.contents.attributes,n=0;n<t.attributes.length;n++)for(var i=t.attributes[n],s=t.attributes[n].name,a=!1,h=0;h<o.length;h++){var u=o[h],l=u.name;if(l==s){if(void 0===u.value||null===u.value)i.value=null;else if("Date"==i.type)try{i.value=new Date(u.value)}catch(p){i.value=null}else i.value=u.value;a=!0}a||(i.value=null)}"string"==typeof c?e(t,c):e(t)}else e(t,Error(r))})},N.prototype.putModel=function(e,r){if(!(e instanceof d))throw new Error("argument must be a Model");if(e.getObjectStateErrors().length)throw new Error("model has validation errors");if("function"!=typeof r)throw new Error("callback required");this.transport.send(new n("PutModel",N.stripModel(e)),function(o){if("PutModelAck"==o.type){var n=o.contents;e.attributes=[];for(var i in n.attributes)if(n.attributes.hasOwnProperty(i)){var s;if("Model"==n.attributes[i].type){var a=S(n.attributes[i].modelType),c=new t.ModelID(a);c.value=n.attributes[i].value.value,n.attributes[i].value.name&&(c.name=n.attributes[i].value.name),s=new t({name:n.attributes[i].name,type:n.attributes[i].type,value:c})}else s=new t(n.attributes[i].name,n.attributes[i].type),s.value=n.attributes[i].value;e.attributes.push(s)}"string"==typeof n?r(e,n):r(e)}else r(e,Error(o))})},N.prototype.deleteModel=function(e,r){if(!(e instanceof d))throw new Error("argument must be a Model");if(e.getObjectStateErrors().length)throw new Error("model has validation errors");if("function"!=typeof r)throw new Error("callback required");this.transport.send(new n("DeleteModel",N.stripModel(e)),function(o){if("DeleteModelAck"==o.type){var n=o.contents;e.attributes=[];for(var i in n.attributes)if(n.attributes.hasOwnProperty(i)){var s=new t(n.attributes[i].name,n.attributes[i].type);s.value=n.attributes[i].value,e.attributes.push(s)}"string"==typeof n?r(e,n):r(e)}else r(e,Error(o))})},N.prototype.getList=function(t,e,r,o){var i,s;if("function"==typeof o?(i=o,s=r):i=r,!(t instanceof f))throw new Error("argument must be a List");if(!(e instanceof Object))throw new Error("filter argument must be Object");if("function"!=typeof i)throw new Error("callback required");for(var a in e)e.hasOwnProperty(a)&&e[a]instanceof RegExp&&(e[a]=e[a].source,e[a]="RegExp:"+e[a]);var c={},h=N.stripModel(t.model);c._itemIndex=t._itemIndex,c._items=t._items,c.model=h,c.attributes=h.attributes,this.transport.send(new n("GetList",{list:c,filter:e,order:s}),function(e){"GetListAck"==e.type?(t._items=e.contents._items,t._itemIndex=e.contents._itemIndex,i(t)):i(t,Error(e))})},"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=p),exports.TGI=p):l.TGI=p;
  }).call(this);