-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemController.js
More file actions
23 lines (21 loc) · 858 Bytes
/
ItemController.js
File metadata and controls
23 lines (21 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(function (win, doc, $, _, Backbone, root) {
var ItemController = Backbone.Model.extend({
create: function (type, attributes) {
var instance = this.createContentOnly(type, attributes), itemList, itemAttrs, item;
if (instance) {
itemList = root.document.getCurrentPage().get("itemList");
itemAttrs = _.pick(attributes, "width", "height", "x", "y");
item = new root.Item(_.extend(itemAttrs, {content: instance}));
itemList.add(item);
}
},
createContentOnly: function (type, attributes) {
var registry = root.ContenttypeRegistry, Constructor;
if (registry.isContenttypeAvailable(type)) {
Constructor = registry.getContentPrototype(type);
return new Constructor(_.omit(attributes, "x", "y"));
}
}
});
root.supply({"ItemController": new ItemController});
})(window, document, jQuery, _, Backbone, window.ds);