2013-09-03 22:25:54 -04:00
|
|
|
(function(define) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
define(function(require, exports) {
|
2013-09-03 22:01:31 -04:00
|
|
|
|
|
|
|
var _ = require('underscore');
|
|
|
|
|
|
|
|
var Helpers = exports.Helpers = {
|
|
|
|
|
2013-09-03 23:02:23 -04:00
|
|
|
// ...self explanatory
|
2013-09-03 22:01:31 -04:00
|
|
|
capitalize: function(word) {
|
|
|
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sorts an object based on the names.
|
|
|
|
sortObject: function(obj) {
|
|
|
|
return _.sortBy(_.pairs(obj), function(a) {
|
|
|
|
return a[0];
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sets up a multi-query to be executed with serial promises.
|
|
|
|
multiQuery: function(builder, i, chain) {
|
|
|
|
if (chain) {
|
|
|
|
return function() {
|
|
|
|
return Helpers.multiQuery(builder, i);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return builder.client.query(_.extend({}, builder, {sql: builder.sql[i]}));
|
2013-09-03 23:02:23 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// The standard Backbone.js `extend` method.
|
|
|
|
extend: function(protoProps, staticProps) {
|
|
|
|
var parent = this;
|
|
|
|
var child;
|
|
|
|
|
|
|
|
// The constructor function for the new subclass is either defined by you
|
|
|
|
// (the "constructor" property in your `extend` definition), or defaulted
|
|
|
|
// by us to simply call the parent's constructor.
|
|
|
|
if (protoProps && _.has(protoProps, 'constructor')) {
|
|
|
|
child = protoProps.constructor;
|
|
|
|
} else {
|
|
|
|
child = function(){ return parent.apply(this, arguments); };
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add static properties to the constructor function, if supplied.
|
|
|
|
_.extend(child, parent, staticProps);
|
|
|
|
|
|
|
|
// Set the prototype chain to inherit from `parent`, without calling
|
|
|
|
// `parent`'s constructor function.
|
|
|
|
var Surrogate = function(){ this.constructor = child; };
|
|
|
|
Surrogate.prototype = parent.prototype;
|
|
|
|
child.prototype = new Surrogate;
|
|
|
|
|
|
|
|
// Add prototype properties (instance properties) to the subclass,
|
|
|
|
// if supplied.
|
|
|
|
if (protoProps) _.extend(child.prototype, protoProps);
|
|
|
|
|
|
|
|
// Set a convenience property in case the parent's prototype is needed
|
|
|
|
// later.
|
|
|
|
child.__super__ = parent.prototype;
|
|
|
|
|
|
|
|
return child;
|
2013-09-03 22:01:31 -04:00
|
|
|
}
|
2013-09-03 23:02:23 -04:00
|
|
|
|
2013-09-03 22:25:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})(
|
|
|
|
typeof define === 'function' && define.amd ? define : function (factory) { factory(require, exports); }
|
|
|
|
);
|