diff options
author | WuKong <rebirthmonkey@gmail.com> | 2017-04-22 13:25:07 +0200 |
---|---|---|
committer | WuKong <rebirthmonkey@gmail.com> | 2017-04-22 13:25:07 +0200 |
commit | d182202fc6001983541504ed323d68479086317e (patch) | |
tree | 11d4c10cdd3e995f519c3e0e324968fdaf175114 /moonv4/moon_gui/static/app/model/edit/metadata | |
parent | 83c1c966baf73329fab8ddcfad19ad7fe0c41c2a (diff) |
add moonv4
Change-Id: I247af788d0b0fb961fbc85416486b241eb1d807c
Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'moonv4/moon_gui/static/app/model/edit/metadata')
4 files changed, 1129 insertions, 0 deletions
diff --git a/moonv4/moon_gui/static/app/model/edit/metadata/metadata-edit.tpl.html b/moonv4/moon_gui/static/app/model/edit/metadata/metadata-edit.tpl.html new file mode 100644 index 00000000..fde6cdb0 --- /dev/null +++ b/moonv4/moon_gui/static/app/model/edit/metadata/metadata-edit.tpl.html @@ -0,0 +1,99 @@ +<div> + + <div class="col-md-4 col-sm-4 col-xs-4"> + <a class="btn btn-primary" type="button" style="white-space: normal;" ng-click="edit.fromList = !edit.fromList"> + <span ng-if="!edit.fromList" data-translate="moon.model.metadata.edit.action.list">Add from the list</span> + <span ng-if="edit.fromList" data-translate="moon.model.metadata.edit.action.new">Add a new Category</span> + </a> + </div> + + <div class="col-md-8 col-sm-8 col-xs-8"> + + <form name="selectMetaData" ng-if="edit.fromList" class="form-horizontal" role="form" > + + <div class="form-group" > + + <ui-select ng-model="edit.selectedMetaData" name="object"> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="ametaData in edit.list"> + <div ng-value="ametaData" ng-bind="ametaData.name"></div> + </ui-select-choices> + + </ui-select> + + </div> + + <div class="form-group"> + + <div class="pull-left col-md-4 col-sm-4 col-xs-4"> + + <a href="" ng-disabled="edit.loading || !edit.selectedMetaData" ng-click="edit.deleteMetaData()" class="btn btn-warning"> + <span class="glyphicon glyphicon-trash"></span> + <span data-translate="moon.model.metadata.edit.action.delete">Delete</span> + </a> + + </div> + + <div class="pull-right col-md-7 col-md-offset-1 col-sm-7 col-sm-offset-1 col-xs-7 col-xs-offset-1 "> + + <a href="" ng-disabled="edit.loading || !edit.selectedMetaData" ng-click="edit.addToMetaRule()" class="btn btn-warning" style="white-space: normal;"> + <span class="glyphicon glyphicon-link"></span> + <span data-translate="moon.model.metadata.edit.action.add">Add the selected Category</span> + </a> + + </div> + + </div> + + <moon-loader ng-if="edit.loading"></moon-loader> + + </form> + + <form ng-if="!edit.fromList" class="form-horizontal" role="form" name="edit.form"> + + <div class="form-group" ng-class="{'has-error': edit.form.name.$invalid && edit.form.name.$dirty}"> + + <label for="name" class="col-sm-3 control-label" data-translate="moon.model.metadata.edit.name">Name</label> + + <div class="col-sm-6"> + + <input name="name" id="name" class="form-control" type="text" data-ng-model="edit.metaData.name" required /> + + <div class="help-block" ng-show="edit.form.name.$dirty && edit.form.name.$invalid"> + <small class="error" ng-show="edit.form.name.$error.required" data-translate="moon.model.metadata.edit.check.name.required">Name is required</small> + </div> + + </div> + + </div> + + <div class="form-group"> + + <label for="description" class="col-sm-3 control-label"data-translate="moon.model.metadata.edit.description">Description</label> + <div class="col-sm-6"> + <textarea id="description" name="description" class="form-control" data-ng-model="edit.metaData.description"></textarea> + </div> + + </div> + + <div class="form-group"> + + <div class="pull-right"> + + <a href="" ng-disabled="edit.loading" ng-click="edit.create()" class="btn btn-warning"> + <span class="glyphicon glyphicon-save"></span> + <span data-translate="moon.model.metadata.edit.action.create">Create</span> + </a> + + <moon-loader ng-if="edit.loading"></moon-loader> + + </div> + + </div> + + </form> + + </div> + +</div>
\ No newline at end of file diff --git a/moonv4/moon_gui/static/app/model/edit/metadata/metadata-list.tpl.html b/moonv4/moon_gui/static/app/model/edit/metadata/metadata-list.tpl.html new file mode 100644 index 00000000..35b61f57 --- /dev/null +++ b/moonv4/moon_gui/static/app/model/edit/metadata/metadata-list.tpl.html @@ -0,0 +1,333 @@ +<div> + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.model.metadata.subject.title">List of associated Subject Categories</h4> + + </div> + + <div class="panel-body"> + + <div class="table-responsive"> + + <table class="table table-striped"> + + <thead> + <tr> + <th data-translate="moon.model.metadata.table.id">Id</th> + <th data-translate="moon.model.metadata.table.name">Name</th> + <th data-translate="moon.model.metadata.table.description">Description</th> + <th ng-if="list.editMode" data-translate="moon.model.metadata.table.action.title"></th> + </tr> + </thead> + + <moon-loader ng-if="list.loadingCatSub"></moon-loader> + + <tbody ng-if="!list.loadingCatSub && list.getSubjectCategories().length > 0"> + <tr ng-repeat="(key, value) in list.catSub"> + <td ng-bind="value.id"></td> + <td ng-bind="value.name"></td> + <td ng-bind="value.description"></td> + <td ng-if="list.editMode"> + + <a href="" ng-if="!value.loader" ng-click="list.unMapSub(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metadata.action.remove">Remove</span> + </a> + + <!--<div ng-if="!value.loader" class="dropdown"> + + <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> + <span data-translate="moon.model.metadata.table.action.title">Actions</span> + <span class="caret"></span> + </button> + + <ul class="dropdown-menu"> + + <li> + <a href="" ng-click="list.unMapSub(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metadata.action.remove">Remove</span> + </a> + </li> + + <li class="divider"></li> + + <li> + <a href="" ng-click="list.deleteSub(value)"> + <span class="glyphicon glyphicon-trash"></span> + <span class="control-label" data-translate="moon.model.metadata.table.action.delete">Delete</span> + </a> + </li> + + </ul> + + </div>--> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + + </tr> + </tbody> + + + <tbody ng-if="!list.loadingCatSub && list.catSub.length === 0"> + <tr> + <td data-translate="moon.model.metadata.subject.notFound">There is no Subjects</td> + <td></td> + <td></td> + <td ng-if="list.editMode"></td> + </tr> + </tbody> + + </table> + + </div> + + </div> + + </div> + + <div ng-if="list.editMode" class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.model.metadata.subject.add.title">Add a Subject Category</h4> + + </div> + + <div class="panel-body"> + + <moon-meta-data-edit meta-rule="list.metaRule" meta-data-type="list.typeOfSubject"></moon-meta-data-edit> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.model.metadata.object.title">List associated of Object Categories</h4> + + </div> + + <div class="panel-body"> + + <div class="table-responsive"> + + <table class="table table-striped"> + + <thead> + <tr> + <th data-translate="moon.model.metadata.table.id">Id</th> + <th data-translate="moon.model.metadata.table.name">Name</th> + <th data-translate="moon.model.metadata.table.description">Description</th> + <th ng-if="list.editMode" data-translate="moon.model.metadata.table.action.title"></th> + + </tr> + </thead> + + <moon-loader ng-if="list.loadingCatObj"></moon-loader> + + <tbody ng-if="!list.loadingCatObj && list.catObj.length > 0"> + <tr ng-repeat="(key, value) in list.catObj"> + <td ng-bind="value.id"></td> + <td ng-bind="value.name"></td> + <td ng-bind="value.description"></td> + <td ng-if="list.editMode"> + + <a href="" ng-if="!value.loader" ng-click="list.unMapObj(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metadata.action.remove">Remove</span> + </a> + + + <!--<div ng-if="!value.loader" class="dropdown"> + + <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> + <span data-translate="moon.model.metadata.table.action.title">Actions</span> + <span class="caret"></span> + </button> + + <ul class="dropdown-menu"> + + <li> + <a href="" ng-click="list.unMapObj(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metadata.action.remove">Remove</span> + </a> + </li> + + <li class="divider"></li> + + <li> + <a href="" ng-click="list.deleteObj(value)"> + <span class="glyphicon glyphicon-trash"></span> + <span class="control-label" data-translate="moon.model.metadata.table.action.delete">Delete</span> + </a> + </li> + + </ul> + + </div>--> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + </tr> + </tbody> + + <tbody ng-if="!list.loadingCatObj && list.catObj.length === 0"> + <tr> + <td data-translate="moon.model.metadata.object.notFound">There is no Objects</td> + <td></td> + <td></td> + <td ng-if="list.editMode"></td> + </tr> + </tbody> + + </table> + + </div> + + </div> + + </div> + + <div ng-if="list.editMode" class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.model.metadata.object.add.title">Add an Object Category</h4> + + </div> + + <div class="panel-body"> + + <moon-meta-data-edit meta-rule="list.metaRule" meta-data-type="list.typeOfObject"></moon-meta-data-edit> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.model.metadata.action.title">List associated of Action Categories</h4> + + </div> + + <div class="panel-body"> + + <div class="table-responsive"> + + <table class="table table-striped"> + + <thead> + <tr> + <th data-translate="moon.model.metadata.table.id">Id</th> + <th data-translate="moon.model.metadata.table.name">Name</th> + <th data-translate="moon.model.metadata.table.description">Description</th> + <th ng-if="list.editMode" data-translate="moon.model.metadata.table.action.title"></th> + </tr> + </thead> + + <moon-loader ng-if="list.loadingCatAct"></moon-loader> + + <tbody ng-if="!list.loadingCatAct && list.catAct.length > 0"> + <tr ng-repeat="(key, value) in list.catAct"> + <td ng-bind="value.id"></td> + <td ng-bind="value.name"></td> + <td ng-bind="value.description"></td> + <td ng-if="list.editMode"> + + <a href="" ng-if="!value.loader" ng-click="list.unMapAct(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metadata.action.remove">Remove</span> + </a> + + <!--<div ng-if="!value.loader" class="dropdown"> + + <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> + <span data-translate="moon.model.metadata.table.action.title">Actions</span> + <span class="caret"></span> + </button> + + <ul class="dropdown-menu"> + + <li> + <a href="" ng-click="list.unMapAct(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metadata.action.remove">Remove</span> + </a> + </li> + + <li class="divider"></li> + + <li> + <a href="" ng-click="list.deleteAct(value)"> + <span class="glyphicon glyphicon-trash"></span> + <span class="control-label" data-translate="moon.model.metadata.table.action.delete">Delete</span> + </a> + </li> + + </ul> + + </div>--> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + </tr> + </tbody> + + <tbody ng-if="!list.loadingCatAct && list.catAct.length === 0"> + <tr> + <td data-translate="moon.model.metadata.action.notFound">There is no Actions</td> + <td></td> + <td></td> + <td ng-if="list.editMode"></td> + </tr> + </tbody> + + </table> + + </div> + + </div> + + </div> + + <div ng-if="list.editMode" class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.model.metadata.action.add.title">Add an Action Category</h4> + + </div> + + <div class="panel-body">. + + <moon-meta-data-edit meta-rule="list.metaRule" meta-data-type="list.typeOfAction"></moon-meta-data-edit> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/moonv4/moon_gui/static/app/model/edit/metadata/metadata.edit.dir.js b/moonv4/moon_gui/static/app/model/edit/metadata/metadata.edit.dir.js new file mode 100644 index 00000000..2e927c44 --- /dev/null +++ b/moonv4/moon_gui/static/app/model/edit/metadata/metadata.edit.dir.js @@ -0,0 +1,330 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonMetaDataEdit', moonMetaDataEdit); + + moonMetaDataEdit.$inject = []; + + function moonMetaDataEdit() { + + return { + templateUrl : 'html/model/edit/metadata/metadata-edit.tpl.html', + bindToController : true, + controller : moonMetaDataEditController, + controllerAs : 'edit', + scope : { + //Type can be 'ACTION', 'OBJECT', 'SUBJECT' + metaDataType: '=', + metaRule : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonMetaDataEditController', moonMetaDataEditController); + + moonMetaDataEditController.$inject = ['$scope', 'metaDataService', 'META_DATA_CST', 'alertService', '$translate', 'formService', 'metaRuleService', 'utilService']; + + function moonMetaDataEditController($scope, metaDataService, META_DATA_CST, alertService, $translate, formService, metaRuleService, utilService) { + + var edit = this; + + edit.metaDataType = $scope.edit.metaDataType; + edit.metaRule = $scope.edit.metaRule; + + edit.fromList = true; + + edit.laoading = false; + + edit.form = {}; + + edit.metaData = { name: null, description: null}; + + edit.list = []; + + edit.create = createMetaData; + edit.addToMetaRule = addToMetaRule; + edit.deleteMetaData = deleteMetaData; + + activate(); + + /* + * + */ + + function activate(){ + + switch(edit.metaDataType){ + + case META_DATA_CST.TYPE.SUBJECT: + + metaDataService.subject.findAllWithCallback(callBackList); + break; + + case META_DATA_CST.TYPE.OBJECT: + + metaDataService.object.findAllWithCallback(callBackList); + break; + + case META_DATA_CST.TYPE.ACTION: + + metaDataService.action.findAllWithCallback(callBackList); + break; + + default : + + edit.list = []; + break; + + } + + function callBackList(list){ + + edit.list = list + + } + + } + + /** + * Add + */ + + function addToMetaRule(){ + + if(!edit.selectedMetaData){ + + return; + + } + + var metaRuleToSend = edit.metaRule; + + switch(edit.metaDataType){ + + case META_DATA_CST.TYPE.SUBJECT: + + metaRuleToSend.subject_categories.push(edit.selectedMetaData.id); + break; + + case META_DATA_CST.TYPE.OBJECT: + + metaRuleToSend.object_categories.push(edit.selectedMetaData.id); + break; + + case META_DATA_CST.TYPE.ACTION: + + metaRuleToSend.action_categories.push(edit.selectedMetaData.id); + break; + } + + metaRuleService.update(metaRuleToSend, updateMetaRuleSuccess, updateMetaRuleError); + + function updateMetaRuleSuccess(data){ + + $translate('moon.model.metarules.update.success', { metaRuleName: metaRuleToSend.name }).then( function(translatedValue) { + + alertService.alertSuccess(translatedValue); + + }); + + metaRuleToSend = utilService.transformOne(data, 'meta_rules'); + + $scope.$emit('event:updateMetaRuleFromMetaDataAddSuccess', metaRuleToSend); + + stopLoading(); + + } + + function updateMetaRuleError(reason){ + + $translate('moon.model.metarules.update.error', { metaRuleName: metaRuleToSend.name, reason: reason.message}).then( function(translatedValue) { + + alertService.alertError(translatedValue); + + }); + + stopLoading(); + + } + + } + + /** + * Create + */ + + function createMetaData() { + + if(formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + } else { + + startLoading(); + + var metaDataToSend = angular.copy(edit.metaData); + + switch(edit.metaDataType){ + + case META_DATA_CST.TYPE.SUBJECT: + + metaDataService.subject.add(metaDataToSend, createSuccess, createError); + break; + + case META_DATA_CST.TYPE.OBJECT: + + metaDataService.object.add(metaDataToSend, createSuccess, createError); + break; + + case META_DATA_CST.TYPE.ACTION: + + metaDataService.action.add(metaDataToSend, createSuccess, createError); + break; + } + + } + + function createSuccess(data) { + + var created = {}; + + switch(edit.metaDataType){ + + case META_DATA_CST.TYPE.SUBJECT: + + created = utilService.transformOne(data, 'subject_categories'); + break; + + case META_DATA_CST.TYPE.OBJECT: + + created = utilService.transformOne(data, 'object_categories'); + break; + + case META_DATA_CST.TYPE.ACTION: + + created = utilService.transformOne(data, 'action_categories'); + break; + } + + $translate('moon.model.metadata.edit.create.success', { name: created.name }).then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + stopLoading(); + + edit.list.push(created); + + displayList(); + + } + + function createError(reason) { + + $translate('moon.model.metadata.edit.create.error', { name: metaDataToSend.name }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + + } + + function deleteMetaData(){ + + if(!edit.selectedMetaData){ + + return; + + } + + startLoading(); + + var metaDataToDelete = angular.copy(edit.selectedMetaData); + + switch(edit.metaDataType){ + case META_DATA_CST.TYPE.SUBJECT: + + metaDataService.subject.delete(metaDataToDelete, deleteSuccess, deleteError); + break; + + case META_DATA_CST.TYPE.OBJECT: + + metaDataService.object.delete(metaDataToDelete, deleteSuccess, deleteError); + break; + + case META_DATA_CST.TYPE.ACTION: + + metaDataService.action.delete(metaDataToDelete, deleteSuccess, deleteError); + break; + } + + + function deleteSuccess(data) { + + $translate('moon.model.metadata.edit.delete.success', { name: metaDataToDelete.name }).then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + metaRuleService.findOneWithMetaData(edit.metaRule.id).then( function(metaRule){ + + edit.metaRule = metaRule; + + cleanSelectedValue(); + + activate(); + + stopLoading(); + + $scope.$emit('event:deleteMetaDataFromMetaDataAddSuccess', edit.metaRule); + + }); + + } + + function deleteError(reason) { + + $translate('moon.model.metadata.edit.delete.error', { name: metaDataToDelete.name }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + } + + function cleanSelectedValue(){ + + delete edit.selectedMetaData; + + } + + function startLoading(){ + + edit.loading = true; + + } + + function stopLoading(){ + + edit.loading = false; + + } + + function displayList(){ + + edit.fromList = true; + + } + + } + +})();
\ No newline at end of file diff --git a/moonv4/moon_gui/static/app/model/edit/metadata/metadata.list.dir.js b/moonv4/moon_gui/static/app/model/edit/metadata/metadata.list.dir.js new file mode 100644 index 00000000..c4654be1 --- /dev/null +++ b/moonv4/moon_gui/static/app/model/edit/metadata/metadata.list.dir.js @@ -0,0 +1,367 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonMetaDataList', moonMetaDataList); + + moonMetaDataList.$inject = []; + + function moonMetaDataList() { + + return { + templateUrl : 'html/model/edit/metadata/metadata-list.tpl.html', + bindToController : true, + controller : moonMetaDataListController, + controllerAs : 'list', + scope : { + metaRule: '=', + editMode : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonMetaDataListController', moonMetaDataListController); + + moonMetaDataListController.$inject = ['$scope', '$rootScope', 'metaDataService', '$translate', 'alertService', 'metaRuleService', 'META_DATA_CST', 'utilService']; + + function moonMetaDataListController($scope, $rootScope, metaDataService, $translate, alertService, metaRuleService, META_DATA_CST, utilService){ + + var list = this; + + list.metaRule = $scope.list.metaRule; + list.editMode = $scope.list.editMode; + + list.typeOfSubject = META_DATA_CST.TYPE.SUBJECT; + list.typeOfObject = META_DATA_CST.TYPE.OBJECT; + list.typeOfAction = META_DATA_CST.TYPE.ACTION; + + list.unMapSub = unMapSub; + list.unMapObj = unMapObj; + list.unMapAct = unMapAct; + + list.deleteSub = deleteSub; + list.deleteObj = deleteObj; + list.deleteAct = deleteAct; + + list.getSubjectCategories = getSubjectCategories; + list.getObjectCategories = getObjectCategories; + list.getActionCategories = getActionCategories; + + activate(); + + function activate(){ + + manageSubjectCategories(); + + manageObjectCategories(); + + manageActionCategories(); + + } + + var rootListeners = { + + 'event:updateMetaRuleFromMetaDataAddSuccess': $rootScope.$on('event:updateMetaRuleFromMetaDataAddSuccess', updateMetaRuleCategories), + + 'event:deleteMetaDataFromMetaDataAddSuccess': $rootScope.$on('event:deleteMetaDataFromMetaDataAddSuccess', deleteMetaRuleCategories) + + }; + + for (var unbind in rootListeners) { + $scope.$on('$destroy', rootListeners[unbind]); + } + + + function manageSubjectCategories(){ + + list.loadingCatSub = true; + + metaDataService.subject.findSomeWithCallback(list.metaRule.subject_categories, function(categories){ + + list.catSub = categories; + list.loadingCatSub = false; + + }); + } + + function manageObjectCategories(){ + + list.loadingCatObj = true; + + metaDataService.object.findSomeWithCallback(list.metaRule.object_categories, function(categories){ + + list.catObj = categories; + list.loadingCatObj = false; + + }); + + } + + function manageActionCategories(){ + + list.loadingCatAct = true; + + metaDataService.action.findSomeWithCallback(list.metaRule.action_categories, function(categories){ + + list.catAct = categories; + list.loadingCatAct = false; + + }); + + } + + + /** + * UnMap + */ + + function unMapSub(subject){ + + subject.loader = true; + + var metaRuleToSend = angular.copy(list.metaRule); + + metaRuleToSend.subject_categories = _.without(metaRuleToSend.subject_categories, subject.id); + + metaRuleService.update(metaRuleToSend, updateMetaRuleSuccess, updateMetaRuleError); + + function updateMetaRuleSuccess(data){ + + $translate('moon.model.metarules.update.success', { metaRuleName: list.metaRule.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + list.metaRule = metaRuleService.findMetaDataFromMetaRule(utilService.transformOne(data, 'meta_rules')); + + activate(); + + subject.loader = false; + + } + + function updateMetaRuleError(reason){ + + $translate('moon.model.metarules.update.error', { metaRuleName: list.metaRule.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + subject.loader = false; + + } + + } + + function unMapObj(object){ + + object.loader = true; + + var metaRuleToSend = angular.copy(list.metaRule); + + metaRuleToSend.object_categories = _.without(metaRuleToSend.object_categories, object.id); + + metaRuleService.update(metaRuleToSend, updateMetaRuleSuccess, updateMetaRuleError); + + function updateMetaRuleSuccess(data){ + + $translate('moon.model.metarules.update.success', { metaRuleName: list.metaRule.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + list.metaRule = metaRuleService.findMetaDataFromMetaRule(utilService.transformOne(data, 'meta_rules')); + + activate(); + + object.loader = false; + + } + + function updateMetaRuleError(reason){ + + $translate('moon.model.metarules.update.error', { metaRuleName: list.metaRule.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + object.loader = false; + + } + + } + + function unMapAct(action){ + + action.loader = true; + + var metaRuleToSend = angular.copy(list.metaRule); + + metaRuleToSend.action_categories = _.without(metaRuleToSend.action_categories, action.id); + + metaRuleService.update(metaRuleToSend, updateMetaRuleSuccess, updateMetaRuleError); + + function updateMetaRuleSuccess(data){ + + $translate('moon.model.metarules.update.success', { metaRuleName: list.metaRule.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + list.metaRule = metaRuleService.findMetaDataFromMetaRule(utilService.transformOne(data, 'meta_rules')); + + activate(); + + action.loader = false; + + } + + function updateMetaRuleError(reason){ + + $translate('moon.model.metarules.update.error', { metaRuleName: list.metaRule.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + action.loader = false; + + } + + } + + /** + * Delete + */ + + function deleteSub(subject){ + + subject.loader = true; + + metaDataService.subject.delete(subject, deleteSubSuccess, deleteSubError); + + function deleteSubSuccess(data){ + + $translate('moon.model.metadata.subject.delete.success', { subjectName: subject.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + removeSubFromSubList(subject); + + subject.loader = false; + + } + + function deleteSubError(reason){ + + $translate('moon.model.metadata.subject.delete.error', { subjectName: subject.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + subject.loader = false; + + } + } + + function deleteObj(object){ + + object.loader = true; + + metaDataService.object.delete(object, deleteObjSuccess, deleteObjError); + + function deleteObjSuccess(data){ + + $translate('moon.model.metadata.object.delete.success', { objectName: object.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + removeObjFromObjList(object); + list.catSub = metaDataService.subject.findSome(metaRule.subject_categories); + list.catObj = metaDataService.object.findSome(metaRule.object_categories); + list.catAct = metaDataService.action.findSome(metaRule.action_categories); + object.loader = false; + + } + + function deleteObjError(reason){ + + $translate('moon.model.metadata.object.delete.error', { objectName: object.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + object.loader = false; + } + } + + function deleteAct(action){ + + action.loader = true; + + metaDataService.action.delete(action, deleteActSuccess, deleteActError); + + function deleteActSuccess(data){ + + $translate('moon.model.metadata.action.delete.success', { actionName: action.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + removeActFromActList(action); + + action.loader = false; + + } + + function deleteActError(reason){ + + $translate('moon.model.metadata.action.delete.error', { actionName: action.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + action.loader = false; + + } + } + + function getSubjectCategories(){ + return list.catSub ? list.catSub : []; + } + + function getObjectCategories(){ + return list.catObj ? list.catObj : []; + } + + function getActionCategories(){ + return list.catAct ? list.catAct : []; + } + + function removeSubFromSubList(subject){ + list.catSub = _.without(list.catSub, subject); + } + + function removeObjFromObjList(object){ + list.catObj = _.without(list.catObj, object); + } + + function removeActFromActList(action){ + list.catAct = _.without(list.catAct, action); + } + + function updateMetaRuleCategories( event, metaRule){ + + list.metaRule = metaRule; + + activate(); + + } + + + function deleteMetaRuleCategories( event, metaRule){ + + list.metaRule = metaRule; + + activate(); + + } + + } + +})();
\ No newline at end of file |