Comparing version 0.4.4 to 0.4.5
136
clib/dpd.js
(function ($) { | ||
if(!$) throw 'dpd.js depends on jQuery.ajax - you must include it before loading dpd.js'; | ||
if(!$) throw Error('dpd.js depends on jQuery.ajax - you must include it before loading dpd.js'); | ||
@@ -9,3 +9,16 @@ // global namespace | ||
, resources = /*resources*/ | ||
, contentType = 'application/json'; | ||
, contentType = 'application/json' | ||
, rootUrl = /*rootUrl*/; | ||
function errorCallback(fn) { | ||
return function (err) { | ||
fn && fn(null, JSON.parse(err.responseText)); | ||
} | ||
} | ||
function successCallback(fn) { | ||
return function (res) { | ||
fn && fn(res); | ||
} | ||
} | ||
@@ -26,15 +39,13 @@ while(r = resources.shift()){ | ||
return $.ajax({ | ||
url: r.path + q, | ||
url: rootUrl + r.path + q, | ||
type: 'GET', | ||
contentType: contentType, | ||
success: function (res) { | ||
fn && fn(res); | ||
fn && fn(res || []); | ||
}, | ||
error: function (err) { | ||
fn && fn(null, JSON.parse(err)); | ||
} | ||
error: errorCallback(fn) | ||
}); | ||
} | ||
})(r), | ||
first: (function (r) { | ||
getOne: (function (r) { | ||
return function (query, fn) { | ||
@@ -46,6 +57,12 @@ if(!fn) { | ||
var q = (query && ('?q=' + JSON.stringify(query))) || ''; | ||
var q = ''; | ||
if (typeof query === 'string') { | ||
q = '/' + query; //Id | ||
} else if (query) { | ||
q = '?q=' + JSON.stringify(query); | ||
} | ||
return $.ajax({ | ||
url: r.path + q, | ||
url: rootUrl + r.path + q, | ||
type: 'GET', | ||
@@ -56,9 +73,9 @@ contentType: contentType, | ||
fn && fn(res[0]); | ||
} else if (typeof res.length !== 'undefined') { | ||
fn && fn(null, {message: 'not found', status: 404}); | ||
} else { | ||
fn && fn(null, {message: 'not found', status: 404}); | ||
fn && fn(res); | ||
} | ||
}, | ||
error: function (err) { | ||
fn && fn(JSON.parse(err)); | ||
} | ||
error: errorCallback(fn) | ||
}); | ||
@@ -69,32 +86,58 @@ } | ||
return function (obj, fn) { | ||
if (typeof obj === 'string') { throw Error("save() does not take an id. Did you mean to use put()?"); } | ||
return $.ajax({ | ||
url: r.path + (obj._id ? ('/' + obj._id) : ''), | ||
url: rootUrl + r.path + (obj._id ? ('/' + obj._id) : ''), | ||
type: 'POST', | ||
contentType: contentType, | ||
data: JSON.stringify(obj), | ||
success: function (res) { | ||
fn && fn(res); | ||
}, | ||
error: function (err) { | ||
fn && fn(null, err); | ||
} | ||
success: successCallback(fn), | ||
error: errorCallback(fn) | ||
}); | ||
} | ||
})(r), | ||
post: (function(r) { | ||
return function (obj, fn) { | ||
if (obj && obj._id) { throw Error("Cannot post() an object with an _id. Did you mean to use save() or put()?"); } | ||
return $.ajax({ | ||
url: rootUrl + r.path, | ||
type: 'POST', | ||
contentType: contentType, | ||
data: JSON.stringify(obj), | ||
success: successCallback(fn), | ||
error: errorCallback(fn) | ||
}); | ||
} | ||
})(r), | ||
put: (function(r) { | ||
return function (id, obj, fn) { | ||
if (typeof id !== 'string') { | ||
obj = arguments[0]; //reorder parameters | ||
fn = arguments[1]; | ||
id = obj && obj._id; | ||
} | ||
if (!id) { throw Error("id must be provided!"); } | ||
return $.ajax({ | ||
url: rootUrl + r.path + '/' + id, | ||
type: 'PUT', | ||
contentType: contentType, | ||
data: JSON.stringify(obj), | ||
success: successCallback(fn), | ||
error: errorCallback(fn) | ||
}); | ||
} | ||
})(r), | ||
del: (function (r) { | ||
return function (query, fn) { | ||
if(!fn) fn = query; | ||
return function (id, fn) { | ||
if (typeof id !== 'string') {throw Error("id must be provided!");} | ||
var q = query && ('?q=' + JSON.stringify(query)); | ||
var q = '/' + id; | ||
return $.ajax({ | ||
url: r.path + q, | ||
url: rootUrl + r.path + q, | ||
type: 'DELETE', | ||
contentType: contentType, | ||
success: function (res) { | ||
fn && fn(res); | ||
success: function(res) { | ||
fn && fn(true); | ||
}, | ||
error: function (err) { | ||
fn && fn(null, err); | ||
} | ||
error: errorCallback(fn) | ||
}); | ||
@@ -104,2 +147,5 @@ } | ||
}; | ||
//Aliases | ||
resource.first = resource.getOne; | ||
@@ -111,12 +157,8 @@ | ||
return $.ajax({ | ||
url: r.path + '/login', | ||
url: rootUrl + r.path + '/login', | ||
type: 'POST', | ||
contentType: contentType, | ||
data: JSON.stringify(credentials), | ||
success: function (res) { | ||
fn && fn(res); | ||
}, | ||
error: function (err) { | ||
fn && fn(null, err); | ||
} | ||
success: successCallback(fn), | ||
error: errorCallback(fn) | ||
}); | ||
@@ -129,11 +171,9 @@ } | ||
return $.ajax({ | ||
url: r.path + '/logout', | ||
url: rootUrl + r.path + '/logout', | ||
type: 'POST', | ||
contentType: contentType, | ||
success: function (res) { | ||
fn && fn(res); | ||
success: function(res) { | ||
fn && fn(true); | ||
}, | ||
error: function (err) { | ||
fn && fn(null, err); | ||
} | ||
error: errorCallback(fn) | ||
}); | ||
@@ -146,11 +186,7 @@ } | ||
return $.ajax({ | ||
url: r.path + '/me', | ||
url: rootUrl + r.path + '/me', | ||
type: 'GET', | ||
contentType: contentType, | ||
success: function (res) { | ||
fn && fn(res); | ||
}, | ||
error: function (err) { | ||
fn && fn(null, err); | ||
} | ||
success: successCallback(fn), | ||
error: errorCallback(fn) | ||
}); | ||
@@ -157,0 +193,0 @@ } |
@@ -1,1 +0,1 @@ | ||
define("model/property",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.Model.extend({defaults:{required:!0},initialize:function(){this.on("change:optional",function(){this.set({required:!this.get("optional")})},this)},parse:function(a){return a.$renameFrom=a.name,a},toJSON:function(){var a=Backbone.Model.prototype.toJSON.call(this);return a.$renameFrom=a.$renameFrom||a._id,a.$renameFrom==a.name&&delete a.$renameFrom,a}})}),define("model/property-collection",["require","exports","module","./property"],function(a,b,c){var d=a("./property"),e=c.exports=Backbone.Collection.extend({model:d,comparator:function(a){return a.get("order")}})}),define("model/collection-settings",["require","exports","module","./property-collection"],function(a,b,c){var d=a("./property-collection"),e=c.exports=Backbone.Model.extend({url:function(){return"/resources/"+this.id},defaults:{properties:null,onGet:"",onPost:'/* Authentication */\n// if (!me || !me.isAdmin) {\n// cancel("You must be an admin!", 401);\n// }\n\n/* Automatic properties */\n// this.creator = me._id;\n// this.creatorName = me.name;\n',onPut:'/* Readonly properties */\n// protect("creator");\n',onDelete:"",onValidate:'/* Validation */\n// if (this.name.length < 10) {\n// error("name", "Must be at least 10 characters");\n// }\n'},initialize:function(){this.set({properties:new d}),this.get("properties").on("add",this.triggerChanged,this),this.get("properties").on("remove",this.triggerChanged,this),this.get("properties").on("update",this.triggerChanged,this),this.get("properties").on("change:name",this.triggerChanged,this),this.get("properties").on("change:required",this.triggerChanged,this),this.get("properties").on("change:order",this.triggerChanged,this)},parse:function(a){var b=a.properties;return delete a.properties,this.get("properties").each(function(a){var c=b[a.get("name")];c&&_.each(a.attributes,function(a,b){_.str.startsWith(b,"c_")&&(c[b]=a)})}),b&&this.get("properties").reset(Backbone.Utils.parseDictionary(b,{keyProperty:"name"}),{parse:!0}),a},triggerChanged:function(){this.trigger("change")},toJSON:function(){var a=Backbone.Model.prototype.toJSON.call(this);return a.properties=Backbone.Utils.toJSONDictionary(a.properties.toJSON(),{keyProperty:"name"}),a}})}),define("app",["require","exports","module","./model/collection-settings"],function(a,b,c){var d=a("./model/collection-settings"),e=Backbone.Model.extend({defaults:{appName:"My App",appUrl:"",resourceType:"",files:undefined},initialize:function(){this.on("change:resourceTypeId",this.setDocLink,this),this.on("change:resourceId",this.loadResource,this),this.on("change:authKey",function(){var a=this.get("authKey");a?$.cookie("DPDAuthKey",a,{expires:7}):$.cookie("DPDAuthKey",null)},this),this.set({appUrl:location.protocol+"//"+location.host,authKey:$.cookie("DPDAuthKey")}),this.setDocLink()},loadResource:function(){var a=this;if(a.get("resourceId")){var b=new Backbone.Model({_id:a.get("resourceId")});b.url="/resources/"+b.id,b.fetch({success:function(){a.set({resourceName:b.get("path"),resourceType:b.get("typeLabel"),resourceTypeId:b.get("type")});if(b.get("type")==="UserCollection"||b.get("type")==="Collection"){var c=new d;c.set(c.parse(b.attributes)),b=c}a.set({resource:b})}})}else a.set({resource:null,resourceName:undefined,resourceType:undefined,resourceTypeId:undefined})},setDocLink:function(){var a=this.get("resourceTypeId"),b="http://deployd.github.com/deployd/";a==="Static"?b+="#Files-Resource":a==="Collection"?b+="#Collection-Resource":a==="UserCollection"&&(b+="#User-Collection-Resource"),this.set("documentation",b)}});c.exports=new e}),define("view/save-status-view",["require","exports","module"],function(a,b,c){function g(a){d=$("#save-status"),a?(d.text(e),l(f)):(j(""),l(!1))}function h(){j("Saving..."),l(!0)}function i(){var a=new Date;j("Last saved "+a.toLocaleTimeString()),l(!1)}function j(a){e=a,d.text(a)}function k(){j("Error"),l(!1)}function l(a){a?d.removeClass("inactive"):d.addClass("inactive"),f=a}var d,e="",f=!1;c.exports={init:g,saving:h,saved:i,error:k},g()}),define("backbone-utils",["require","exports","module","./app","./view/save-status-view"],function(a,b,c){function h(a){return Object.prototype.toString.call(a)==="[object Array]"}var d=a("./app"),e=a("./view/save-status-view");Backbone.Model.prototype.idAttribute="_id",Backbone.View.prototype.close=function(){this.remove(),this.unbind()};var f=Backbone.sync;Backbone.sync=function(a,b,c){var g=_.isFunction(b.url)?b.url():b.url;g=d.get("appUrl")+g;if(a==="create"||a==="update"||a==="delete"){e.saving();var h=c.success,i=c.error,j=function(){e.saved(),h&&h.apply(this,arguments)},k=function(){e.error(),i&&i.apply(this,arguments)};c.success=j,c.error=k}if(a==="create"||a==="update"){var l=c.data||b.toJSON();typeof l!="string"&&(Backbone.Utils.removeClientValues(l),c.contentType="application/json",c.data=JSON.stringify(l))}return c.headers={"x-dssh-key":d.get("authKey")},c.url=c.url||g,f(a,b,c)};var g=Backbone.History.prototype.checkUrl;Backbone.History.prototype.checkUrl=function(a){this._lastFragment=this.fragment;if(this.getFragment()!==this.fragment){var b={cancel:!1};this.trigger("load",b);if(b.cancel)return this.navigate(this.fragment,{trigger:!0,replace:!0}),a.preventDefault(),window.location.hash=this.fragment,!1}g.apply(this,arguments)},Backbone.Utils=Backbone.Utils||{},Backbone.Utils.removeClientValues=function(a){return h(a)?_.each(a,function(a,b){typeof a=="object"&&Backbone.Utils.removeClientValues(a)}):_.each(a,function(b,c){_.str.startsWith(c,"c_")?delete a[c]:typeof b=="object"&&Backbone.Utils.removeClientValues(b)}),a},Backbone.Utils.parseDictionary=function(a,b){var c={keyProperty:"label"};b=_.defaults(b||{},c);var d=Object.keys(a),e=[];return _.each(d,function(c){var d=a[c];d._id=c,d[b.keyProperty]=d[b.keyProperty]||c,e.push(d)}),e},Backbone.Utils.toJSONDictionary=function(a,b){var c={keyProperty:"label"};_.defaults(b,c);var d={};return _.each(a,function(a){var c=a[b.keyProperty];delete a[b.keyProperty],d[c]=a}),d},Backbone.Utils.cancelEvent=function(a){return!1}}),define("knockout-utils",["require","exports","module"],function(a,b,c){function e(a,b){var c;for(c in b)if(typeof a[c]=="undefined")return!1;for(c in b)if(b[c])switch(typeof b[c]){case"object":if(!e(a[c],b[c]))return!1;break;case"function":if(typeof a[c]=="undefined"||c!="equals"&&b[c].toString()!=a[c].toString())return!1;break;default:if(b[c]!=a[c])return!1}else if(a[c])return!1;for(c in a)if(typeof b[c]=="undefined")return!1;return!0}var d=ko.utils.unwrapObservable;ko.bindingHandlers.cssNamed={update:function(a,b){var c=ko.utils.unwrapObservable(b()),d=$(a).data("knockoutCssNamed");$(a).removeClass(d||" ").addClass(c).data("knockoutCssNamed",c)}},ko.bindingHandlers.enter={init:function(a,b,c,d){var e=ko.utils.unwrapObservable(b());$(a).keypress(function(a){a.which===13&&e.call(d,d,a)})}},ko.bindingHandlers.escape={init:function(a,b,c,d){var e=ko.utils.unwrapObservable(b());$(a).keypress(function(a){a.which===23&&e.call(d,d,a)})}},ko.bindingHandlers.tooltip={init:function(a,b){var c=ko.toJS(b());typeof c=="string"&&(c={title:c}),$(a).tooltip(c)},update:function(a,b){var c=b(),e;typeof c=="string"?e=c:e=d(c.title),$(a).attr("data-original-title",e).tooltip("fixTitle")}},ko.bindingHandlers.popover={init:function(a,b){var c=ko.toJS(b());$(a).popover(c)},update:function(a,b){$(a).attr("data-original-title",d(b().title)),$(a).attr("data-content",d(b().content))}},ko.extenders.variableName=function(a){var b=ko.computed({read:a,write:function(b){var c=a();b=b.replace(/[^A-Za-z0-9]/g,""),c!==b&&a(b)}});return b(a()),b},c.exports={objectEquals:e}}),define("view/undo-button-view",["require","exports","module"],function(a,b,c){function g(){d=$("#undo-btn"),e=$(".action-label",d),i(),d.click(function(){f(),d.hide()})}function h(a,b){d.show(),e.text(a),f=b}function i(){d.hide(),f=null,e.text("")}var d,e,f;c.exports={init:g,show:h,hide:i},g()}),define("view/divider-drag",["require","exports","module"],function(a,b,c){c.exports=function(){function j(a){a>h-b?a=h-b:a<b&&(a=b),i=a,d.outerHeight(a-g/2),e.outerHeight(h-a-g),f.css("top",a),$(".main-area .panel").height(d.innerHeight()-44)}var a=10,b=50,c=$(".main-area"),d=$(".top-panel",c),e=$(".bottom-panel",c),f=$(".divider",c),g=f.outerHeight(),h=c.innerHeight(),i=0;j(h-h/3),f.mousedown(function(){var a=function(a){var b=a.pageY-c.offset().top;return j(b),!1};return $(window).mousemove(a),$(window).mouseup(function(){return $(window).unbind("mousemove",a),!1}),!1}),$(window).resize(function(){var a=i/h;h=c.innerHeight(),j(h*a)})}}),define("model/resource",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.Model.extend({defaults:{path:"",order:0},parse:function(a){return a.$renameFrom=a.path,a},initialize:function(){this.on("change:path",this.sanitizePath,this)},sanitizePath:function(){var a=this.get("path");a=d.sanitizePath(a),a!==this.get("path")&&this.set({path:a})}});d.sanitizePath=function(a){return a=a.toLowerCase().replace(/[ _]/g,"-").replace(/[^a-z0-9\/\-]/g,""),_.str.startsWith(a,"/")||(a="/"+a),a}}),define("model/resource-collection",["require","exports","module","../model/resource","../app"],function(a,b,c){var d=a("../model/resource"),e=a("../app"),f=c.exports=Backbone.Collection.extend({model:d,url:"/resources",initialize:function(){this.on("error",this.error,this)},comparator:function(a){return a.get("order")},error:function(){e.set({authKey:undefined},{silent:!0}),e.trigger("change:authKey")},fetch:function(a){a=_.extend(a||{},{data:{q:'{"type": {"$ne": "Static"}}'}}),Backbone.Collection.prototype.fetch.call(this,a)}})}),define("view/template-view",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.View.extend({initialize:function(){this.template=_.template($("#"+this.template).html()),this.render(),this.model&&this.model.on("change",this.render,this),this.collection&&(this.collection.on("reset",this.render,this),this.collection.on("add",this.render,this),this.collection.on("remove",this.render,this))},templateData:function(){return{model:this.model,collection:this.collection}},render:function(){$(this.el).html(this.template(this.templateData()))}})}),define("view/auth-modal-view",["require","exports","module","../app","./template-view"],function(a,b,c){var d=a("../app"),e=a("./template-view"),f=c.exports=e.extend({el:"#authModal",template:"auth-modal-template",initialize:function(){_.bindAll(this),e.prototype.initialize.apply(this,arguments),this.$el=$(this.el).modal({show:!1}),this.$el.on("click",".save",this.saveAuthToken),this.$el.on("hidden",this.cancel)},saveAuthToken:function(){return this.hide(),setTimeout(_.bind(function(){var a=this.$el.find("[name=key]").val();d.set({authKey:a},{silent:!0}),d.trigger("change:authKey")},this),0),!1},show:function(){this.$el.find("[name=key]").val(d.get("authKey")),this.$el.modal("show")},hide:function(){this._programHide=!0,setTimeout(_.bind(function(){this._programHide=!1},this),0),this.$el.modal("hide")},update:function(){d.get("authKey")?this.hide():this.show()},showError:function(){this.$el.find(".key-error").show()},hideError:function(){this.$el.find(".key-error").hide()},cancel:function(){this._programHide||setTimeout(this.show,0)}})}),define("view/resource-sidebar-view",["require","exports","module","./template-view","../app"],function(a,b,c){var d=a("./template-view"),e=a("../app"),f=c.exports=d.extend({el:"#resource-sidebar",template:"resource-sidebar-template",initialize:function(){e.on("change:resourceId",this.render,this),e.on("change:files",this.render,this),d.prototype.initialize.apply(this,arguments)},templateData:function(){return _.extend(d.prototype.templateData.apply(this),{app:e.toJSON()})}})}),define("view/component-type-sidebar-view",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.View.extend({events:{"click li":"onAddItem"},initialize:function(){this.collection=this.collection||this.options.collection,this.template=this.template||this.options.template,this.listView=this.listView||this.options.listView,this.collection.on("reset",this.render,this)},render:function(){var a=this;$(this.el).html(this.template({types:this.collection})),a.$("li").each(function(){}).popover({placement:"right"})},onAddItem:function(a){var b=$(a.currentTarget).attr("data-cid"),c=this.collection.getByCid(b);this.listView.addItem(c)}})}),define("model/resource-type-collection",["require","exports","module","../backbone-utils"],function(a,b,c){a("../backbone-utils");var d=c.exports=Backbone.Collection.extend({url:"/types",sort:function(a){return a.get("label")},parse:function(a){return Object.keys(a).forEach(function(b){b==="Collection"?(a[b].tooltip="Add a simple store to save, update, fetch and delete JSON objects. Available over REST at the specified url.",a[b].tooltipTitle="Persist Data"):b==="UserCollection"?(a[b].tooltip="Add a collection of users such as 'admins', 'authors', or just 'users'. Store users as JSON objects and log them in over REST.",a[b].tooltipTitle="Manage Users"):b==="Static"&&delete a[b]}),Backbone.Utils.parseDictionary(a)}})}),define("view/header-view",["require","exports","module","../model/resource","./save-status-view","./undo-button-view"],function(a,b,c){var d=a("../model/resource"),e=a("./save-status-view"),f=a("./undo-button-view"),g=c.exports=Backbone.View.extend({el:"#header",template:_.template($("#header-template").html()),events:{"click .resourceName":"rename"},initialize:function(){this.model.on("change",this.render,this),this.render()},rename:function(){var a=this.model.get("resource"),b=prompt("Enter a new name for this "+a.get("type"),a.get("path"));return b&&(b=d.sanitizePath(b),a.save({path:b,$renameFrom:a.get("path")}),this.model.set("resourceName",b)),!1},render:function(){return $(this.el).html(this.template(this.model.toJSON())),e.init(!0),f.init(),this}})}),define("model/property-type-collection",["require","exports","module","../backbone-utils"],function(a,b,c){a("../backbone-utils");var d=c.exports=Backbone.Collection.extend({url:"/property-types",sort:function(a){return a.get("label")},parse:function(a){return Object.keys(a).forEach(function(b){b==="string"?(a[b].tooltip="Add a string property. If the incoming value is not a string it will be rejected.",a[b].tooltipTitle="Arbitrary Text"):b==="number"?(a[b].tooltip="Add a number property. If the incoming value is not a number it will be rejected.",a[b].tooltipTitle="JSON Number"):b==="boolean"?(a[b].tooltip="Add a boolean property. If the incoming value is not 'true' or 'false' it will be rejected.",a[b].tooltipTitle="True or false"):b==="date"&&(a[b].tooltip="Add a date string property. If the incoming value is not a valide date string it will be rejected.",a[b].tooltipTitle="specific point in time")}),Backbone.Utils.parseDictionary(a)}})}),define("model/data-collection",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.Collection.extend({url:function(){var a=this.path;return this.querystring&&(this.querystring.indexOf("{")==0?a+="?q="+this.querystring:a+="?"+this.querystring),a}})}),define("view-model/property-view-model",["require","exports","module"],function(a,b){function d(a,b){a=_.defaults(a||{},{name:" ",type:"string",typeLabel:"string",optional:!1,required:!0}),a._id=a.name;var d=ko.mapping.fromJS(a,c);return d.name=d.name.extend({variableName:!0}),d.editing=ko.observable(!1),d.nameFocus=ko.observable(),d.isNew=b!=null,d.toggleEditing=function(){return d.editing(!d.editing()),d.editing()&&d.nameFocus(!0),!1},d.onClickHeader=function(a,b){return!d.editing()||b.target===b.currentTarget||$(b.target).is("div")?(d.toggleEditing(),!1):!0},d.onNameKeypress=function(a,c){return c.which==13&&setTimeout(function(){d.isNew?b.addProperty():d.editing(!1)},1),!0},d.setType=function(a){d.type(ko.utils.unwrapObservable(a._id)),d.typeLabel(ko.utils.unwrapObservable(a.label)),d.type()==="boolean"&&d.optional(!1)},d}var c={include:["optional","_id","$renameFrom"]};b.create=d}),define("view-model/property-list-view-model",["require","exports","module","../view/undo-button-view","./property-view-model"],function(a,b){function e(){var a={properties:ko.observableArray(),propertyTypes:ko.observableArray()};return a.newProperty=d.create({},a),a.newProperty.nameFocus(!0),a.addProperty=_.bind(function(){this.newProperty.name()&&this.newProperty.type()&&(this.properties.push(d.create(ko.mapping.toJS(this.newProperty))),this.newProperty.name(""))},a),a.removeProperty=_.bind(function(a){var b=this,d=this.properties.indexOf(a);c.show("Delete "+a.name(),function(){b.properties.splice(d,0,a)}),this.properties.remove(a)},a),a.onNewNameKeypress=_.bind(function(b,c){return c.which==13&&setTimeout(function(){a.addProperty()},1),!0},a),a}var c=a("../view/undo-button-view"),d=a("./property-view-model");b.create=e}),define("view/property-list-view",["require","exports","module","../knockout-utils","../app","./undo-button-view","../view-model/property-list-view-model","../view-model/property-view-model"],function(a,b,c){var d=a("../knockout-utils"),e=a("../app"),f=a("./undo-button-view"),g=a("../view-model/property-list-view-model"),h=a("../view-model/property-view-model"),i=c.exports=Backbone.View.extend({el:"#property-list",template:_.template($("#property-list-template").html()),initialize:function(){this.collection=this.collection||this.options.collection,this.typeCollection=this.typeCollection||this.options.typeCollection,this.initializeViewModel(),this.mapProperties(),this.collection.on("reset",this.mapProperties,this),this.mapTypes(),this.typeCollection.on("reset",this.mapTypes,this),this.render()},initializeViewModel:function(){var a=this;this.viewModel=g.create(),this.mapping={properties:{key:function(a){return ko.utils.unwrapObservable(a.name)},create:_.bind(function(a){return h.create(a.data)},this)}},ko.computed(function(){var b=a._lastJSON,c=ko.mapping.toJS(this),e=c.properties;b&&!d.objectEquals(b,e)&&(a.collection.reset(c.properties,{silent:!0}),a.collection.trigger("update"),a._lastJSON=e)},this.viewModel).extend({throttle:100})},mapProperties:function(){var a=this.collection.toJSON();this._lastJSON=a,ko.mapping.fromJS({properties:a},this.mapping,this.viewModel);var b=ko.mapping.toJS(this.viewModel);d.objectEquals(b.properties,a)||(console.log("WARNING: viewmodel/model mismatched. Remapping..."),this.viewModel.properties.removeAll(),setTimeout(_.bind(this.mapProperties,this),1))},mapTypes:function(){ko.mapping.fromJS({propertyTypes:this.typeCollection.toJSON()},this.mapping,this.viewModel)},render:function(){this.el&&ko.cleanNode(this.el),$(this.el).html(this.template({resourceTypeId:e.get("resourceTypeId")})),ko.applyBindings(this.viewModel,this.el)},close:function(){ko.removeNode(this.el)}})}),define("view/property-reference-view",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.View.extend({el:"#property-reference",template:_.template($("#property-reference-template").html()),initialize:function(){this.render(),this.model.on("change",this.render,this)},render:function(){$(this.el).html(this.template({model:this.model})),this.$("li i").tooltip({placement:"left"})}})}),define("view-model/collection-data-view-model",["require","exports","module"],function(a,b,c){createRow=b.createRow=function(a,b,c){function e(a,b){var c={_id:null};b.forEach(function(a){c[a.name]=undefined}),a=_.defaults(a,c),ko.mapping.fromJS(a,{},d)}var d={};return e(a,b),d.c_editing=ko.observable(!1),d.c_focus=ko.observable(),d.c_errors=ko.observable({}),d.c_formatted=function(a,b){var a=ko.utils.unwrapObservable(a),b=ko.utils.unwrapObservable(b),c=ko.utils.unwrapObservable(d[a]);return b==="password"||typeof c=="undefined"?"...":c},d.c_toggleEditing=function(){d.c_editing()&&!d.isNew?c.revertRow(d):d.c_editing(!0)},d.c_remapProps=function(a){var b=ko.mapping.toJS(d);e(b,a)},d._onKeypress=function(a,b){return b.which==13?setTimeout(function(){c.saveRow(d)},1):b.which==27&&!d.isNew&&setTimeout(function(){c.revertRow(d)},1),!0},d._onDoubleclick=function(a,b){if(!!d.c_editing())return!0;d.c_editing(!0),d.c_focus(a.name())},d},create=b.create=function(){var a={properties:ko.observableArray(),collection:ko.observableArray(),queryString:ko.observable(),queryError:ko.observable("")};return a.newRow=createRow({},[],a),a.newRow.isNew=!0,a}}),define("view/collection-data-view",["require","exports","module","../view-model/collection-data-view-model","../app","./undo-button-view"],function(a,b,c){var d=a("../view-model/collection-data-view-model"),e=a("../app"),f=a("./undo-button-view"),g=c.exports=Backbone.View.extend({el:"#data",template:_.template($("#collection-data-template").html()),initialize:function(){var a=this;a.properties=a.options.properties,a.collection=a.options.collection,a.initializeViewModel(),a.initializeMapping(),a.isUser=e.get("resourceTypeId")==="UserCollection",a.mapProperties(),a.properties.on("reset",a.mapProperties,a),a.properties.on("add",a.mapProperties,a),a.properties.on("remove",a.mapProperties,a),a.properties.on("change:name",a.mapProperties,a),a.mapCollection(),a.collection.on("reset",a.mapCollection,a),a.collection.on("add",a.mapCollection,a),a.collection.on("remove",a.mapCollection,a),function b(c,d){d&&d.responseText?a.viewModel.queryError(d.responseText):a.viewModel.queryError(""),a._timeout=setTimeout(function(){a.collection.fetch({success:b,error:b})},1e3)}(),a.render()},initializeViewModel:function(){var a=this,b=a.viewModel=d.create();b.deleteRow=function(b){var c=a.collection,d=c.get(b._id()),e=c.indexOf(d);d&&d.destroy({wait:!0}),d.set("_id",undefined),f.show("Delete row",function(){c.create(d,{at:e})})},b.saveRow=function(c){function f(a,b){try{var d=JSON.parse(b.responseText);c.c_errors(d.errors)}catch(e){alert("An error occurred when saving: "+b.responseText)}}var d=ko.mapping.toJS(c),e=a.collection;if(c.isNew)e.create(d,{success:function(){c.c_errors({}),b.properties().forEach(function(a){c[a.name()]&&c[a.name()](null)})},error:f,wait:!0});else{var g=e.get(c._id());g.save(d,{success:function(){c.c_editing(!1),c.c_errors({}),ko.mapping.fromJS(g.toJSON(),{},c)},error:f})}},b.revertRow=function(b){var c=a.collection,d=c.get(b._id());d.fetch({success:function(){ko.mapping.fromJS(d.toJSON(),{},b),b.c_editing(!1)}})},ko.computed(function(){a.collection.querystring=b.queryString()},b).extend({throttle:100}),ko.computed(function(){var c=b.queryError(),d=a.$("#current-data-querystring");c?d.attr("data-original-title",c).tooltip("fixTitle").tooltip("show"):d.attr("data-original-title","").tooltip("fixTitle").tooltip("hide")},b)},initializeMapping:function(){var a=this,b=this.viewModel;a.propertiesMapping={properties:{key:function(a){return ko.utils.unwrapObservable(a._id)}}},a.collectionMapping={collection:{key:function(a){return ko.utils.unwrapObservable(a._id)},create:function(a){return d.createRow(a.data,ko.mapping.toJS(b.properties),b)},update:function(a){return a.target.c_editing()?a.data:a.target}}}},mapProperties:function(){var a=this.properties.toJSON();e.get("resourceTypeId")==="UserCollection"&&a.unshift({name:"email",type:"string",typeLabel:"string"},{name:"password",type:"password",typeLabel:"password"}),this.viewModel.collection().forEach(function(b){b.c_remapProps(a)}),this.viewModel.newRow.c_remapProps(a),ko.mapping.fromJS({properties:a},this.propertiesMapping,this.viewModel)},mapCollection:function(){ko.mapping.fromJS({collection:this.collection.toJSON()},this.collectionMapping,this.viewModel)},render:function(){var a=this;ko.cleanNode(this.el),$(this.el).html(this.template({resourceType:e.get("resourceTypeId")})),ko.applyBindings(this.viewModel,this.el)},close:function(){clearTimeout(this._timeout),ko.removeNode(this.el)}})}),define("view/code-editor-view",["require","exports","module"],function(a,b,c){function i(a){return h||(h=ace.edit(g[0])),$(a).append(g),h}var d=ace.require("ace/mode/javascript").Mode,e=ace.require("ace/mode/css").Mode,f=ace.require("ace/mode/html").Mode,g=$("<div>"),h,j=c.exports=Backbone.View.extend(Backbone.Events).extend({initialize:function(){this.mode=this.options.mode,_.bindAll(this,"trackUpdate","update","render")},trackUpdate:function(){this._timeout&&clearTimeout(this._timeout);var a=this.updateTime||1e3;this._timeout=setTimeout(this.update,a)},update:function(){this.trigger("change")},getText:function(){return this.editor?this.editor.getSession().getValue():undefined},setText:function(a){this.editor.getSession().setValue(a),clearTimeout(this._timeout)},resize:function(){this.editor.resize()},render:function(){var a=this,b=i(this.el);b.resize();var c=this.mode||"js";return c==="html"||c==="htm"?b.getSession().setMode(new f):c==="css"?b.getSession().setMode(new e):c==="js"&&b.getSession().setMode(new d),b.getSession().on("change",this.trackUpdate),b.commands.addCommand({name:"save",bindKey:{win:"Ctrl-S",mac:"Command-S"},exec:function(b){a.trigger("save")}}),this.editor=b,b.focus(),this},close:function(){this._timeout&&clearTimeout(this._timeout),this.off(),this.setText("")}})}),define("view/collection-event-view",["require","exports","module","./code-editor-view"],function(a,b,c){var d=a("./code-editor-view"),e=c.exports=Backbone.View.extend({template:_.template($("#events-template").html()),events:{"click #event-nav a":"updateRender"},initialize:function(){var a=this;$(this.el).html(this.template(this.model.toJSON())),this.editor=(new d({})).render(),this.editor.on("change",a.update,a),this.resize=_.bind(this.resize,this),$("#resource-sidebar").on("click","a",this.resize)},getActive:function(){return this.$("#event-nav .active a").attr("data-editor")},update:function(a){var b=this.editor.getText();typeof b!="undefined"&&this.model.set(this.getActive(),b)},updateRender:function(){this.update(),setTimeout(_.bind(this.render,this),1)},render:function(){var a=this.getActive();return this.editor.setText(this.model.get(a)),this.editor.setElement("#"+a),this.editor.render(),this},resize:function(){this.editor.resize()},close:function(){$("#resource-sidebar").off("click","a",this.resize),this.editor.close()}})}),define("view/collection-routes-view",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.View.extend({el:"#api",template:_.template($("#collection-routes-template").html()),initialize:function(){this.render(),this.model.on("change",this.render,this)},render:function(){$(this.el).html(this.template(this.model.toJSON()))}})}),define("model/file",["require","exports","module","../app"],function(a,b,c){var d=a("../app"),e=c.exports=Backbone.Model.extend({url:function(){var a=this.get("info"),b=this.get("path");return a?b+"/"+a.fileName:b},sync:function(a,b,c){function g(){}var e=this,f=arguments,h=b.get("info"),i=b.get("data");if(a==="create"&&(h||i)){var j;if(h)j=new FormData,j.append("data",h);else if(i||i==="")j=i;var k=_.isFunction(b.url)?b.url():b.url;k=d.get("appUrl")+k;var l=new XMLHttpRequest;l.open("POST",k),l.setRequestHeader("x-dssh-key",d.get("authKey")),l.send(j),l.addEventListener("readystatechange",function(){typeof c.success=="function"&&c.success(),e.trigger("sync")})}else Backbone.sync.apply(b,f)}})}),define("view-model/folder-view-model",["require","exports","module","model/file","model/resource","app"],function(a,b,c){function i(a){return{data:a}}function j(a){return a=_.extend(a||{},{data:{type:"Static"}}),Backbone.Collection.prototype.fetch.call(this,a)}var d=a("model/file"),e=a("model/resource"),f=a("app"),g={folders:{key:function(a){return ko.utils.unwrapObservable(a.path)}}},h=b.template={eventIsButton:function(a){var b=$(a.target);return b.is("a")||b.parentsUntil(".file, .folder").is("a")?!0:!1},mapFiles:function(){this.files(this.model.get("data"))},mapFolders:function(){var a=[],b=this;this.foldersCollection.each(function(c){var d=c.get("path");if(d==="/")return;var e="/"+b.getPath("");if(d.indexOf(e)!==-1){var f=d.slice(e.length);if(f.length&&f.indexOf("/")===-1){var g=_.find(b.folders(),function(a){return a.path===d});g||(c.urlRoot=b.foldersCollection.url,g={path:d,name:f,model:c,isOpen:ko.observable(!1),viewModel:k(d)}),b.foldersToOpen[d]&&(g.isOpen(!0),delete b.foldersToOpen[d]),a.push(g)}}}),b.folders(a)},fetch:function(){this.fetchFiles(),this.fetchFolders(),_.each(this.folders(),function(a){a.isOpen()&&a.viewModel.fetch()})},fetchFolders:function(){this.foldersCollection.fetch()},fetchFiles:function(){this.model.fetch()},getPath:function(a){var b=this.path.slice(1);return this.path!=="/"&&(b+="/"),b+a},deleteFile:function(a){var b=new d({path:"/",info:{fileName:a},_id:a}),c=this;b.destroy({success:function(){c.fetchFiles()}})},editFile:function(a){f.set("files",this.getPath(a))},onClickFile:function(a,b){if(!!this.eventIsButton(b))return!0;this.editFile(a)},onChangeUpload:function(a,b){var c=b.target.files&&b.target.files,d=this;_.each(c,d.uploadFile)},uploadFile:function(a){var b=new d({info:a,path:this.path}),c=a.fileName,e=this;this.uploadingFiles.push(c),b.on("sync",function(){e.fetchFiles(),e.uploadingFiles.remove(c)}),b.save()},addFile:function(){var a=prompt("Enter a name for this file, including the extension:");a&&this.editFile(a)},deleteFolder:function(a){var b=this;a.model.destroy({success:function(){b.fetchFolders()}})},addFolder:function(){var a=prompt("Enter a name for this folder:"),b=this;if(a){var c=e.sanitizePath(a);b.path!=="/"&&(c=b.path+c),this.foldersCollection.create({path:c,type:"Static"},{success:function(){b.foldersToOpen[c]=!0,b.fetchFolders()}})}},toggleFolder:function(a){a.isOpen(!a.isOpen()),a.isOpen()&&a.viewModel.fetch()},onClickFolder:function(a,b){if(!!this.eventIsButton(b))return!0;this.toggleFolder(a)}},k=b.create=function(a){a=a||"/";var b=Object.create(h);_.bindAll(b),b.path=a,b.model=new Backbone.Model,b.model.parse=i,b.model.url=a,b.model.on("change:data",b.mapFiles,b);var c=b.foldersCollection=new Backbone.Collection;return c.url="/resources",c.fetch=j,c.on("reset",b.mapFolders,b),b.foldersToOpen={},b.files=ko.observableArray(),b.folders=ko.observableArray(),b.uploadingFiles=ko.observableArray(),b.uploadingText=ko.computed(function(){var a=this.uploadingFiles().length;return a==1?"Uploading "+this.uploadingFiles()[0]+"...":a?"Uploading "+a+" files...":""},b),b}}),define("view/static-view",["require","exports","module","view-model/folder-view-model"],function(a,b,c){var d=a("view-model/folder-view-model"),e,f=c.exports=Backbone.View.extend({template:_.template($("#static-template").html()),initialize:function(){this.initializeViewModel(),this.render()},initializeViewModel:function(){e||(e=d.create()),this.viewModel=e,this.viewModel.fetch()},render:function(){this.$el.html(this.template({})),ko.cleanNode(this.el),ko.applyBindings(this.viewModel,this.el)},close:function(){ko.removeNode(this.el)}})}),define("view/file-editor-view",["require","exports","module","../app","../model/file","./code-editor-view"],function(a,b,c){var d=a("../app"),e=a("./code-editor-view"),f=a("../model/file"),g=a("./save-status-view"),h=c.exports=Backbone.View.extend(Backbone.Events).extend({template:_.template($("#file-editor-template").html()),events:{"click .back":"back","click #save-btn":"save"},initialize:function(){$(this.el).html(this.template({}));var a=this.path="/"+d.get("files"),b=this,c=a.slice(a.indexOf(".")+1),f=this.editor=(new e({el:$("#editor"),mode:c})).render();f.updateTime=1,_.bind(b.save,b),f.on("save",function(){b.save()}),f.on("change",function(){b.hasChanges()}),$.get(a,function(a){f.setText(a)},"text");var g=$(".editor-container"),h=$(window);h.resize(function(){g.height(h.height()-200),f.resize()}),h.resize(),b.saved()},back:function(){return d.set("files",!0),!1},save:function(){var a=new f({path:this.path,data:this.editor.getText()});a.save({},{success:function(){g.saved()}}),this.saved(),g.saving()},hasChanges:function(){$("#file-status").empty().append('<i class="icon-file"></i> '+this.link()+' <i class="icon-asterisk"></i>'),$("#save-btn").removeAttr("disabled")},link:function(){return'<a href="'+this.path+'" target="_blank">'+this.path+"</a>"},saved:function(){$("#file-status").empty().append('<i class="icon-file"></i> '+this.link()),$("#save-btn").attr("disabled",!0)},close:function(){this.editor.close()}})}),define("router",["require","exports","module","./app"],function(a,b,c){var d=a("./app"),e=Backbone.Router.extend({routes:{"":"home",files:"files","files/*path":"editFile",":id":"resource"},home:function(){d.set({resourceId:undefined,files:undefined})},resource:function(a){d.set({resourceId:a,files:undefined})},files:function(){d.set({resourceId:undefined,files:!0})},editFile:function(a){d.set({resourceId:undefined,files:a})}});c.exports=new e}),define("view/resource-view",["require","exports","module","./undo-button-view","../router"],function(a,b,c){var d=a("./undo-button-view"),e=a("../router"),f=_.template($("#resource-template").html()),g=c.exports=Backbone.View.extend({tagName:"li",className:"component-item",events:{"click .delete-btn":"delete","click .component-item-header":"onClickHeader","click .path":"activate","click .rename-btn":"activate","click .cancel-btn":"deactivate","click .save-btn":"save",'keypress input[name="path"]':"onKeypress",'keyup input[name="path"]':"onKeyup"},initialize:function(){this.parentView=this.options.parentView,this.model.on("change:c_active",this.render,this),this.model.on("change:_id",this.render,this),this.model.on("change:path",this.render,this)},render:function(){var a=$(this.el);return a.attr("id",this.model.cid).html(f({resource:this.model.toJSON()})),this.model.isNew()?a.addClass("unsaved"):a.removeClass("unsaved"),this},gotoDetail:function(){return this.model.isNew()||e.navigate(this.model.get("_id"),{trigger:!0}),!1},"delete":function(){var a=this;return a.model.isNew()?a.model.destroy():confirm("Do you wish to delete this resource? All associated data and configuration will be permanently removed.")&&a.model.destroy({wait:!0}),!1},activate:function(){return this.model.set({c_active:!0}),this.$('input[name="path"]').focus(),!1},deactivate:function(){return this.model.isNew()?this.delete():this.model.set({c_active:!1}),!1},save:function(){return this.model.save({path:this.$('input[name="path"]').val()}),this.model.set({c_active:!1}),!1},onClickHeader:function(a){if($(a.target).hasClass("component-item-header")||$(a.target).hasClass("type-icon"))return this.model.get("c_active")?this.deactivate():this.gotoDetail(),!1;this.onFocus(a)},onFocus:function(a){$(a.target).focus()},onKeypress:function(a){var b=$(a.currentTarget).val();_.str.startsWith(b,"/")||(b="/"+b,$(a.currentTarget).val(b))},onKeyup:function(a){a.which==13&&(this.model.isNew()?this.model.save({path:this.$('input[name="path"]').val()},{success:_.bind(function(){this.gotoDetail()},this)}):this.save()),a.which==27&&this.deactivate()},destroy:function(){this.model.off("change:c_active",this.render),this.model.off("change:_id",this.render),this.model.off("change:path",this.render)}})}),define("view/resource-list-view",["require","exports","module","../model/resource","./resource-view"],function(a,b,c){var d=a("../model/resource"),e=a("./resource-view"),f=c.exports=Backbone.View.extend({el:"#resource-list",emptyEl:"#resource-list-empty",subViews:[],initialize:function(){this.parentView=this.options.parentView,this.collection=this.options.collection,this.typeCollection=this.options.typeCollection,this.collection.on("reset",this.render,this),this.collection.on("add",this.render,this),this.collection.on("remove",this.render,this),this.initializeDom(),this.render()},initializeDom:function(){},addItem:function(a,b){isNaN(b)&&(b=this.collection.length);var c=new d({path:a.get("defaultPath"),typeLabel:a.get("label"),type:a.get("_id"),order:b+1,c_active:!0});return this.collection.add(c,{at:b}),this.updateOrder(),setTimeout(function(){this.$("#"+c.cid).find('input[name="path"]').focus()},0),!1},updateOrder:function(){var a=this,b=[];$(this.el).children().each(function(){var c=a.collection.getByCid($(this).attr("id"));c&&b.push(c)});var c=0;_.each(b,function(a){c+=1,a.isNew()?a.set({order:c},{silent:!0}):a.save({order:c},{silent:!0})})},onReceiveComponent:function(a,b){var c=a.attr("data-cid"),d=this.parentView.resourceTypes.getByCid(c);a.remove(),this.addItem(d,b)},onReorder:function(){this.updateOrder()},render:function(a){var b=this;_.each(b.subViews,function(a){a.destroy()}),$(b.el).find("li:not(.locked)").remove(),b.collection.length?($(b.emptyEl).hide(),b.subViews=b.collection.map(function(a){var c=new e({model:a,parentView:b});return $(b.el).append(c.el),c.render(),c})):$(b.emptyEl).show()}})}),define("view/resources-view",["require","exports","module","./component-type-sidebar-view","./resource-list-view","./template-view","../model/resource-collection","../model/resource-type-collection","router"],function(a,b,c){var d=a("./component-type-sidebar-view"),e=a("./resource-list-view"),f=a("./template-view"),g=a("../model/resource-collection"),h=a("../model/resource-type-collection"),i=a("router"),j=c.exports=f.extend({el:"#resources-container",template:"resources-template",typesTemplate:_.template($("#resource-types-template").html()),events:{"click #property-types a":"addItem","click #files-resource":"goToFiles"},initialize:function(){this.resources=this.options.resources,this.resourceTypes=new h,f.prototype.initialize.apply(this,arguments),this.resourceListView=new e({collection:this.resources,typeCollection:this.resourceTypes,parentView:this}),this.resourceTypes.on("reset",this.renderTypes,this),this.resourceTypes.fetch()},goToFiles:function(){i.navigate("files",{trigger:!0})},addItem:function(a){var b=$(a.currentTarget).parents("li").attr("data-cid"),c=this.resourceTypes.getByCid(b);this.resourceListView.addItem(c)},renderTypes:function(){$("#property-types").html(this.typesTemplate({types:this.resourceTypes})).find("li").popover({placement:"left"})}})}),define("view/collection-view",["require","exports","module","../model/property-type-collection","../model/collection-settings","../model/data-collection","./property-list-view","./property-reference-view","./collection-data-view","./collection-event-view","./collection-routes-view","../app","../router","./undo-button-view"],function(a,b,c){var d=a("../model/property-type-collection"),e=a("../model/collection-settings"),f=a("../model/data-collection"),g=a("./property-list-view"),h=a("./property-reference-view"),i=a("./collection-data-view"),j=a("./collection-event-view"),k=a("./collection-routes-view"),l=a("../app"),m=a("../router"),n=a("./undo-button-view"),o=c.exports=Backbone.View.extend({template:_.template($("#collection-template").html()),events:{"click .cta-link":"onClickCta"},initialize:function(){$(this.el).html(this.template({})),this.propertyTypes=new d,this.dataCollection=new f([]),this.dataCollection.path=this.model.get("path"),this.dataCollection.fetch(),this.model.on("change:path",function(){this.dataCollection.path=this.model.get("path")},this),this.propertyListView=new g({collection:this.model.get("properties"),typeCollection:this.propertyTypes,parentView:this}),this.PropertyReferenceView=new h({model:this.model}),this.dataView=new i({properties:this.model.get("properties"),collection:this.dataCollection}),this.routesView=new k({model:this.model}),this.eventsView=(new j({el:this.$("#events-panel"),model:this.model})).render(),this.model.on("change",this.save,this),this.dataCollection.on("reset",this.render,this),this.model.on("change",this.render,this),this.propertyTypes.fetch(),this.render(),this.initializeDom()},initializeDom:function(){this.onKeypress=_.bind(this.onKeypress,this),$(".icon-info-sign").popover(),this.model.get("properties").length?this.$('#resource-sidebar a[href="#data"]').click():this.$('#resource-sidebar a[href="#properties"]').click()},save:function(){var a=this;this.model.save()},onKeypress:function(a){if((a.ctrlKey||a.metaKey)&&a.which=="83")return this.save(),a.preventDefault(),!1},onClickCta:function(a){var b=$(a.currentTarget).attr("href"),c=$('#resource-sidebar a[href="'+b+'"]');return c.click(),!1},navigate:function(a){var b=$(a.currentTarget),c=b.attr("href");return $(window).scrollTop($(c).offset().top-50),!1},render:function(){var a=$("#property-now-what");return this.model.get("properties").length&&!this.dataCollection.length?a.show():a.hide(),this},close:function(){Backbone.View.prototype.close.call(this),this.propertyListView.close(),this.dataView.close(),this.eventsView.close(),$(window).off("scroll",this.onScroll)}})}),define("view/app-view",["require","exports","module","../app","../router","./undo-button-view","./save-status-view","../model/resource-collection","./auth-modal-view","./resource-sidebar-view","./resources-view","./header-view","./collection-view","./static-view","./file-editor-view"],function(a,b,c){var d=a("../app"),e=a("../router"),f=a("./undo-button-view"),g=a("./save-status-view"),h=a("../model/resource-collection"),i=a("./auth-modal-view"),j=a("./resource-sidebar-view"),k=a("./resources-view"),l=a("./header-view"),m=a("./collection-view"),n=a("./static-view"),o=a("./file-editor-view"),p=c.exports=Backbone.View.extend({initialize:function(){this.resources=new h,this.modal=new i,this.authenticate(),d.on("change:authKey",this.authenticate,this),this.resources.on("reset",this.initRender,this),this.resources.on("error",this.modal.showError,this.modal)},authenticate:function(){d.get("authKey")?this.resources.fetch():this.modal.show()},initRender:function(){this.resourceSidebarView=new j({collection:this.resources}),this.resourceView=new k({resources:this.resources}),this.headerView=new l({model:d}),this.resources.off("reset",this.initRender,this),d.on("change:resource",this.render,this),d.on("change:files",this.render,this),this.render()},render:function(){this.bodyView&&this.bodyView.close();var a=d.get("resource"),b=d.get("files");if(d.get("resourceId")||b){var c=null;if(b)b!==!0?c=o:c=n;else if(a){var h=a.get("type");if(h==="Collection"||h==="UserCollection")c=m}if(c){var i=$("<div>");$("#body").empty().append(i),this.bodyView=new c({model:a,el:i})}$("#body-container").show(),$("#resources-container").hide();if(b){var j="/files";b!==!0&&(j+="/"+b),e.navigate(j)}else e.navigate(d.get("resourceId"))}else $("#body-container").hide(),$("#resources-container").show(),this.resources.fetch(),e.navigate("");f.init(),g.init()}}),q;p.init=function(){return q||(q=new p),q}}),define("entry",["require","exports","module","./backbone-utils","./knockout-utils","./view/undo-button-view","./view/divider-drag","./view/app-view","./router"],function(a,b,c){a("./backbone-utils"),a("./knockout-utils"),a("./view/undo-button-view"),a("./view/divider-drag");var d=a("./view/app-view"),e=a("./router");d.init(),Backbone.history.start()}) | ||
define("model/property",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.Model.extend({defaults:{required:!0},initialize:function(){this.on("change:optional",function(){this.set({required:!this.get("optional")})},this)},parse:function(a){return a.$renameFrom=a.name,a},toJSON:function(){var a=Backbone.Model.prototype.toJSON.call(this);return a.$renameFrom=a.$renameFrom||a._id,a.$renameFrom==a.name&&delete a.$renameFrom,a}})}),define("model/property-collection",["require","exports","module","./property"],function(a,b,c){var d=a("./property"),e=c.exports=Backbone.Collection.extend({model:d,comparator:function(a){return a.get("order")}})}),define("model/collection-settings",["require","exports","module","./property-collection"],function(a,b,c){var d=a("./property-collection"),e=c.exports=Backbone.Model.extend({url:function(){return"/resources/"+this.id},defaults:{properties:null,onGet:"",onPost:'/* Authentication */\n// if (!me || !me.isAdmin) {\n// cancel("You must be an admin!", 401);\n// }\n\n/* Automatic properties */\n// this.creator = me._id;\n// this.creatorName = me.name;\n',onPut:'/* Readonly properties */\n// protect("creator");\n',onDelete:"",onValidate:'/* Validation */\n// if (this.name.length < 10) {\n// error("name", "Must be at least 10 characters");\n// }\n'},initialize:function(){this.set({properties:new d}),this.get("properties").on("add",this.triggerChanged,this),this.get("properties").on("remove",this.triggerChanged,this),this.get("properties").on("update",this.triggerChanged,this),this.get("properties").on("change:name",this.triggerChanged,this),this.get("properties").on("change:required",this.triggerChanged,this),this.get("properties").on("change:order",this.triggerChanged,this)},parse:function(a){var b=a.properties;return delete a.properties,this.get("properties").each(function(a){var c=b[a.get("name")];c&&_.each(a.attributes,function(a,b){_.str.startsWith(b,"c_")&&(c[b]=a)})}),b&&this.get("properties").reset(Backbone.Utils.parseDictionary(b,{keyProperty:"name"}),{parse:!0}),a},triggerChanged:function(){this.trigger("change")},toJSON:function(){var a=Backbone.Model.prototype.toJSON.call(this);return a.properties=Backbone.Utils.toJSONDictionary(a.properties.toJSON(),{keyProperty:"name"}),a}})}),define("app",["require","exports","module","./model/collection-settings"],function(a,b,c){var d=a("./model/collection-settings"),e=Backbone.Model.extend({defaults:{appName:"My App",appUrl:"",resourceType:"",files:undefined},initialize:function(){this.on("change:resourceTypeId",this.setDocLink,this),this.on("change:resourceId",this.loadResource,this),this.on("change:authKey",function(){var a=this.get("authKey");a?$.cookie("DPDAuthKey",a,{expires:7}):$.cookie("DPDAuthKey",null)},this),this.set({appUrl:location.protocol+"//"+location.host,authKey:$.cookie("DPDAuthKey")}),this.setDocLink()},loadResource:function(){var a=this;if(a.get("resourceId")){var b=new Backbone.Model({_id:a.get("resourceId")});b.url="/resources/"+b.id,b.fetch({success:function(){a.set({resourceName:b.get("path"),resourceType:b.get("typeLabel"),resourceTypeId:b.get("type")});if(b.get("type")==="UserCollection"||b.get("type")==="Collection"){var c=new d;c.set(c.parse(b.attributes)),b=c}a.set({resource:b})}})}else a.set({resource:null,resourceName:undefined,resourceType:undefined,resourceTypeId:undefined})},setDocLink:function(){var a=this.get("resourceTypeId"),b="http://deployd.github.com/deployd/";a==="Static"?b+="#Files-Resource":a==="Collection"?b+="#Collection-Resource":a==="UserCollection"&&(b+="#User-Collection-Resource"),this.set("documentation",b)}});c.exports=new e}),define("view/save-status-view",["require","exports","module"],function(a,b,c){function g(a){d=$("#save-status"),a?(d.text(e),l(f)):(j(""),l(!1))}function h(){j("Saving..."),l(!0)}function i(){var a=new Date;j("Last saved "+a.toLocaleTimeString()),l(!1)}function j(a){e=a,d.text(a)}function k(){j("Error"),l(!1)}function l(a){a?d.removeClass("inactive"):d.addClass("inactive"),f=a}var d,e="",f=!1;c.exports={init:g,saving:h,saved:i,error:k},g()}),define("backbone-utils",["require","exports","module","./app","./view/save-status-view"],function(a,b,c){function h(a){return Object.prototype.toString.call(a)==="[object Array]"}var d=a("./app"),e=a("./view/save-status-view");Backbone.Model.prototype.idAttribute="_id",Backbone.View.prototype.close=function(){this.remove(),this.unbind()};var f=Backbone.sync;Backbone.sync=function(a,b,c){var g=_.isFunction(b.url)?b.url():b.url;g=d.get("appUrl")+g;if(a==="create"||a==="update"||a==="delete"){e.saving();var h=c.success,i=c.error,j=function(){e.saved(),h&&h.apply(this,arguments)},k=function(){e.error(),i&&i.apply(this,arguments)};c.success=j,c.error=k}if(a==="create"||a==="update"){var l=c.data||b.toJSON();typeof l!="string"&&(Backbone.Utils.removeClientValues(l),c.contentType="application/json",c.data=JSON.stringify(l))}return c.headers={"x-dssh-key":d.get("authKey")},c.url=c.url||g,f(a,b,c)};var g=Backbone.History.prototype.checkUrl;Backbone.History.prototype.checkUrl=function(a){this._lastFragment=this.fragment;if(this.getFragment()!==this.fragment){var b={cancel:!1};this.trigger("load",b);if(b.cancel)return this.navigate(this.fragment,{trigger:!0,replace:!0}),a.preventDefault(),window.location.hash=this.fragment,!1}g.apply(this,arguments)},Backbone.Utils=Backbone.Utils||{},Backbone.Utils.removeClientValues=function(a){return h(a)?_.each(a,function(a,b){typeof a=="object"&&Backbone.Utils.removeClientValues(a)}):_.each(a,function(b,c){_.str.startsWith(c,"c_")?delete a[c]:typeof b=="object"&&Backbone.Utils.removeClientValues(b)}),a},Backbone.Utils.parseDictionary=function(a,b){var c={keyProperty:"label"};b=_.defaults(b||{},c);var d=Object.keys(a),e=[];return _.each(d,function(c){var d=a[c];d._id=c,d[b.keyProperty]=d[b.keyProperty]||c,e.push(d)}),e},Backbone.Utils.toJSONDictionary=function(a,b){var c={keyProperty:"label"};_.defaults(b,c);var d={};return _.each(a,function(a){var c=a[b.keyProperty];delete a[b.keyProperty],d[c]=a}),d},Backbone.Utils.cancelEvent=function(a){return!1}}),define("knockout-utils",["require","exports","module"],function(a,b,c){function e(a,b){var c;for(c in b)if(typeof a[c]=="undefined")return!1;for(c in b)if(b[c])switch(typeof b[c]){case"object":if(!e(a[c],b[c]))return!1;break;case"function":if(typeof a[c]=="undefined"||c!="equals"&&b[c].toString()!=a[c].toString())return!1;break;default:if(b[c]!=a[c])return!1}else if(a[c])return!1;for(c in a)if(typeof b[c]=="undefined")return!1;return!0}var d=ko.utils.unwrapObservable;ko.bindingHandlers.cssNamed={update:function(a,b){var c=ko.utils.unwrapObservable(b()),d=$(a).data("knockoutCssNamed");$(a).removeClass(d||" ").addClass(c).data("knockoutCssNamed",c)}},ko.bindingHandlers.enter={init:function(a,b,c,d){var e=ko.utils.unwrapObservable(b());$(a).keypress(function(a){a.which===13&&e.call(d,d,a)})}},ko.bindingHandlers.escape={init:function(a,b,c,d){var e=ko.utils.unwrapObservable(b());$(a).keypress(function(a){a.which===23&&e.call(d,d,a)})}},ko.bindingHandlers.tooltip={init:function(a,b){var c=ko.toJS(b());typeof c=="string"&&(c={title:c}),$(a).tooltip(c)},update:function(a,b){var c=b(),e;typeof c=="string"?e=c:e=d(c.title),$(a).attr("data-original-title",e).tooltip("fixTitle")}},ko.bindingHandlers.popover={init:function(a,b){var c=ko.toJS(b());$(a).popover(c)},update:function(a,b){$(a).attr("data-original-title",d(b().title)),$(a).attr("data-content",d(b().content))}},ko.extenders.variableName=function(a){var b=ko.computed({read:a,write:function(b){var c=a();b=b.replace(/[^A-Za-z0-9]/g,""),c!==b&&a(b)}});return b(a()),b},c.exports={objectEquals:e}}),define("view/undo-button-view",["require","exports","module"],function(a,b,c){function g(){d=$("#undo-btn"),e=$(".action-label",d),i(),d.click(function(){f(),d.hide()})}function h(a,b){d.show(),e.text(a),f=b}function i(){d.hide(),f=null,e.text("")}var d,e,f;c.exports={init:g,show:h,hide:i},g()}),define("view/divider-drag",["require","exports","module"],function(a,b,c){c.exports=function(){function j(a){a>h-b?a=h-b:a<b&&(a=b),i=a,d.outerHeight(a-g/2),e.outerHeight(h-a-g),f.css("top",a),$(".main-area .panel").height(d.innerHeight()-44)}var a=10,b=50,c=$(".main-area"),d=$(".top-panel",c),e=$(".bottom-panel",c),f=$(".divider",c),g=f.outerHeight(),h=c.innerHeight(),i=0;j(h-h/3),f.mousedown(function(){var a=function(a){var b=a.pageY-c.offset().top;return j(b),!1};return $(window).mousemove(a),$(window).mouseup(function(){return $(window).unbind("mousemove",a),!1}),!1}),$(window).resize(function(){var a=i/h;h=c.innerHeight(),j(h*a)})}}),define("model/resource",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.Model.extend({defaults:{path:"",order:0},parse:function(a){return a.$renameFrom=a.path,a},initialize:function(){this.on("change:path",this.sanitizePath,this)},sanitizePath:function(){var a=this.get("path");a=d.sanitizePath(a),a!==this.get("path")&&this.set({path:a})}});d.sanitizePath=function(a){return a=a.toLowerCase().replace(/[ _]/g,"-").replace(/[^a-z0-9\/\-]/g,""),_.str.startsWith(a,"/")||(a="/"+a),a}}),define("model/resource-collection",["require","exports","module","../model/resource","../app"],function(a,b,c){var d=a("../model/resource"),e=a("../app"),f=c.exports=Backbone.Collection.extend({model:d,url:"/resources",initialize:function(){this.on("error",this.error,this)},comparator:function(a){return a.get("order")},error:function(){e.set({authKey:undefined},{silent:!0}),e.trigger("change:authKey")},fetch:function(a){a=_.extend(a||{},{data:{q:'{"type": {"$ne": "Static"}}'}}),Backbone.Collection.prototype.fetch.call(this,a)}})}),define("view/template-view",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.View.extend({initialize:function(){this.template=_.template($("#"+this.template).html()),this.render(),this.model&&this.model.on("change",this.render,this),this.collection&&(this.collection.on("reset",this.render,this),this.collection.on("add",this.render,this),this.collection.on("remove",this.render,this))},templateData:function(){return{model:this.model,collection:this.collection}},render:function(){$(this.el).html(this.template(this.templateData()))}})}),define("view/auth-modal-view",["require","exports","module","../app","./template-view"],function(a,b,c){var d=a("../app"),e=a("./template-view"),f=c.exports=e.extend({el:"#authModal",template:"auth-modal-template",initialize:function(){_.bindAll(this),e.prototype.initialize.apply(this,arguments),this.$el=$(this.el).modal({show:!1}),this.$el.on("click",".save",this.saveAuthToken),this.$el.on("hidden",this.cancel)},saveAuthToken:function(){return this.hide(),setTimeout(_.bind(function(){var a=this.$el.find("[name=key]").val();d.set({authKey:a},{silent:!0}),d.trigger("change:authKey")},this),0),!1},show:function(){this.$el.find("[name=key]").val(d.get("authKey")),this.$el.modal("show")},hide:function(){this._programHide=!0,setTimeout(_.bind(function(){this._programHide=!1},this),0),this.$el.modal("hide")},update:function(){d.get("authKey")?this.hide():this.show()},showError:function(){this.$el.find(".key-error").show()},hideError:function(){this.$el.find(".key-error").hide()},cancel:function(){this._programHide||setTimeout(this.show,0)}})}),define("view/resource-sidebar-view",["require","exports","module","./template-view","../app"],function(a,b,c){var d=a("./template-view"),e=a("../app"),f=c.exports=d.extend({el:"#resource-sidebar",template:"resource-sidebar-template",initialize:function(){e.on("change:resourceId",this.render,this),e.on("change:files",this.render,this),d.prototype.initialize.apply(this,arguments)},templateData:function(){return _.extend(d.prototype.templateData.apply(this),{app:e.toJSON()})}})}),define("view/component-type-sidebar-view",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.View.extend({events:{"click li":"onAddItem"},initialize:function(){this.collection=this.collection||this.options.collection,this.template=this.template||this.options.template,this.listView=this.listView||this.options.listView,this.collection.on("reset",this.render,this)},render:function(){var a=this;$(this.el).html(this.template({types:this.collection})),a.$("li").each(function(){}).popover({placement:"right"})},onAddItem:function(a){var b=$(a.currentTarget).attr("data-cid"),c=this.collection.getByCid(b);this.listView.addItem(c)}})}),define("model/resource-type-collection",["require","exports","module","../backbone-utils"],function(a,b,c){a("../backbone-utils");var d=c.exports=Backbone.Collection.extend({url:"/types",sort:function(a){return a.get("label")},parse:function(a){return Object.keys(a).forEach(function(b){b==="Collection"?(a[b].tooltip="Add a simple store to save, update, fetch and delete JSON objects. Available over REST at the specified url.",a[b].tooltipTitle="Persist Data"):b==="UserCollection"?(a[b].tooltip="Add a collection of users such as 'admins', 'authors', or just 'users'. Store users as JSON objects and log them in over REST.",a[b].tooltipTitle="Manage Users"):b==="Static"&&delete a[b]}),Backbone.Utils.parseDictionary(a)}})}),define("view/header-view",["require","exports","module","../model/resource","./save-status-view","./undo-button-view"],function(a,b,c){var d=a("../model/resource"),e=a("./save-status-view"),f=a("./undo-button-view"),g=c.exports=Backbone.View.extend({el:"#header",template:_.template($("#header-template").html()),events:{"click .resourceName":"rename"},initialize:function(){this.model.on("change",this.render,this),this.render()},rename:function(){var a=this.model.get("resource"),b=prompt("Enter a new name for this "+a.get("type"),a.get("path"));return b&&(b=d.sanitizePath(b),a.save({path:b,$renameFrom:a.get("path")}),this.model.set("resourceName",b)),!1},render:function(){return $(this.el).html(this.template(this.model.toJSON())),e.init(!0),f.init(),this}})}),define("model/property-type-collection",["require","exports","module","../backbone-utils"],function(a,b,c){a("../backbone-utils");var d=c.exports=Backbone.Collection.extend({url:"/property-types",sort:function(a){return a.get("label")},parse:function(a){return Object.keys(a).forEach(function(b){b==="string"?(a[b].tooltip="Add a string property. If the incoming value is not a string it will be rejected.",a[b].tooltipTitle="Arbitrary Text"):b==="number"?(a[b].tooltip="Add a number property. If the incoming value is not a number it will be rejected.",a[b].tooltipTitle="JSON Number"):b==="boolean"?(a[b].tooltip="Add a boolean property. If the incoming value is not 'true' or 'false' it will be rejected.",a[b].tooltipTitle="True or false"):b==="date"&&(a[b].tooltip="Add a date string property. If the incoming value is not a valide date string it will be rejected.",a[b].tooltipTitle="specific point in time")}),Backbone.Utils.parseDictionary(a)}})}),define("model/data-collection",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.Collection.extend({url:function(){var a=this.path;return this.querystring&&(this.querystring.indexOf("{")==0?a+="?q="+this.querystring:a+="?"+this.querystring),a}})}),define("view-model/property-view-model",["require","exports","module"],function(a,b){function d(a,b){function g(a,b){return console.log(b.which),b.metaKey||b.which===38||b.which===40?(f[b.which]&&f[b.which](a),!1):!0}a=_.defaults(a||{},{name:" ",type:"string",typeLabel:"string",optional:!1,required:!0}),a._id=a.name;var d=ko.mapping.fromJS(a,c);d.name=d.name.extend({variableName:!0}),d.editing=ko.observable(!1),d.nameFocus=ko.observable(),d.isNew=b!=null,d.toggleEditing=function(){return d.editing(!d.editing()),d.editing()&&d.nameFocus(!0),!1},d.onClickHeader=function(a,b){return!d.editing()||b.target===b.currentTarget||$(b.target).is("div")?(d.toggleEditing(),!1):!0},d.onNameKeypress=function(a,c){return c.which==13&&setTimeout(function(){d.isNew?b.addProperty():d.editing(!1)},1),!0},d.onNameKeyDown=function(a,b){return f[b.which]?g(a,b):!0},d.setType=function(a){d.type(ko.utils.unwrapObservable(a._id)),d.typeLabel(ko.utils.unwrapObservable(a.label)),d.type()==="boolean"&&d.optional(!1)};var e=["string","number","boolean","date"],f={66:function(a){a.type("boolean")},83:function(a){a.type("string")},77:function(a){a.type("number")},68:function(a){a.type("date")},38:function(a){var b=a.type();for(var c=0;c<e.length;c++)if(b===e[c]){a.type(e[c+1]||e[0]);return}},40:function(a){var b=a.type();for(var c=0;c<e.length;c++)if(b===e[c]){a.type(e[c-1]||e[e.length-1]);return}},79:function(a){a.optional(!a.optional())}};return d}var c={include:["optional","_id","$renameFrom"]};b.create=d}),define("view-model/property-list-view-model",["require","exports","module","../view/undo-button-view","./property-view-model"],function(a,b){function e(){var a={properties:ko.observableArray(),propertyTypes:ko.observableArray()};return a.newProperty=d.create({},a),a.newProperty.nameFocus(!0),a.addProperty=_.bind(function(){this.newProperty.name()&&this.newProperty.type()&&(this.properties.push(d.create(ko.mapping.toJS(this.newProperty))),this.newProperty.name(""))},a),a.removeProperty=_.bind(function(a){var b=this,d=this.properties.indexOf(a);c.show("Delete "+a.name(),function(){b.properties.splice(d,0,a)}),this.properties.remove(a)},a),a.onNewNameKeypress=_.bind(function(b,c){return c.which==13&&setTimeout(function(){a.addProperty()},1),!0},a),a}var c=a("../view/undo-button-view"),d=a("./property-view-model");b.create=e}),define("view/property-list-view",["require","exports","module","../knockout-utils","../app","./undo-button-view","../view-model/property-list-view-model","../view-model/property-view-model"],function(a,b,c){var d=a("../knockout-utils"),e=a("../app"),f=a("./undo-button-view"),g=a("../view-model/property-list-view-model"),h=a("../view-model/property-view-model"),i=c.exports=Backbone.View.extend({el:"#property-list",template:_.template($("#property-list-template").html()),initialize:function(){this.collection=this.collection||this.options.collection,this.typeCollection=this.typeCollection||this.options.typeCollection,this.initializeViewModel(),this.mapProperties(),this.collection.on("reset",this.mapProperties,this),this.mapTypes(),this.typeCollection.on("reset",this.mapTypes,this),this.render()},initializeViewModel:function(){var a=this;this.viewModel=g.create(),this.mapping={properties:{key:function(a){return ko.utils.unwrapObservable(a.name)},create:_.bind(function(a){return h.create(a.data)},this)}},ko.computed(function(){var b=a._lastJSON,c=ko.mapping.toJS(this),e=c.properties;b&&!d.objectEquals(b,e)&&(a.collection.reset(c.properties,{silent:!0}),a.collection.trigger("update"),a._lastJSON=e)},this.viewModel).extend({throttle:100})},mapProperties:function(){var a=this.collection.toJSON();this._lastJSON=a,ko.mapping.fromJS({properties:a},this.mapping,this.viewModel);var b=ko.mapping.toJS(this.viewModel);d.objectEquals(b.properties,a)||(console.log("WARNING: viewmodel/model mismatched. Remapping..."),this.viewModel.properties.removeAll(),setTimeout(_.bind(this.mapProperties,this),1))},mapTypes:function(){ko.mapping.fromJS({propertyTypes:this.typeCollection.toJSON()},this.mapping,this.viewModel)},render:function(){this.el&&ko.cleanNode(this.el),$(this.el).html(this.template({resourceTypeId:e.get("resourceTypeId")})),ko.applyBindings(this.viewModel,this.el)},close:function(){ko.removeNode(this.el)}})}),define("view/property-reference-view",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.View.extend({el:"#property-reference",template:_.template($("#property-reference-template").html()),initialize:function(){this.render(),this.model.on("change",this.render,this)},render:function(){$(this.el).html(this.template({model:this.model})),this.$("li i").tooltip({placement:"left"})}})}),define("view-model/collection-data-view-model",["require","exports","module"],function(a,b,c){createRow=b.createRow=function(a,b,c){function e(a,b){var c={_id:null};b.forEach(function(a){c[a.name]=undefined}),a=_.defaults(a,c),ko.mapping.fromJS(a,{},d)}var d={};return e(a,b),d.c_editing=ko.observable(!1),d.c_focus=ko.observable(),d.c_errors=ko.observable({}),d.c_formatted=function(a,b){var a=ko.utils.unwrapObservable(a),b=ko.utils.unwrapObservable(b),c=ko.utils.unwrapObservable(d[a]);return b==="password"||typeof c=="undefined"?"...":c},d.c_toggleEditing=function(){d.c_editing()&&!d.isNew?c.revertRow(d):d.c_editing(!0)},d.c_remapProps=function(a){var b=ko.mapping.toJS(d);e(b,a)},d._onKeypress=function(a,b){return b.which==13?setTimeout(function(){c.saveRow(d)},1):b.which==27&&!d.isNew&&setTimeout(function(){c.revertRow(d)},1),!0},d._onDoubleclick=function(a,b){if(!!d.c_editing())return!0;d.c_editing(!0),d.c_focus(a.name())},d},create=b.create=function(){var a={properties:ko.observableArray(),collection:ko.observableArray(),queryString:ko.observable(),queryError:ko.observable("")};return a.newRow=createRow({},[],a),a.newRow.isNew=!0,a}}),define("view/collection-data-view",["require","exports","module","../view-model/collection-data-view-model","../app","./undo-button-view"],function(a,b,c){var d=a("../view-model/collection-data-view-model"),e=a("../app"),f=a("./undo-button-view"),g=c.exports=Backbone.View.extend({el:"#data",template:_.template($("#collection-data-template").html()),initialize:function(){var a=this;a.properties=a.options.properties,a.collection=a.options.collection,a.initializeViewModel(),a.initializeMapping(),a.isUser=e.get("resourceTypeId")==="UserCollection",a.mapProperties(),a.properties.on("reset",a.mapProperties,a),a.properties.on("add",a.mapProperties,a),a.properties.on("remove",a.mapProperties,a),a.properties.on("change:name",a.mapProperties,a),a.mapCollection(),a.collection.on("reset",a.mapCollection,a),a.collection.on("add",a.mapCollection,a),a.collection.on("remove",a.mapCollection,a),function b(c,d){d&&d.responseText?a.viewModel.queryError(d.responseText):a.viewModel.queryError(""),a._timeout=setTimeout(function(){a.collection.fetch({success:b,error:b})},1e3)}(),a.render()},initializeViewModel:function(){var a=this,b=a.viewModel=d.create();b.deleteRow=function(b){var c=a.collection,d=c.get(b._id()),e=c.indexOf(d);d&&d.destroy({wait:!0}),d.set("_id",undefined),f.show("Delete row",function(){c.create(d,{at:e})})},b.saveRow=function(c){function f(a,b){try{var d=JSON.parse(b.responseText);c.c_errors(d.errors)}catch(e){alert("An error occurred when saving: "+b.responseText)}}var d=ko.mapping.toJS(c),e=a.collection;if(c.isNew)e.create(d,{success:function(){c.c_errors({}),b.properties().forEach(function(a){c[a.name()]&&c[a.name()](null)})},error:f,wait:!0});else{var g=e.get(c._id());g.save(d,{success:function(){c.c_editing(!1),c.c_errors({}),ko.mapping.fromJS(g.toJSON(),{},c)},error:f})}},b.revertRow=function(b){var c=a.collection,d=c.get(b._id());d.fetch({success:function(){ko.mapping.fromJS(d.toJSON(),{},b),b.c_editing(!1)}})},ko.computed(function(){a.collection.querystring=b.queryString()},b).extend({throttle:100}),ko.computed(function(){var c=b.queryError(),d=a.$("#current-data-querystring");c?d.attr("data-original-title",c).tooltip("fixTitle").tooltip("show"):d.attr("data-original-title","").tooltip("fixTitle").tooltip("hide")},b)},initializeMapping:function(){var a=this,b=this.viewModel;a.propertiesMapping={properties:{key:function(a){return ko.utils.unwrapObservable(a._id)}}},a.collectionMapping={collection:{key:function(a){return ko.utils.unwrapObservable(a._id)},create:function(a){return d.createRow(a.data,ko.mapping.toJS(b.properties),b)},update:function(a){return a.target.c_editing()?a.data:a.target}}}},mapProperties:function(){var a=this.properties.toJSON();e.get("resourceTypeId")==="UserCollection"&&a.unshift({name:"email",type:"string",typeLabel:"string"},{name:"password",type:"password",typeLabel:"password"}),this.viewModel.collection().forEach(function(b){b.c_remapProps(a)}),this.viewModel.newRow.c_remapProps(a),ko.mapping.fromJS({properties:a},this.propertiesMapping,this.viewModel)},mapCollection:function(){ko.mapping.fromJS({collection:this.collection.toJSON()},this.collectionMapping,this.viewModel)},render:function(){var a=this;ko.cleanNode(this.el),$(this.el).html(this.template({resourceType:e.get("resourceTypeId")})),ko.applyBindings(this.viewModel,this.el)},close:function(){clearTimeout(this._timeout),ko.removeNode(this.el)}})}),define("view/code-editor-view",["require","exports","module"],function(a,b,c){function i(a){return h||(h=ace.edit(g[0]),h.setTheme("ace/theme/deployd"),h.setShowPrintMargin(!1)),$(a).append(g),h}var d=ace.require("ace/mode/javascript").Mode,e=ace.require("ace/mode/css").Mode,f=ace.require("ace/mode/html").Mode,g=$("<div>"),h,j=c.exports=Backbone.View.extend(Backbone.Events).extend({initialize:function(){this.mode=this.options.mode,_.bindAll(this,"trackUpdate","update","render")},trackUpdate:function(){this._timeout&&clearTimeout(this._timeout);var a=this.updateTime||1e3;this._timeout=setTimeout(this.update,a)},update:function(){this.trigger("change")},getText:function(){return this.editor?this.editor.getSession().getValue():undefined},setText:function(a){this.editor.getSession().setValue(a),clearTimeout(this._timeout)},resize:function(){this.editor.resize()},render:function(){var a=this,b=i(this.el);b.resize();var c=this.mode||"js";return c==="html"||c==="htm"?b.getSession().setMode(new f):c==="css"?b.getSession().setMode(new e):c==="js"&&b.getSession().setMode(new d),b.getSession().on("change",this.trackUpdate),b.commands.addCommand({name:"save",bindKey:{win:"Ctrl-S",mac:"Command-S"},exec:function(b){a.trigger("save")}}),this.editor=b,b.focus(),this},close:function(){this._timeout&&clearTimeout(this._timeout),this.off(),this.setText("")}})}),define("view/collection-event-view",["require","exports","module","./code-editor-view"],function(a,b,c){var d=a("./code-editor-view"),e=c.exports=Backbone.View.extend({template:_.template($("#events-template").html()),events:{"click #event-nav a":"updateRender"},initialize:function(){var a=this;$(this.el).html(this.template(this.model.toJSON())),this.editor=(new d({})).render(),this.editor.on("change",a.update,a),this.resize=_.bind(this.resize,this),$("#resource-sidebar").on("click","a",this.resize)},getActive:function(){return this.$("#event-nav .active a").attr("data-editor")},update:function(a){var b=this.editor.getText();typeof b!="undefined"&&this.model.set(this.getActive(),b)},updateRender:function(){this.update(),setTimeout(_.bind(this.render,this),1)},render:function(){var a=this.getActive();return this.editor.setText(this.model.get(a)),this.editor.setElement("#"+a),this.editor.render(),this},resize:function(){this.editor.resize()},close:function(){$("#resource-sidebar").off("click","a",this.resize),this.editor.close()}})}),define("view/collection-routes-view",["require","exports","module"],function(a,b,c){var d=c.exports=Backbone.View.extend({el:"#api",template:_.template($("#collection-routes-template").html(),null,{variable:"resourceData"}),initialize:function(){this.render(),this.model.on("change",this.render,this)},render:function(){$(this.el).html(this.template(this.model.toJSON())),prettyPrint()}})}),define("model/file",["require","exports","module","../app"],function(a,b,c){var d=a("../app"),e=c.exports=Backbone.Model.extend({url:function(){var a=this.get("info"),b=this.get("path");return a?b+"/"+a.fileName:b},sync:function(a,b,c){function g(){}var e=this,f=arguments,h=b.get("info"),i=b.get("data");if(a==="create"&&(h||i)){var j;if(h)j=new FormData,j.append("data",h);else if(i||i==="")j=i;var k=_.isFunction(b.url)?b.url():b.url;k=d.get("appUrl")+k;var l=new XMLHttpRequest;l.open("POST",k),l.setRequestHeader("x-dssh-key",d.get("authKey")),l.send(j),l.addEventListener("readystatechange",function(){typeof c.success=="function"&&c.success(),e.trigger("sync")})}else Backbone.sync.apply(b,f)}})}),define("view-model/folder-view-model",["require","exports","module","model/file","model/resource","app"],function(a,b,c){function i(a){return{data:a}}function j(a){return a=_.extend(a||{},{data:{type:"Static"}}),Backbone.Collection.prototype.fetch.call(this,a)}var d=a("model/file"),e=a("model/resource"),f=a("app"),g={folders:{key:function(a){return ko.utils.unwrapObservable(a.path)}}},h=b.template={eventIsButton:function(a){var b=$(a.target);return b.is("a")||b.parentsUntil(".file, .folder").is("a")?!0:!1},mapFiles:function(){this.files(this.model.get("data"))},mapFolders:function(){var a=[],b=this;this.foldersCollection.each(function(c){var d=c.get("path");if(d==="/")return;var e="/"+b.getPath("");if(d.indexOf(e)!==-1){var f=d.slice(e.length);if(f.length&&f.indexOf("/")===-1){var g=_.find(b.folders(),function(a){return a.path===d});g||(c.urlRoot=b.foldersCollection.url,g={path:d,name:f,model:c,isOpen:ko.observable(!1),viewModel:k(d)}),b.foldersToOpen[d]&&(g.isOpen(!0),delete b.foldersToOpen[d]),a.push(g)}}}),b.folders(a)},fetch:function(){this.fetchFiles(),this.fetchFolders(),_.each(this.folders(),function(a){a.isOpen()&&a.viewModel.fetch()})},fetchFolders:function(){this.foldersCollection.fetch()},fetchFiles:function(){this.model.fetch()},getPath:function(a){var b=this.path.slice(1);return this.path!=="/"&&(b+="/"),b+a},deleteFile:function(a){var b=new d({path:"/",info:{fileName:a},_id:a}),c=this;b.destroy({success:function(){c.fetchFiles()}})},editFile:function(a){f.set("new file",!1),f.set("files",this.getPath(a))},onClickFile:function(a,b){if(!!this.eventIsButton(b))return!0;this.editFile(a)},onChangeUpload:function(a,b){var c=b.target.files&&b.target.files,d=this;_.each(c,d.uploadFile)},uploadFile:function(a){var b=new d({info:a,path:this.path}),c=a.fileName,e=this;this.uploadingFiles.push(c),b.on("sync",function(){e.fetchFiles(),e.uploadingFiles.remove(c)}),b.save()},addFile:function(){var a=prompt("Enter a name for this file, including the extension:");a&&(f.set("new file",!0),f.set("files",this.getPath(a)))},deleteFolder:function(a){var b=this;a.model.destroy({success:function(){b.fetchFolders()}})},addFolder:function(){var a=prompt("Enter a name for this folder:"),b=this;if(a){var c=e.sanitizePath(a);b.path!=="/"&&(c=b.path+c),this.foldersCollection.create({path:c,type:"Static"},{success:function(){b.foldersToOpen[c]=!0,b.fetchFolders()}})}},toggleFolder:function(a){a.isOpen(!a.isOpen()),a.isOpen()&&a.viewModel.fetch()},onClickFolder:function(a,b){if(!!this.eventIsButton(b))return!0;this.toggleFolder(a)}},k=b.create=function(a){a=a||"/";var b=Object.create(h);_.bindAll(b),b.path=a,b.model=new Backbone.Model,b.model.parse=i,b.model.url=a,b.model.on("change:data",b.mapFiles,b);var c=b.foldersCollection=new Backbone.Collection;return c.url="/resources",c.fetch=j,c.on("reset",b.mapFolders,b),b.foldersToOpen={},b.files=ko.observableArray(),b.folders=ko.observableArray(),b.uploadingFiles=ko.observableArray(),b.uploadingText=ko.computed(function(){var a=this.uploadingFiles().length;return a==1?"Uploading "+this.uploadingFiles()[0]+"...":a?"Uploading "+a+" files...":""},b),b}}),define("view/static-view",["require","exports","module","view-model/folder-view-model"],function(a,b,c){var d=a("view-model/folder-view-model"),e,f=c.exports=Backbone.View.extend({template:_.template($("#static-template").html()),initialize:function(){this.initializeViewModel(),this.render()},initializeViewModel:function(){e||(e=d.create()),this.viewModel=e,this.viewModel.fetch()},render:function(){this.$el.html(this.template({})),ko.cleanNode(this.el),ko.applyBindings(this.viewModel,this.el),prettyPrint()},close:function(){ko.removeNode(this.el)}})}),define("view/file-editor-view",["require","exports","module","../app","../model/file","./code-editor-view"],function(a,b,c){var d=a("../app"),e=a("./code-editor-view"),f=a("../model/file"),g=a("./save-status-view"),h=c.exports=Backbone.View.extend(Backbone.Events).extend({template:_.template($("#file-editor-template").html()),events:{"click .back":"back","click #save-btn":"save"},initialize:function(){$(this.el).html(this.template({}));var a=this.path="/"+d.get("files"),b=this,c=a.slice(a.indexOf(".")+1),f=this.editor=(new e({el:$("#editor"),mode:c})).render();f.updateTime=1,_.bind(b.save,b),f.on("save",function(){b.save()}),f.on("change",function(){b.hasChanges()});if(d.get("new file")){if(a.indexOf(".html")>-1||a.indexOf(".htm")>-1)f.setText($("#empty-html-template").html().replace(/\n/,"").replace(/xscript/g,"script")),b.hasChanges()}else $.get(a,function(a){f.setText(a)},"text"),b.saved();var g=$(".editor-container"),h=$(window);h.resize(function(){g.height(h.height()-200),f.resize()}),h.resize()},back:function(){return d.set("files",!0),!1},save:function(){var a=new f({path:this.path,data:this.editor.getText()});a.save({},{success:function(){g.saved()}}),this.saved(),g.saving()},hasChanges:function(){$("#file-status").empty().append('<i class="icon-file"></i> '+this.link()+' <i class="icon-asterisk"></i>'),$("#save-btn").removeAttr("disabled")},link:function(){return'<a href="'+this.path+'" target="_blank">'+this.path+"</a>"},saved:function(){$("#file-status").empty().append('<i class="icon-file"></i> '+this.link()),$("#save-btn").attr("disabled",!0)},close:function(){this.editor.close()}})}),define("router",["require","exports","module","./app"],function(a,b,c){var d=a("./app"),e=Backbone.Router.extend({routes:{"":"home",files:"files","files/*path":"editFile",":id":"resource"},home:function(){d.set({resourceId:undefined,files:undefined})},resource:function(a){d.set({resourceId:a,files:undefined})},files:function(){d.set({resourceId:undefined,files:!0})},editFile:function(a){d.set({resourceId:undefined,files:a})}});c.exports=new e}),define("view/resource-view",["require","exports","module","./undo-button-view","../router"],function(a,b,c){var d=a("./undo-button-view"),e=a("../router"),f=_.template($("#resource-template").html()),g=c.exports=Backbone.View.extend({tagName:"li",className:"component-item",events:{"click .delete-btn":"delete","click .component-item-header":"onClickHeader","click .path":"activate","click .rename-btn":"activate","click .cancel-btn":"deactivate","click .save-btn":"save",'keypress input[name="path"]':"onKeypress",'keyup input[name="path"]':"onKeyup"},initialize:function(){this.parentView=this.options.parentView,this.model.on("change:c_active",this.render,this),this.model.on("change:_id",this.render,this),this.model.on("change:path",this.render,this)},render:function(){var a=$(this.el);return a.attr("id",this.model.cid).html(f({resource:this.model.toJSON()})),this.model.isNew()?a.addClass("unsaved"):a.removeClass("unsaved"),this},gotoDetail:function(){return this.model.isNew()||e.navigate(this.model.get("_id"),{trigger:!0}),!1},"delete":function(){var a=this;return a.model.isNew()?a.model.destroy():confirm("Do you wish to delete this resource? All associated data and configuration will be permanently removed.")&&a.model.destroy({wait:!0}),!1},activate:function(){return this.model.set({c_active:!0}),this.$('input[name="path"]').focus(),!1},deactivate:function(){return this.model.isNew()?this.delete():this.model.set({c_active:!1}),!1},save:function(){return this.model.save({path:this.$('input[name="path"]').val()}),this.model.set({c_active:!1}),!1},onClickHeader:function(a){if($(a.target).hasClass("component-item-header")||$(a.target).hasClass("type-icon"))return this.model.get("c_active")?this.deactivate():this.gotoDetail(),!1;this.onFocus(a)},onFocus:function(a){$(a.target).focus()},onKeypress:function(a){var b=$(a.currentTarget).val();_.str.startsWith(b,"/")||(b="/"+b,$(a.currentTarget).val(b))},onKeyup:function(a){a.which==13&&(this.model.isNew()?this.model.save({path:this.$('input[name="path"]').val()},{success:_.bind(function(){this.gotoDetail()},this)}):this.save()),a.which==27&&this.deactivate()},destroy:function(){this.model.off("change:c_active",this.render),this.model.off("change:_id",this.render),this.model.off("change:path",this.render)}})}),define("view/resource-list-view",["require","exports","module","../model/resource","./resource-view"],function(a,b,c){var d=a("../model/resource"),e=a("./resource-view"),f=c.exports=Backbone.View.extend({el:"#resource-list",emptyEl:"#resource-list-empty",subViews:[],initialize:function(){this.parentView=this.options.parentView,this.collection=this.options.collection,this.typeCollection=this.options.typeCollection,this.collection.on("reset",this.render,this),this.collection.on("add",this.render,this),this.collection.on("remove",this.render,this),this.initializeDom(),this.render()},initializeDom:function(){},addItem:function(a,b){isNaN(b)&&(b=this.collection.length);var c=new d({path:a.get("defaultPath"),typeLabel:a.get("label"),type:a.get("_id"),order:b+1,c_active:!0});return this.collection.add(c,{at:b}),this.updateOrder(),setTimeout(function(){this.$("#"+c.cid).find('input[name="path"]').focus()},0),!1},updateOrder:function(){var a=this,b=[];$(this.el).children().each(function(){var c=a.collection.getByCid($(this).attr("id"));c&&b.push(c)});var c=0;_.each(b,function(a){c+=1,a.isNew()?a.set({order:c},{silent:!0}):a.save({order:c},{silent:!0})})},onReceiveComponent:function(a,b){var c=a.attr("data-cid"),d=this.parentView.resourceTypes.getByCid(c);a.remove(),this.addItem(d,b)},onReorder:function(){this.updateOrder()},render:function(a){var b=this;_.each(b.subViews,function(a){a.destroy()}),$(b.el).find("li:not(.locked)").remove(),b.collection.length?($(b.emptyEl).hide(),b.subViews=b.collection.map(function(a){var c=new e({model:a,parentView:b});return $(b.el).append(c.el),c.render(),c})):$(b.emptyEl).show()}})}),define("view/resources-view",["require","exports","module","./component-type-sidebar-view","./resource-list-view","./template-view","../model/resource-collection","../model/resource-type-collection","router"],function(a,b,c){var d=a("./component-type-sidebar-view"),e=a("./resource-list-view"),f=a("./template-view"),g=a("../model/resource-collection"),h=a("../model/resource-type-collection"),i=a("router"),j=c.exports=f.extend({el:"#resources-container",template:"resources-template",typesTemplate:_.template($("#resource-types-template").html()),events:{"click #property-types a":"addItem","click #files-resource":"goToFiles"},initialize:function(){this.resources=this.options.resources,this.resourceTypes=new h,f.prototype.initialize.apply(this,arguments),this.resourceListView=new e({collection:this.resources,typeCollection:this.resourceTypes,parentView:this}),this.resourceTypes.on("reset",this.renderTypes,this),this.resourceTypes.fetch()},goToFiles:function(){i.navigate("files",{trigger:!0})},addItem:function(a){var b=$(a.currentTarget).parents("li").attr("data-cid"),c=this.resourceTypes.getByCid(b);this.resourceListView.addItem(c)},renderTypes:function(){$("#property-types").html(this.typesTemplate({types:this.resourceTypes})).find("li").popover({placement:"left"})}})}),define("view/collection-view",["require","exports","module","../model/property-type-collection","../model/collection-settings","../model/data-collection","./property-list-view","./property-reference-view","./collection-data-view","./collection-event-view","./collection-routes-view","../app","../router","./undo-button-view"],function(a,b,c){var d=a("../model/property-type-collection"),e=a("../model/collection-settings"),f=a("../model/data-collection"),g=a("./property-list-view"),h=a("./property-reference-view"),i=a("./collection-data-view"),j=a("./collection-event-view"),k=a("./collection-routes-view"),l=a("../app"),m=a("../router"),n=a("./undo-button-view"),o=c.exports=Backbone.View.extend({template:_.template($("#collection-template").html()),events:{"click .cta-link":"onClickCta"},initialize:function(){$(this.el).html(this.template({})),this.propertyTypes=new d,this.dataCollection=new f([]),this.dataCollection.path=this.model.get("path"),this.dataCollection.fetch(),this.model.on("change:path",function(){this.dataCollection.path=this.model.get("path")},this),this.propertyListView=new g({collection:this.model.get("properties"),typeCollection:this.propertyTypes,parentView:this}),this.PropertyReferenceView=new h({model:this.model}),this.dataView=new i({properties:this.model.get("properties"),collection:this.dataCollection}),this.routesView=new k({model:this.model}),this.eventsView=(new j({el:this.$("#events-panel"),model:this.model})).render(),this.model.on("change",this.save,this),this.dataCollection.on("reset",this.render,this),this.model.on("change",this.render,this),this.propertyTypes.fetch(),this.render(),this.initializeDom()},initializeDom:function(){this.onKeypress=_.bind(this.onKeypress,this),$(".icon-info-sign").popover(),this.model.get("properties").length?this.$('#resource-sidebar a[href="#data"]').click():this.$('#resource-sidebar a[href="#properties"]').click()},save:function(){var a=this;this.model.save()},onKeypress:function(a){if((a.ctrlKey||a.metaKey)&&a.which=="83")return this.save(),a.preventDefault(),!1},onClickCta:function(a){var b=$(a.currentTarget).attr("href"),c=$('#resource-sidebar a[href="'+b+'"]');return c.click(),!1},navigate:function(a){var b=$(a.currentTarget),c=b.attr("href");return $(window).scrollTop($(c).offset().top-50),!1},render:function(){var a=$("#property-now-what");return this.model.get("properties").length&&!this.dataCollection.length?a.show():a.hide(),this},close:function(){Backbone.View.prototype.close.call(this),this.propertyListView.close(),this.dataView.close(),this.eventsView.close(),$(window).off("scroll",this.onScroll)}})}),define("view/app-view",["require","exports","module","../app","../router","./undo-button-view","./save-status-view","../model/resource-collection","./auth-modal-view","./resource-sidebar-view","./resources-view","./header-view","./collection-view","./static-view","./file-editor-view"],function(a,b,c){var d=a("../app"),e=a("../router"),f=a("./undo-button-view"),g=a("./save-status-view"),h=a("../model/resource-collection"),i=a("./auth-modal-view"),j=a("./resource-sidebar-view"),k=a("./resources-view"),l=a("./header-view"),m=a("./collection-view"),n=a("./static-view"),o=a("./file-editor-view"),p=c.exports=Backbone.View.extend({initialize:function(){this.resources=new h,this.modal=new i,this.authenticate(),d.on("change:authKey",this.authenticate,this),this.resources.on("reset",this.initRender,this),this.resources.on("error",this.modal.showError,this.modal)},authenticate:function(){d.get("authKey")?this.resources.fetch():this.modal.show()},initRender:function(){this.resourceSidebarView=new j({collection:this.resources}),this.resourceView=new k({resources:this.resources}),this.headerView=new l({model:d}),this.resources.off("reset",this.initRender,this),d.on("change:resource",this.render,this),d.on("change:files",this.render,this),this.render()},render:function(){this.bodyView&&this.bodyView.close();var a=d.get("resource"),b=d.get("files");if(d.get("resourceId")||b){var c=null;if(b)b!==!0?c=o:c=n;else if(a){var h=a.get("type");if(h==="Collection"||h==="UserCollection")c=m}if(c){var i=$("<div>");$("#body").empty().append(i),this.bodyView=new c({model:a,el:i})}$("#body-container").show(),$("#resources-container").hide();if(b){var j="/files";b!==!0&&(j+="/"+b),e.navigate(j)}else e.navigate(d.get("resourceId"))}else $("#body-container").hide(),$("#resources-container").show(),this.resources.fetch(),e.navigate("");f.init(),g.init()}}),q;p.init=function(){return q||(q=new p),q}}),define("entry",["require","exports","module","./backbone-utils","./knockout-utils","./view/undo-button-view","./view/divider-drag","./view/app-view","./router"],function(a,b,c){a("./backbone-utils"),a("./knockout-utils"),a("./view/undo-button-view"),a("./view/divider-drag");var d=a("./view/app-view"),e=a("./router");d.init(),Backbone.history.start()}) |
@@ -1,2 +0,2 @@ | ||
// Underscore.js 1.3.1 | ||
// Underscore.js 1.3.3 | ||
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. | ||
@@ -8,2 +8,2 @@ // Underscore is freely distributable under the MIT license. | ||
// http://documentcloud.github.com/underscore | ||
((function(){function A(a,b,c){if(a===b)return a!==0||1/a==1/b;if(a==null||b==null)return a===b;a._chain&&(a=a._wrapped),b._chain&&(b=b._wrapped);if(a.isEqual&&w.isFunction(a.isEqual))return a.isEqual(b);if(b.isEqual&&w.isFunction(b.isEqual))return b.isEqual(a);var d=i.call(a);if(d!=i.call(b))return!1;switch(d){case"[object String]":return a==String(b);case"[object Number]":return a!=+a?b!=+b:a==0?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if(typeof a!="object"||typeof b!="object")return!1;var e=c.length;while(e--)if(c[e]==a)return!0;c.push(a);var f=0,g=!0;if(d=="[object Array]"){f=a.length,g=f==b.length;if(g)while(f--)if(!(g=f in a==f in b&&A(a[f],b[f],c)))break}else{if("constructor"in a!="constructor"in b||a.constructor!=b.constructor)return!1;for(var h in a)if(w.has(a,h)){f++;if(!(g=w.has(b,h)&&A(a[h],b[h],c)))break}if(g){for(h in b)if(w.has(b,h)&&!(f--))break;g=!f}}return c.pop(),g}var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.slice,h=d.unshift,i=e.toString,j=e.hasOwnProperty,k=d.forEach,l=d.map,m=d.reduce,n=d.reduceRight,o=d.filter,p=d.every,q=d.some,r=d.indexOf,s=d.lastIndexOf,t=Array.isArray,u=Object.keys,v=f.bind,w=function(a){return new E(a)};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=w),exports._=w):a._=w,w.VERSION="1.3.1";var x=w.each=w.forEach=function(a,b,d){if(a==null)return;if(k&&a.forEach===k)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;e<f;e++)if(e in a&&b.call(d,a[e],e,a)===c)return}else for(var g in a)if(w.has(a,g)&&b.call(d,a[g],g,a)===c)return};w.map=w.collect=function(a,b,c){var d=[];return a==null?d:l&&a.map===l?a.map(b,c):(x(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),a.length===+a.length&&(d.length=a.length),d)},w.reduce=w.foldl=w.inject=function(a,b,c,d){var e=arguments.length>2;a==null&&(a=[]);if(m&&a.reduce===m)return d&&(b=w.bind(b,d)),e?a.reduce(b,c):a.reduce(b);x(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)});if(!e)throw new TypeError("Reduce of empty array with no initial value");return c},w.reduceRight=w.foldr=function(a,b,c,d){var e=arguments.length>2;a==null&&(a=[]);if(n&&a.reduceRight===n)return d&&(b=w.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=w.toArray(a).reverse();return d&&!e&&(b=w.bind(b,d)),e?w.reduce(f,b,c,d):w.reduce(f,b)},w.find=w.detect=function(a,b,c){var d;return y(a,function(a,e,f){if(b.call(c,a,e,f))return d=a,!0}),d},w.filter=w.select=function(a,b,c){var d=[];return a==null?d:o&&a.filter===o?a.filter(b,c):(x(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},w.reject=function(a,b,c){var d=[];return a==null?d:(x(a,function(a,e,f){b.call(c,a,e,f)||(d[d.length]=a)}),d)},w.every=w.all=function(a,b,d){var e=!0;return a==null?e:p&&a.every===p?a.every(b,d):(x(a,function(a,f,g){if(!(e=e&&b.call(d,a,f,g)))return c}),e)};var y=w.some=w.any=function(a,b,d){b||(b=w.identity);var e=!1;return a==null?e:q&&a.some===q?a.some(b,d):(x(a,function(a,f,g){if(e||(e=b.call(d,a,f,g)))return c}),!!e)};w.include=w.contains=function(a,b){var c=!1;return a==null?c:r&&a.indexOf===r?a.indexOf(b)!=-1:(c=y(a,function(a){return a===b}),c)},w.invoke=function(a,b){var c=g.call(arguments,2);return w.map(a,function(a){return(w.isFunction(b)?b||a:a[b]).apply(a,c)})},w.pluck=function(a,b){return w.map(a,function(a){return a[b]})},w.max=function(a,b,c){if(!b&&w.isArray(a))return Math.max.apply(Math,a);if(!b&&w.isEmpty(a))return-Infinity;var d={computed:-Infinity};return x(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},w.min=function(a,b,c){if(!b&&w.isArray(a))return Math.min.apply(Math,a);if(!b&&w.isEmpty(a))return Infinity;var d={computed:Infinity};return x(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g<d.computed&&(d={value:a,computed:g})}),d.value},w.shuffle=function(a){var b=[],c;return x(a,function(a,d,e){d==0?b[0]=a:(c=Math.floor(Math.random()*(d+1)),b[d]=b[c],b[c]=a)}),b},w.sortBy=function(a,b,c){return w.pluck(w.map(a,function(a,d,e){return{value:a,criteria:b.call(c,a,d,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0}),"value")},w.groupBy=function(a,b){var c={},d=w.isFunction(b)?b:function(a){return a[b]};return x(a,function(a,b){var e=d(a,b);(c[e]||(c[e]=[])).push(a)}),c},w.sortedIndex=function(a,b,c){c||(c=w.identity);var d=0,e=a.length;while(d<e){var f=d+e>>1;c(a[f])<c(b)?d=f+1:e=f}return d},w.toArray=function(a){return a?a.toArray?a.toArray():w.isArray(a)?g.call(a):w.isArguments(a)?g.call(a):w.values(a):[]},w.size=function(a){return w.toArray(a).length},w.first=w.head=function(a,b,c){return b!=null&&!c?g.call(a,0,b):a[0]},w.initial=function(a,b,c){return g.call(a,0,a.length-(b==null||c?1:b))},w.last=function(a,b,c){return b!=null&&!c?g.call(a,Math.max(a.length-b,0)):a[a.length-1]},w.rest=w.tail=function(a,b,c){return g.call(a,b==null||c?1:b)},w.compact=function(a){return w.filter(a,function(a){return!!a})},w.flatten=function(a,b){return w.reduce(a,function(a,c){return w.isArray(c)?a.concat(b?c:w.flatten(c)):(a[a.length]=c,a)},[])},w.without=function(a){return w.difference(a,g.call(arguments,1))},w.uniq=w.unique=function(a,b,c){var d=c?w.map(a,c):a,e=[];return w.reduce(d,function(c,d,f){if(0==f||(b===!0?w.last(c)!=d:!w.include(c,d)))c[c.length]=d,e[e.length]=a[f];return c},[]),e},w.union=function(){return w.uniq(w.flatten(arguments,!0))},w.intersection=w.intersect=function(a){var b=g.call(arguments,1);return w.filter(w.uniq(a),function(a){return w.every(b,function(b){return w.indexOf(b,a)>=0})})},w.difference=function(a){var b=w.flatten(g.call(arguments,1));return w.filter(a,function(a){return!w.include(b,a)})},w.zip=function(){var a=g.call(arguments),b=w.max(w.pluck(a,"length")),c=new Array(b);for(var d=0;d<b;d++)c[d]=w.pluck(a,""+d);return c},w.indexOf=function(a,b,c){if(a==null)return-1;var d,e;if(c)return d=w.sortedIndex(a,b),a[d]===b?d:-1;if(r&&a.indexOf===r)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===b)return d;return-1},w.lastIndexOf=function(a,b){if(a==null)return-1;if(s&&a.lastIndexOf===s)return a.lastIndexOf(b);var c=a.length;while(c--)if(c in a&&a[c]===b)return c;return-1},w.range=function(a,b,c){arguments.length<=1&&(b=a||0,a=0),c=arguments[2]||1;var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);while(e<d)f[e++]=a,a+=c;return f};var z=function(){};w.bind=function(b,c){var d,e;if(b.bind===v&&v)return v.apply(b,g.call(arguments,1));if(!w.isFunction(b))throw new TypeError;return e=g.call(arguments,2),d=function(){if(this instanceof d){z.prototype=b.prototype;var a=new z,f=b.apply(a,e.concat(g.call(arguments)));return Object(f)===f?f:a}return b.apply(c,e.concat(g.call(arguments)))}},w.bindAll=function(a){var b=g.call(arguments,1);return b.length==0&&(b=w.functions(a)),x(b,function(b){a[b]=w.bind(a[b],a)}),a},w.memoize=function(a,b){var c={};return b||(b=w.identity),function(){var d=b.apply(this,arguments);return w.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},w.delay=function(a,b){var c=g.call(arguments,2);return setTimeout(function(){return a.apply(a,c)},b)},w.defer=function(a){return w.delay.apply(w,[a,1].concat(g.call(arguments,1)))},w.throttle=function(a,b){var c,d,e,f,g,h=w.debounce(function(){g=f=!1},b);return function(){c=this,d=arguments;var i=function(){e=null,g&&a.apply(c,d),h()};e||(e=setTimeout(i,b)),f?g=!0:a.apply(c,d),h(),f=!0}},w.debounce=function(a,b){var c;return function(){var d=this,e=arguments,f=function(){c=null,a.apply(d,e)};clearTimeout(c),c=setTimeout(f,b)}},w.once=function(a){var b=!1,c;return function(){return b?c:(b=!0,c=a.apply(this,arguments))}},w.wrap=function(a,b){return function(){var c=[a].concat(g.call(arguments,0));return b.apply(this,c)}},w.compose=function(){var a=arguments;return function(){var b=arguments;for(var c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},w.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}},w.keys=u||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)w.has(a,c)&&(b[b.length]=c);return b},w.values=function(a){return w.map(a,w.identity)},w.functions=w.methods=function(a){var b=[];for(var c in a)w.isFunction(a[c])&&b.push(c);return b.sort()},w.extend=function(a){return x(g.call(arguments,1),function(b){for(var c in b)a[c]=b[c]}),a},w.defaults=function(a){return x(g.call(arguments,1),function(b){for(var c in b)a[c]==null&&(a[c]=b[c])}),a},w.clone=function(a){return w.isObject(a)?w.isArray(a)?a.slice():w.extend({},a):a},w.tap=function(a,b){return b(a),a},w.isEqual=function(a,b){return A(a,b,[])},w.isEmpty=function(a){if(w.isArray(a)||w.isString(a))return a.length===0;for(var b in a)if(w.has(a,b))return!1;return!0},w.isElement=function(a){return!!a&&a.nodeType==1},w.isArray=t||function(a){return i.call(a)=="[object Array]"},w.isObject=function(a){return a===Object(a)},w.isArguments=function(a){return i.call(a)=="[object Arguments]"},w.isArguments(arguments)||(w.isArguments=function(a){return!!a&&!!w.has(a,"callee")}),w.isFunction=function(a){return i.call(a)=="[object Function]"},w.isString=function(a){return i.call(a)=="[object String]"},w.isNumber=function(a){return i.call(a)=="[object Number]"},w.isNaN=function(a){return a!==a},w.isBoolean=function(a){return a===!0||a===!1||i.call(a)=="[object Boolean]"},w.isDate=function(a){return i.call(a)=="[object Date]"},w.isRegExp=function(a){return i.call(a)=="[object RegExp]"},w.isNull=function(a){return a===null},w.isUndefined=function(a){return a===void 0},w.has=function(a,b){return j.call(a,b)},w.noConflict=function(){return a._=b,this},w.identity=function(a){return a},w.times=function(a,b,c){for(var d=0;d<a;d++)b.call(c,d)},w.escape=function(a){return(""+a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")},w.mixin=function(a){x(w.functions(a),function(b){G(b,w[b]=a[b])})};var B=0;w.uniqueId=function(a){var b=B++;return a?a+b:b},w.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var C=/.^/,D=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};w.template=function(a,b){var c=w.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(c.escape||C,function(a,b){return"',_.escape("+D(b)+"),'"}).replace(c.interpolate||C,function(a,b){return"',"+D(b)+",'"}).replace(c.evaluate||C,function(a,b){return"');"+D(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return b?e(b,w):function(a){return e.call(this,a,w)}},w.chain=function(a){return w(a).chain()};var E=function(a){this._wrapped=a};w.prototype=E.prototype;var F=function(a,b){return b?w(a).chain():a},G=function(a,b){E.prototype[a]=function(){var a=g.call(arguments);return h.call(a,this._wrapped),F(b.apply(w,a),this._chain)}};w.mixin(w),x(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];E.prototype[a]=function(){var c=this._wrapped;b.apply(c,arguments);var d=c.length;return(a=="shift"||a=="splice")&&d===0&&delete c[0],F(c,this._chain)}}),x(["concat","join","slice"],function(a){var b=d[a];E.prototype[a]=function(){return F(b.apply(this._wrapped,arguments),this._chain)}}),E.prototype.chain=function(){return this._chain=!0,this},E.prototype.value=function(){return this._wrapped}})).call(this); | ||
((function(){function A(a,b,c){if(a===b)return a!==0||1/a==1/b;if(a==null||b==null)return a===b;a._chain&&(a=a._wrapped),b._chain&&(b=b._wrapped);if(a.isEqual&&w.isFunction(a.isEqual))return a.isEqual(b);if(b.isEqual&&w.isFunction(b.isEqual))return b.isEqual(a);var d=i.call(a);if(d!=i.call(b))return!1;switch(d){case"[object String]":return a==String(b);case"[object Number]":return a!=+a?b!=+b:a==0?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if(typeof a!="object"||typeof b!="object")return!1;var e=c.length;while(e--)if(c[e]==a)return!0;c.push(a);var f=0,g=!0;if(d=="[object Array]"){f=a.length,g=f==b.length;if(g)while(f--)if(!(g=f in a==f in b&&A(a[f],b[f],c)))break}else{if("constructor"in a!="constructor"in b||a.constructor!=b.constructor)return!1;for(var h in a)if(w.has(a,h)){f++;if(!(g=w.has(b,h)&&A(a[h],b[h],c)))break}if(g){for(h in b)if(w.has(b,h)&&!(f--))break;g=!f}}return c.pop(),g}var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.slice,h=d.unshift,i=e.toString,j=e.hasOwnProperty,k=d.forEach,l=d.map,m=d.reduce,n=d.reduceRight,o=d.filter,p=d.every,q=d.some,r=d.indexOf,s=d.lastIndexOf,t=Array.isArray,u=Object.keys,v=f.bind,w=function(a){return new I(a)};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=w),exports._=w):a._=w,w.VERSION="1.3.3";var x=w.each=w.forEach=function(a,b,d){if(a==null)return;if(k&&a.forEach===k)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;e<f;e++)if(e in a&&b.call(d,a[e],e,a)===c)return}else for(var g in a)if(w.has(a,g)&&b.call(d,a[g],g,a)===c)return};w.map=w.collect=function(a,b,c){var d=[];return a==null?d:l&&a.map===l?a.map(b,c):(x(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),a.length===+a.length&&(d.length=a.length),d)},w.reduce=w.foldl=w.inject=function(a,b,c,d){var e=arguments.length>2;a==null&&(a=[]);if(m&&a.reduce===m)return d&&(b=w.bind(b,d)),e?a.reduce(b,c):a.reduce(b);x(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)});if(!e)throw new TypeError("Reduce of empty array with no initial value");return c},w.reduceRight=w.foldr=function(a,b,c,d){var e=arguments.length>2;a==null&&(a=[]);if(n&&a.reduceRight===n)return d&&(b=w.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=w.toArray(a).reverse();return d&&!e&&(b=w.bind(b,d)),e?w.reduce(f,b,c,d):w.reduce(f,b)},w.find=w.detect=function(a,b,c){var d;return y(a,function(a,e,f){if(b.call(c,a,e,f))return d=a,!0}),d},w.filter=w.select=function(a,b,c){var d=[];return a==null?d:o&&a.filter===o?a.filter(b,c):(x(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},w.reject=function(a,b,c){var d=[];return a==null?d:(x(a,function(a,e,f){b.call(c,a,e,f)||(d[d.length]=a)}),d)},w.every=w.all=function(a,b,d){var e=!0;return a==null?e:p&&a.every===p?a.every(b,d):(x(a,function(a,f,g){if(!(e=e&&b.call(d,a,f,g)))return c}),!!e)};var y=w.some=w.any=function(a,b,d){b||(b=w.identity);var e=!1;return a==null?e:q&&a.some===q?a.some(b,d):(x(a,function(a,f,g){if(e||(e=b.call(d,a,f,g)))return c}),!!e)};w.include=w.contains=function(a,b){var c=!1;return a==null?c:r&&a.indexOf===r?a.indexOf(b)!=-1:(c=y(a,function(a){return a===b}),c)},w.invoke=function(a,b){var c=g.call(arguments,2);return w.map(a,function(a){return(w.isFunction(b)?b||a:a[b]).apply(a,c)})},w.pluck=function(a,b){return w.map(a,function(a){return a[b]})},w.max=function(a,b,c){if(!b&&w.isArray(a)&&a[0]===+a[0])return Math.max.apply(Math,a);if(!b&&w.isEmpty(a))return-Infinity;var d={computed:-Infinity};return x(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},w.min=function(a,b,c){if(!b&&w.isArray(a)&&a[0]===+a[0])return Math.min.apply(Math,a);if(!b&&w.isEmpty(a))return Infinity;var d={computed:Infinity};return x(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g<d.computed&&(d={value:a,computed:g})}),d.value},w.shuffle=function(a){var b=[],c;return x(a,function(a,d,e){c=Math.floor(Math.random()*(d+1)),b[d]=b[c],b[c]=a}),b},w.sortBy=function(a,b,c){var d=w.isFunction(b)?b:function(a){return a[b]};return w.pluck(w.map(a,function(a,b,e){return{value:a,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c===void 0?1:d===void 0?-1:c<d?-1:c>d?1:0}),"value")},w.groupBy=function(a,b){var c={},d=w.isFunction(b)?b:function(a){return a[b]};return x(a,function(a,b){var e=d(a,b);(c[e]||(c[e]=[])).push(a)}),c},w.sortedIndex=function(a,b,c){c||(c=w.identity);var d=0,e=a.length;while(d<e){var f=d+e>>1;c(a[f])<c(b)?d=f+1:e=f}return d},w.toArray=function(a){return a?w.isArray(a)?g.call(a):w.isArguments(a)?g.call(a):a.toArray&&w.isFunction(a.toArray)?a.toArray():w.values(a):[]},w.size=function(a){return w.isArray(a)?a.length:w.keys(a).length},w.first=w.head=w.take=function(a,b,c){return b!=null&&!c?g.call(a,0,b):a[0]},w.initial=function(a,b,c){return g.call(a,0,a.length-(b==null||c?1:b))},w.last=function(a,b,c){return b!=null&&!c?g.call(a,Math.max(a.length-b,0)):a[a.length-1]},w.rest=w.tail=function(a,b,c){return g.call(a,b==null||c?1:b)},w.compact=function(a){return w.filter(a,function(a){return!!a})},w.flatten=function(a,b){return w.reduce(a,function(a,c){return w.isArray(c)?a.concat(b?c:w.flatten(c)):(a[a.length]=c,a)},[])},w.without=function(a){return w.difference(a,g.call(arguments,1))},w.uniq=w.unique=function(a,b,c){var d=c?w.map(a,c):a,e=[];return a.length<3&&(b=!0),w.reduce(d,function(c,d,f){if(b?w.last(c)!==d||!c.length:!w.include(c,d))c.push(d),e.push(a[f]);return c},[]),e},w.union=function(){return w.uniq(w.flatten(arguments,!0))},w.intersection=w.intersect=function(a){var b=g.call(arguments,1);return w.filter(w.uniq(a),function(a){return w.every(b,function(b){return w.indexOf(b,a)>=0})})},w.difference=function(a){var b=w.flatten(g.call(arguments,1),!0);return w.filter(a,function(a){return!w.include(b,a)})},w.zip=function(){var a=g.call(arguments),b=w.max(w.pluck(a,"length")),c=new Array(b);for(var d=0;d<b;d++)c[d]=w.pluck(a,""+d);return c},w.indexOf=function(a,b,c){if(a==null)return-1;var d,e;if(c)return d=w.sortedIndex(a,b),a[d]===b?d:-1;if(r&&a.indexOf===r)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===b)return d;return-1},w.lastIndexOf=function(a,b){if(a==null)return-1;if(s&&a.lastIndexOf===s)return a.lastIndexOf(b);var c=a.length;while(c--)if(c in a&&a[c]===b)return c;return-1},w.range=function(a,b,c){arguments.length<=1&&(b=a||0,a=0),c=arguments[2]||1;var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);while(e<d)f[e++]=a,a+=c;return f};var z=function(){};w.bind=function(b,c){var d,e;if(b.bind===v&&v)return v.apply(b,g.call(arguments,1));if(!w.isFunction(b))throw new TypeError;return e=g.call(arguments,2),d=function(){if(this instanceof d){z.prototype=b.prototype;var a=new z,f=b.apply(a,e.concat(g.call(arguments)));return Object(f)===f?f:a}return b.apply(c,e.concat(g.call(arguments)))}},w.bindAll=function(a){var b=g.call(arguments,1);return b.length==0&&(b=w.functions(a)),x(b,function(b){a[b]=w.bind(a[b],a)}),a},w.memoize=function(a,b){var c={};return b||(b=w.identity),function(){var d=b.apply(this,arguments);return w.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},w.delay=function(a,b){var c=g.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},w.defer=function(a){return w.delay.apply(w,[a,1].concat(g.call(arguments,1)))},w.throttle=function(a,b){var c,d,e,f,g,h,i=w.debounce(function(){g=f=!1},b);return function(){c=this,d=arguments;var j=function(){e=null,g&&a.apply(c,d),i()};return e||(e=setTimeout(j,b)),f?g=!0:h=a.apply(c,d),i(),f=!0,h}},w.debounce=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)};c&&!d&&a.apply(e,f),clearTimeout(d),d=setTimeout(g,b)}},w.once=function(a){var b=!1,c;return function(){return b?c:(b=!0,c=a.apply(this,arguments))}},w.wrap=function(a,b){return function(){var c=[a].concat(g.call(arguments,0));return b.apply(this,c)}},w.compose=function(){var a=arguments;return function(){var b=arguments;for(var c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},w.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}},w.keys=u||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)w.has(a,c)&&(b[b.length]=c);return b},w.values=function(a){return w.map(a,w.identity)},w.functions=w.methods=function(a){var b=[];for(var c in a)w.isFunction(a[c])&&b.push(c);return b.sort()},w.extend=function(a){return x(g.call(arguments,1),function(b){for(var c in b)a[c]=b[c]}),a},w.pick=function(a){var b={};return x(w.flatten(g.call(arguments,1)),function(c){c in a&&(b[c]=a[c])}),b},w.defaults=function(a){return x(g.call(arguments,1),function(b){for(var c in b)a[c]==null&&(a[c]=b[c])}),a},w.clone=function(a){return w.isObject(a)?w.isArray(a)?a.slice():w.extend({},a):a},w.tap=function(a,b){return b(a),a},w.isEqual=function(a,b){return A(a,b,[])},w.isEmpty=function(a){if(a==null)return!0;if(w.isArray(a)||w.isString(a))return a.length===0;for(var b in a)if(w.has(a,b))return!1;return!0},w.isElement=function(a){return!!a&&a.nodeType==1},w.isArray=t||function(a){return i.call(a)=="[object Array]"},w.isObject=function(a){return a===Object(a)},w.isArguments=function(a){return i.call(a)=="[object Arguments]"},w.isArguments(arguments)||(w.isArguments=function(a){return!!a&&!!w.has(a,"callee")}),w.isFunction=function(a){return i.call(a)=="[object Function]"},w.isString=function(a){return i.call(a)=="[object String]"},w.isNumber=function(a){return i.call(a)=="[object Number]"},w.isFinite=function(a){return w.isNumber(a)&&isFinite(a)},w.isNaN=function(a){return a!==a},w.isBoolean=function(a){return a===!0||a===!1||i.call(a)=="[object Boolean]"},w.isDate=function(a){return i.call(a)=="[object Date]"},w.isRegExp=function(a){return i.call(a)=="[object RegExp]"},w.isNull=function(a){return a===null},w.isUndefined=function(a){return a===void 0},w.has=function(a,b){return j.call(a,b)},w.noConflict=function(){return a._=b,this},w.identity=function(a){return a},w.times=function(a,b,c){for(var d=0;d<a;d++)b.call(c,d)},w.escape=function(a){return(""+a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")},w.result=function(a,b){if(a==null)return null;var c=a[b];return w.isFunction(c)?c.call(a):c},w.mixin=function(a){x(w.functions(a),function(b){K(b,w[b]=a[b])})};var B=0;w.uniqueId=function(a){var b=B++;return a?a+b:b},w.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var C=/.^/,D={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"};for(var E in D)D[D[E]]=E;var F=/\\|'|\r|\n|\t|\u2028|\u2029/g,G=/\\(\\|'|r|n|t|u2028|u2029)/g,H=function(a){return a.replace(G,function(a,b){return D[b]})};w.template=function(a,b,c){c=w.defaults(c||{},w.templateSettings);var d="__p+='"+a.replace(F,function(a){return"\\"+D[a]}).replace(c.escape||C,function(a,b){return"'+\n_.escape("+H(b)+")+\n'"}).replace(c.interpolate||C,function(a,b){return"'+\n("+H(b)+")+\n'"}).replace(c.evaluate||C,function(a,b){return"';\n"+H(b)+"\n;__p+='"})+"';\n";c.variable||(d="with(obj||{}){\n"+d+"}\n"),d="var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n"+d+"return __p;\n";var e=new Function(c.variable||"obj","_",d);if(b)return e(b,w);var f=function(a){return e.call(this,a,w)};return f.source="function("+(c.variable||"obj")+"){\n"+d+"}",f},w.chain=function(a){return w(a).chain()};var I=function(a){this._wrapped=a};w.prototype=I.prototype;var J=function(a,b){return b?w(a).chain():a},K=function(a,b){I.prototype[a]=function(){var a=g.call(arguments);return h.call(a,this._wrapped),J(b.apply(w,a),this._chain)}};w.mixin(w),x(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];I.prototype[a]=function(){var c=this._wrapped;b.apply(c,arguments);var d=c.length;return(a=="shift"||a=="splice")&&d===0&&delete c[0],J(c,this._chain)}}),x(["concat","join","slice"],function(a){var b=d[a];I.prototype[a]=function(){return J(b.apply(this._wrapped,arguments),this._chain)}}),I.prototype.chain=function(){return this._chain=!0,this},I.prototype.value=function(){return this._wrapped}})).call(this); |
@@ -9,15 +9,37 @@ /** | ||
module.exports = function (req, res, next) { | ||
resources.get(function (err, resources) { | ||
if(err) return next(err); | ||
resources = resources || []; | ||
fs.readFile(__dirname + '/../clib/dpd.js', function (err, data) { | ||
function loadAndSendFile(fileName, callback) { | ||
fs.readFile(__dirname + fileName, function (err, data) { | ||
var src = data.toString(); | ||
res.header('Content-Type', 'text/javascript'); | ||
res.send( | ||
src.replace('/*resources*/', JSON.stringify(resources)) | ||
); | ||
if (callback) { src = callback(src); } | ||
var rootUrl = process.url.href; | ||
if (rootUrl.lastIndexOf('/') === rootUrl.length - 1) { rootUrl = rootUrl.slice(0, -1); } | ||
src = src.replace('/*rootUrl*/', '"' + rootUrl + '"'); | ||
res.send(src); | ||
}) | ||
}); | ||
} | ||
if (req.param('proxy')) { | ||
loadAndSendFile('/../clib/dpd-loader.js', function(src) { | ||
res.header('Content-Disposition', 'attachment; filename=dpd.js') | ||
return src; | ||
}); | ||
} else { | ||
resources.get(function (err, resources) { | ||
if(err) return next(err); | ||
resources = resources || []; | ||
loadAndSendFile('/../clib/dpd.js', function(src) { | ||
return src.replace('/*resources*/', JSON.stringify(resources)); | ||
}); | ||
}); | ||
} | ||
} |
@@ -40,3 +40,3 @@ /** | ||
collection.use(rename).rename(resource.path.replace('/', ''), function (err) { | ||
next(err); | ||
next(); | ||
}); | ||
@@ -43,0 +43,0 @@ } |
{ | ||
"author": "Ritchie Martori", | ||
"name": "deployd", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "url": "git://github.com/deployd/deployd.git" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4031996
89
6136