var PrerequisiteView = BaseViews.BaseListView.extend({ template: require("./hbtemplates/selected_dialog.handlebars"), onselect:null, lists: [], name: NAMESPACE, $trs: MESSAGES, initialize: function(options) { _.bindAll(this, 'render_selected_view'); this.modal = options.modal; this.collection = State.nodeCollection; this.onselect = options.onselect; this.allow_edit = options.allow_edit; this.rootID = options.rootID; this.views_to_update = options.views_to_update; this.render(); }, render: function() { var self = this; this.$el.html(this.template({node: this.model.toJSON()}, { data: this.get_intl_data() })); PrereqTree.set(this.model).then(this.render_selected_view); }, render_selected_view: function(){ this.selectedView = new SelectedView({ model: this.model, container: this, collection: this.collection, allow_edit: this.allow_edit }); this.$("#selected_view_wrapper").html(this.selectedView.el); }, update_prerequisites: function(skip_rendering){ var self = this; PrereqTree.fetch_prerequisites().then(function(){ var immediate_prereqs = PrereqTree.get_immediate_prerequisites(); self.onselect(immediate_prereqs, self.views_to_update); if(skip_rendering){ if(self.selectedView){ self.selectedView.toggle_warning(); } } else{ if(self.selectedView){ self.selectedView.remove(); delete self.selectedView; } self.render_selected_view(); } self.open_selected(); }); }, open_related: function(){ this.$("#selected_view_wrapper").css('display', 'none'); this.relatedView = new RelatedView({ model: this.model, container: this, rootID: this.rootID }); this.$("#related_view_wrapper").html(this.relatedView.el); }, open_selected: function(){ this.$("#selected_view_wrapper").css('display', 'block'); if(this.relatedView){ this.relatedView.remove(); delete this.relatedView } } });
var SyncView = BaseViews.BaseListView.extend({ template: require("./hbtemplates/sync_dialog.handlebars"), onsync:null, lists: [], name: NAMESPACE, $trs: MESSAGES, initialize: function(options) { _.bindAll(this, 'sync_content'); this.modal = options.modal; this.onsync = options.onsync; this.collection = new Models.ContentNodeCollection(); this.changed_collection = new Models.ContentNodeCollection(); this.selected_collection = new Models.ContentNodeCollection(); this.render(); }, events: { "click #sync_content_button" : "sync_content" }, close_sync:function(){ (this.modal)? this.modal.close() : this.remove(); }, /*********** LOADING METHODS ***********/ render: function() { var self = this; this.$el.html(this.template(null, { data: this.get_intl_data() })); State.current_channel.get_node_diff().then(function(difference){ self.collection = difference.original; self.changed_collection = difference.changed; self.synclist = new SyncList({ el: self.$("#changed_list_area"), collection: self.collection, changed: self.changed_collection, container: self }); self.preview = new SyncPreviewView({ el: self.$("#sync_preview_section"), model: null, changed: null }); }); }, /*********** SYNCING METHODS ***********/ sync_content:function(){ var self = this; this.display_load(this.get_translation("syncing_content"), function(resolve, reject){ var selected_models = _.chain(self.synclist.views).where({checked:true}).pluck('model').value(); self.collection.sync_nodes(selected_models).then(function(synced){ self.onsync(synced); self.close_sync(); resolve(true) }).catch(reject); }); }, handle_selection: function(){ this.selected_collection.reset(_.chain(this.synclist.views).where({checked : true}).pluck('model').value()); if(this.selected_collection.length){ this.$("#sync_content_button").prop("disabled", false); this.$("#sync_content_button").removeClass("disabled"); this.$("#sync_status").text(this.get_translation("syncing_items", this.selected_collection.length)); } else { this.$("#sync_content_button").prop("disabled", true); this.$("#sync_content_button").addClass("disabled"); this.$("#sync_status").text(""); } }, set_selected(model, changed){ this.preview.set_selected(model, changed); } });