Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- /**
- * @ngdoc function
- * @name dmsApp.controller:CategoryVocabularylistCtrl
- * @description
- * # CategoryVocabularylistCtrl
- * Controller of the dmsApp
- */
- angular.module('dmsApp')
- .config(function ($routeProvider) {
- $routeProvider
- .when('/category/vocabularyAdd', {
- templateUrl: 'views/category/vocabularyEdit.html',
- controller: 'CategoryVocabularyAddCtrl',
- controllerAs: 'categoryVocabularyEdit'
- })
- .when('/category/vocabularyAdd/:id',{
- templateUrl:'views/category/vocabularyEdit.html',
- controller:'CategoryVocabularyAddCtrl',
- controllerAs: 'categoryVocabularyEdit'
- })
- .when('/category/vocabularyList', {
- templateUrl: 'views/category/vocabulary.html',
- controller: 'CategoryVocabularylistCtrl',
- controllerAs: 'categoryVocabularyList'
- })
- })
- .controller('CategoryVocabularylistCtrl', function ($scope,category_vocabularyService,stringValueService,$location,$mdDialog) {
- var controller=this;
- $scope.row_select = [5, 10, 25];
- $scope.query = {
- filter: '',
- order: 'name',
- limit: 5,
- page: 1
- };
- $scope.init = function(){
- console.debug("Init");
- controller.listVocabulary();
- };
- controller.listVocabulary=function() {
- category_vocabularyService.list().then(function(response) {
- $scope.vocabularies=response.data;
- console.debug(response.data);
- },function(response){
- console.debug(response.status);
- });
- };
- controller.add = function() {
- console.log("add vocabolario ");
- $location.path("/category/vocabularyAdd/");
- };
- controller.delete = function(vocabolario) {
- var confirm = $mdDialog.confirm()
- .title('Vuoi veramente eliminare il vocabolario ' + vocabolario.nameValues[vocabolario.defaultLocale].fieldValue+'?')
- .textContent('Una volta effettuata la cancellazione non potrà essere ripristinato')
- .ok('Ok!')
- .cancel('Cancel');
- $mdDialog.show(confirm).then(function() {
- category_vocabularyService.delete(vocabolario.id).success(function (data, status, headers, config) {
- stringValueService.deleteByObjectId(vocabolario.id).success(function (data, status, headers, config) {
- controller.listVocabulary();
- });
- });
- });
- };
- controller.edit=function(id){
- console.log("edit vocabolario");
- $location.path("/category/vocabularyAdd/"+id);
- }
- }).controller('CategoryVocabularyAddCtrl', function ($scope,$mdDialog,stringValueService,category_vocabularyService,categoryService,$window,$routeParams) {
- this.awesomeThings = [
- 'HTML5 Boilerplate',
- 'AngularJS',
- 'Karma'
- ];
- $scope.init=function(){
- $scope.vocabolarioSelected=$routeParams.id;
- if($scope.vocabolarioSelected>0){
- category_vocabularyService.get($scope.vocabolarioSelected).then(function (response) {
- $scope.vocabolario=response.data;
- },function(response){
- });
- categoryService.listByVocabulary($scope.vocabolarioSelected).then(function(response){
- $scope.categorie=response.data;
- },function(response){
- });
- }
- };
- $scope.collapsed = false;
- $scope.toggleCollapse = function() {
- $scope.collapsed = !$scope.collapsed;
- };
- this.save = function(vocabolario){
- console.log("save vocabolario");
- category_vocabularyService.save(vocabolario).then(function(response){
- if(vocabolario.id>0) {
- var nome=vocabolario.nameValues[vocabolario.defaultLocale];
- stringValueService.getByObjectAndFieldUrl(vocabolario.id,nome.fieldUrl).then(function (response) {
- stringValueService.save(nome).then(function (response) {
- var descrizione=vocabolario.descriptionValues[vocabolario.defaultLocale];
- stringValueService.getByObjectAndFieldUrl(vocabolario.id, descrizione.fieldUrl).then(function (response) {
- stringValueService.save(descrizione).then(function (response) {
- console.log("save catStringValueDescrizione");
- $window.location.href = '/#/category/vocabularyList';
- });
- })
- })
- })
- }else{
- var stringValue={};
- stringValue.fieldValue=vocabolario.nameValues[vocabolario.defaultLocale].fieldValue;
- stringValue.locale=vocabolario.defaultLocale;
- stringValue.objectId=response.data.id;
- stringValue.fieldUrl="type://it.dstech.category.Vocabulary.name/";
- stringValueService.save(stringValue).then(function(response){
- stringValue.fieldValue=vocabolario.descriptionValues[vocabolario.defaultLocale].fieldValue;
- stringValue.fieldUrl="type://it.dstech.category.Vocabulary.description";
- stringValueService.save(stringValue).then(function(response){
- $window.location.href = '/#/category/vocabularyList';
- });
- });
- }
- })
- };
- $scope.vocabolario;
- $scope.addCategoria = function(categoria){
- $mdDialog.show({
- clickOutsideToClose: true,
- controller: 'DialogCategoriaEdit',
- controllerAs: 'editCategoria',
- focusOnOpen: false,
- locals:{
- categoria:categoria
- },
- templateUrl: 'views/category/categoriaEdit.html'
- }).then(function(response) {
- /*category_vocabularyService.get($routeParams.id).then(function (response) {
- $scope.vocabolario = response.data;
- console.log($scope.vocabolario)})*/
- categoryService.listByVocabulary($scope.vocabolarioSelected).then(function(response){
- $scope.categorie=response.data;})
- },function(response){
- category_vocabularyService.get($routeParams.id).then(function (response) {
- $scope.vocabolario = response.data;
- console.log($scope.vocabolario)})
- });
- };
- $scope.delete=function(categoria) {
- var confirm = $mdDialog.confirm()
- .title('Vuoi veramente eliminare la categoria ?')
- .textContent('Una volta effettuata la cancellazione non potrà essere ripristinata')
- .ok('Ok!')
- .cancel('Cancel');
- $mdDialog.show(confirm).then(function () {
- categoryService.delete(categoria).then(function (response) {
- stringValueService.deleteByObjectId(categoria.id).then(function (response) {
- categoryService.listByVocabulary($scope.vocabolarioSelected).then(function(response){
- $scope.categorie=response.data;
- },function(response){
- });
- })
- })
- });
- }
- }).controller('DialogCategoriaEdit',function($scope,$mdDialog,categoria,categoryService,stringValueService,$routeParams){
- $scope.cancel = $mdDialog.cancel;
- $scope.categoria=categoria;
- $scope.save = function(categoria){
- categoria.vocabolaryId=$routeParams.id;
- console.log("save categoria");
- categoryService.salva(categoria).then(function (response){
- if(categoria.id>0){
- var nome=categoria.nameValues[categoria.defaultLocale];
- stringValueService.getByObjectAndFieldUrl(categoria.id,nome.fieldUrl).then(function (response) {
- stringValueService.save(nome).then(function (response) {
- var descrizione=categoria.descriptionValues[categoria.defaultLocale];
- stringValueService.getByObjectAndFieldUrl(categoria.id, descrizione.fieldUrl).then(function (response) {
- stringValueService.save(descrizione).then(function (response) {
- $mdDialog.hide();
- });
- });
- });
- });
- }else{
- var stringValue={};
- stringValue.fieldValue=categoria.nameValues[categoria.defaultLocale].fieldValue;
- stringValue.locale=categoria.defaultLocale;
- stringValue.objectId=response.data.id;
- stringValue.fieldUrl="type://it.dstech.category.Category.name/";
- stringValueService.save(stringValue).then(function(response){
- stringValue.fieldValue=categoria.descriptionValues[categoria.defaultLocale].fieldValue;
- stringValue.fieldUrl="type://it.dstech.category.Category.description/";
- stringValueService.save(stringValue).then(function(response){
- $mdDialog.hide();
- });
- });
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement