var OAAS_CONTROLLER = (function (my, Backbone, OAAS_VIEW, OAAS_MODEL, _, $) { my.GeneralController = function () { this.variationRequestHandler = function (evt) { var self = this; var dialog = new OAAS_VIEW.VariationDialog({ model: evt.model }); var dialogController = {}; _.extend(dialogController, Backbone.Events); dialogController.listenTo(dialog, 'variations-generated', function (variations) { var parent = evt.model.get('parent'); for (var i = 0; i < variations.length; i++) { var title = evt.model.get('title'); var offset = title.indexOf('(') if (offset != -1) { title = title.substring(0, offset); } title += '('; for (var j = 0; j < variations[i].length; j++) { title += variations[i][j].Name + " = " + variations[i][j].Value + "; "; } title += ')'; var data = { AlgorithmParameters: variations[i] }; if (evt.model.attributes.data.ProblemParameters) { data.ProblemParameters = evt.model.attributes.data.ProblemParameters; } parent.addNode({ title: title, nodeId: evt.model.get('nodeId'), data: data }); } self.model.trigger('change'); }); dialog.render(); }, this.experimentFinishedHandler = function (experimentModel, availableExperiments, selectableGroup) { var loadingDialog = new OAAS_VIEW.LoadingDialog({ el: $('#loadingDialog') }); // start the loading dialog loadingDialog.setLoading(true); loadingDialog.text('Saving experiment ' + experimentModel.get('title') + '...'); loadingDialog.render(); // send experiment to server experimentModel.save({}, { success: function () { loadingDialog.setLoading(false); loadingDialog.text('Experiment successfully saved!'); loadingDialog.render(); if (availableExperiments) availableExperiments.fetch({ cache: false, success: function (itm) { selectableGroup.render(); } }); }, error: function (model, response, options) { loadingDialog.setLoading(false); loadingDialog.text('Failed to save Experiment - Please log off an and on and try again!'); loadingDialog.render(); } }); //loadingDialog.close(); } } my.ExperimentPageController = function () { this.refreshExperiments = function () { var availableExperiments = new OAAS_MODEL.ExperimentList(); availableExperiments.fetch({ cache: false, success: function (itm) { var group = new OAAS_VIEW.DraggableGroup({ collection: availableExperiments, el: $('#experiments') }); group.render(); } }); }, this.refreshScenarios = function () { var availableScenarios = new OAAS_MODEL.ScenarioList(); availableScenarios.fetch({ cache: false, success: function (itm) { var group = new OAAS_VIEW.DraggableGroup({ collection: availableScenarios, el: $('#algorithms') }); group.render(); } }); }, this.create = function () { var self = this; var generalController = new my.GeneralController(); // create all models + required view for the experiment page var model = new OAAS_MODEL.ExperimentNode({ title: 'Experiment', key: 0, isExperiment: true }, { parse: true }); generalController.model = model; var experimentModel = new OAAS_MODEL.Experiment({ experiment: model }); var view = new OAAS_VIEW.ExperimentTreeView({ model: model, el: $('#container') }); view.render(); this.refreshScenarios(); this.refreshExperiments(); var wizard = new OAAS_VIEW.StepWizardView({ el: $('#stepWizard') }); wizard.render(); var detailsView = new OAAS_VIEW.ExperimentDetailsTreeView({ model: model, el: $('#container2') }); var validationView = new OAAS_VIEW.ValidationHintsView({ model: { header: "Validation failed!", text: ""} }); var parameterDialog = new OAAS_VIEW.ParameterDialog({ model: model, el: $('#parameterDialog') }); var wizardController = {}; _.extend(wizardController, Backbone.Events); wizardController.listenTo(model, 'change', function () { // update the details view, when the model changes view.render(); detailsView.render(); }); wizardController.listenTo(wizard, 'experiment-finished', function () { generalController.experimentFinishedHandler(experimentModel, null, null); self.refreshExperiments(); }); wizardController.listenTo(view, 'structure-changed', function (node) { view.render(); detailsView.render(); }); wizardController.listenTo(view, 'node-added', function (node) { // get details about the node node.fetch({ success: function (itm) { model.trigger('change', {}); } }); }); wizardController.listenTo(detailsView, 'node-clicked', function (node) { // get details about the node var modelNode = OAAS_MODEL.ExperimentNode.lookup(node.data.key); if (!modelNode.get('isExperiment')) { parameterDialog.model = modelNode; parameterDialog.render(); } }); wizardController.listenTo(parameterDialog, 'parameters-finished', function (node) { parameterDialog.close(); }); wizardController.listenTo(view, 'variation-request', function (evt) { generalController.variationRequestHandler(evt); }); var experimentDetailsView = new OAAS_VIEW.ExperimentDetailsView({ el: $('#step3'), model: experimentModel }); } } /// ==================== EDIT PAGE ========================= /// ==================== EDIT PAGE ========================= /// ==================== EDIT PAGE ========================= my.ExperimentEditPageController = function () { this.refreshScenarios = function () { var availableScenarios = new OAAS_MODEL.ScenarioList(); availableScenarios.fetch({ cache: false, success: function (itm) { var group = new OAAS_VIEW.DraggableGroup({ collection: availableScenarios, el: $('#draggableAlgorithms') }); group.render(); } }); }, this.create = function () { var generalController = new my.GeneralController(); var self = this; // create all models + required view for the experiment page var controllerModel = new OAAS_MODEL.ControllerModel(); var model = new OAAS_MODEL.ExperimentNode({ title: 'Experiment', key: 0, isExperiment: true }, { parse: true }); generalController.model = model; var experimentModel = new OAAS_MODEL.Experiment({ experiment: model }); var experimentDetailsView = new OAAS_VIEW.ExperimentDetailsView({ el: $('#step4'), model: experimentModel }); experimentDetailsView.render(); var availableExperiments = new OAAS_MODEL.ExperimentList(); var wizardController = {}; _.extend(wizardController, Backbone.Events); this.refreshScenarios(); var selectableGroup = new OAAS_VIEW.SelectableGroup({ collection: availableExperiments, el: $('#experiments') }); //selectableGroup.render(); var draggableExperiments = new OAAS_VIEW.DraggableGroup({ collection: availableExperiments, el: $('#draggableExperiments') }); availableExperiments.fetch({ cache: false, success: function (itm) { // selectableGroup = new OAAS_VIEW.SelectableGroup({ collection: availableExperiments, el: $('#experiments') }); selectableGroup.render(); draggableExperiments.render(); wizardController.listenTo(selectableGroup, 'node-selected', function (nodeId) { var node = availableExperiments.find(function (itm) { return itm.get('nodeId') == nodeId; }); var newNode = new OAAS_MODEL.ExperimentNode(node.attributes); newNode.fetch({ success: function () { experimentModel.set({ experiment: newNode, title: node.get('title'), nodeId: node.get('nodeId'), run: node.get('run'), repititions: node.get('repititions'), group: node.get('group') }); controllerModel.set({ selectedNode: newNode }); $('#deleteExperimentButton').removeAttr('disabled'); detailsView.model = newNode; detailsView.render(); view.model = newNode; view.render(); experimentDetailsView.render(); } }); } ); } }); // create wizard with 4 steps var wizard = new OAAS_VIEW.StepWizardView({ el: $('#stepWizard') }); wizard.render(); var view = new OAAS_VIEW.ExperimentTreeView({ model: model, el: $('#container') }); view.render(); var validationView = new OAAS_VIEW.ValidationHintsView({ model: { header: "Validation failed!", text: ""} }); var detailsView = new OAAS_VIEW.ExperimentDetailsTreeView({ model: model, el: $('#container2') }); var parameterDialog = new OAAS_VIEW.ParameterDialog({ model: model, el: $('#parameterDialog') }); var loadingDialog = new OAAS_VIEW.LoadingDialog({ el: $('#loadingDialog') }); wizardController.listenTo(wizard, 'step-validated', function (validationModel) { // update the details view if (validationModel.stepNumber == 1) { if (controllerModel.get('selectedNode') == null) { validationView.model["text"] = 'Please select an experiment to continue!'; validationView.render(); validationModel.succeeded = false; } } detailsView.render(); }); wizardController.listenTo(model, 'change', function () { // update the details view, when the model changes view.render(); detailsView.render(); }); wizardController.listenTo(view, 'structure-changed', function (node) { view.render(); }); wizardController.listenTo(view, 'node-added', function (node) { // get details about the node //if (!node.get('isExperiment')) node.fetch({ success: function (itm) { model.trigger('change', {}); } }); }); wizardController.listenTo(wizard, 'experiment-finished', function () { generalController.experimentFinishedHandler(experimentModel, availableExperiments, selectableGroup); }); wizardController.listenTo(detailsView, 'node-clicked', function (node) { // get details about the node var modelNode = OAAS_MODEL.ExperimentNode.lookup(node.data.key); if (!modelNode.get('isExperiment')) { parameterDialog.model = modelNode; parameterDialog.render(); } }); wizardController.listenTo(view, 'variation-request', function (evt) { generalController.variationRequestHandler(evt); }); wizardController.listenTo(parameterDialog, 'parameters-finished', function (node) { parameterDialog.close(); }); $('#deleteExperimentButton').click(function (evt) { var node = controllerModel.get('selectedNode'); var nodes = availableExperiments.where({ nodeId: node.get('nodeId') }); if (nodes.length == 1) { nodes[0].destroy(); $('#deleteExperimentButton').attr('disabled', 'disabled'); controllerModel.set('selectedNode', null); } }); } } return my; } (OAAS_CONTROLLER || {}, Backbone, OAAS_VIEW, OAAS_MODEL, _, $));