From 1100c66ce03a059ebe7ece9734e799b49b3a5a9e Mon Sep 17 00:00:00 2001 From: WuKong Date: Sat, 23 Dec 2017 21:49:35 +0100 Subject: moonv4 cleanup Change-Id: Icef927f3236d985ac13ff7376f6ce6314b2b39b0 Signed-off-by: WuKong --- .../static/app/model/edit/model.edit.basic.dir.js | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 moon_gui/static/app/model/edit/model.edit.basic.dir.js (limited to 'moon_gui/static/app/model/edit/model.edit.basic.dir.js') diff --git a/moon_gui/static/app/model/edit/model.edit.basic.dir.js b/moon_gui/static/app/model/edit/model.edit.basic.dir.js new file mode 100755 index 00000000..54bb7071 --- /dev/null +++ b/moon_gui/static/app/model/edit/model.edit.basic.dir.js @@ -0,0 +1,97 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonModelEditBasic', moonModelEditBasic); + + moonModelEditBasic.$inject = []; + + function moonModelEditBasic() { + + return { + templateUrl : 'html/model/edit/model-edit-basic.tpl.html', + bindToController : true, + controller : moonModelEditBasicController, + controllerAs : 'edit', + scope : { + model : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonModelEditBasicController', moonModelEditBasicController); + + moonModelEditBasicController.$inject = ['$scope', 'modelService', 'formService', 'alertService', '$translate', 'utilService']; + + function moonModelEditBasicController($scope, modelService, formService, alertService, $translate, utilService){ + + var edit = this; + + edit.editModel = editModel; + edit.init = init; + + edit.form = {}; + + activate(); + + function activate(){ + + edit.model = $scope.edit.model; + + edit.modelToEdit = angular.copy(edit.model); + + } + + function editModel(){ + + if(formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + }else{ + + edit.loading = true; + + modelService.update(edit.modelToEdit, updateSuccess, updateError); + + } + + function updateSuccess(data) { + + var updatedModel = utilService.transformOne(data, 'models'); + + $translate('moon.model.edit.basic.success', { modelName: updatedModel.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + edit.loading = false; + + $scope.$emit('event:modelUpdatedSuccess', updatedModel); + + } + + function updateError(reason) { + + $translate('moon.model.edit.basic.error', { modelName: edit.model.name }).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + edit.loading = false; + + } + } + + function init(){ + + edit.modelToEdit = angular.copy(edit.model); + + } + } + +})(); -- cgit 1.2.3-korg