Scott Baker | bb4961d | 2014-07-14 18:10:53 -0700 | [diff] [blame^] | 1 | SliceEditorApp = new Marionette.Application(); |
| 2 |
|
| 3 | SliceEditorApp.addRegions({
|
| 4 | sliceList: "#sliceEditorList",
|
| 5 | sliceDetail: "#sliceEditorDetail",
|
| 6 | }); |
| 7 | |
| 8 | SliceEditorApp.SliceListItemView = Marionette.ItemView.extend({ |
| 9 | template: "#sliceeditor-listitem-template",
|
| 10 | tagName: 'li',
|
| 11 | className: 'sliceeditor-listitem',
|
| 12 |
|
| 13 | events: {"click": "changeSlice"},
|
| 14 |
|
| 15 | changeSlice: function(e) {
|
| 16 | e.preventDefault();
|
| 17 | e.stopPropagation();
|
| 18 |
|
| 19 | if (SliceEditorApp.sliceDetail.currentView && SliceEditorApp.sliceDetail.currentView.dirty) {
|
| 20 | if (!confirm("discard current changes?")) {
|
| 21 | return;
|
| 22 | }
|
| 23 | }
|
| 24 |
|
| 25 | var sliceDetailView = new SliceEditorApp.SliceDetailView({
|
| 26 | model: this.model,
|
| 27 | });
|
| 28 | SliceEditorApp.sliceDetail.show(sliceDetailView);
|
| 29 | },
|
| 30 | });
|
| 31 | |
| 32 | SliceEditorApp.SliceListView = Marionette.CollectionView.extend({ |
| 33 | tagName: "ul",
|
| 34 | childView: SliceEditorApp.SliceListItemView,
|
| 35 |
|
| 36 | modelEvents: {"sync": "render"},
|
| 37 |
|
| 38 | initialize: function() {
|
| 39 | this.dirty = false;
|
| 40 | this.listenTo(this.collection, 'change', this._renderChildren);
|
| 41 | },
|
| 42 |
|
| 43 | attachHtml: function(compositeView, childView, index) {
|
| 44 | // The REST API will let admin users see everything. For the developer
|
| 45 | // view we still want to hide slices we are not members of.
|
| 46 | if (childView.model.get("sliceInfo").roles.length == 0) {
|
| 47 | return;
|
| 48 | }
|
| 49 | SliceEditorApp.SliceListView.__super__.attachHtml(compositeView, childView, index);
|
| 50 | },
|
| 51 | });
|
| 52 |
|
| 53 | SliceEditorApp.SliceDetailView = Marionette.ItemView.extend({
|
| 54 | template: "#sliceeditor-sliceedit-template",
|
| 55 | tagName: 'div',
|
| 56 |
|
| 57 | events: {"click button.js-submit": "submitClicked",
|
| 58 | "change input": "inputChanged"},
|
| 59 |
|
| 60 | inputChanged: function(e) {
|
| 61 | this.dirty = true;
|
| 62 | },
|
| 63 |
|
| 64 | submitClicked: function(e) {
|
| 65 | e.preventDefault();
|
| 66 | var data = Backbone.Syphon.serialize(this);
|
| 67 | this.model.save(data);
|
| 68 | this.dirty = false;
|
| 69 | },
|
| 70 | });
|
| 71 | |
| 72 | SliceEditorApp.on("start", function() { |
| 73 | var sliceListView = new SliceEditorApp.SliceListView({ |
| 74 | collection: xos.slicesPlus
|
| 75 | });
|
| 76 | SliceEditorApp.sliceList.show(sliceListView);
|
| 77 | xos.slicesPlus.startPolling();
|
| 78 | }); |
| 79 | |
| 80 | $(document).ready(function(){ |
| 81 | SliceEditorApp.start(); |
| 82 | }); |
| 83 | |