Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.29 KB | None | 0 0
  1. 'use strict';
  2.  
  3. /**
  4. * @ngdoc function
  5. * @name dmsApp.controller:CategoryVocabularylistCtrl
  6. * @description
  7. * # CategoryVocabularylistCtrl
  8. * Controller of the dmsApp
  9. */
  10. angular.module('dmsApp')
  11. .config(function ($routeProvider) {
  12. $routeProvider
  13. .when('/category/vocabularyAdd', {
  14. templateUrl: 'views/category/vocabularyEdit.html',
  15. controller: 'CategoryVocabularyAddCtrl',
  16. controllerAs: 'categoryVocabularyEdit'
  17. })
  18. .when('/category/vocabularyAdd/:id',{
  19. templateUrl:'views/category/vocabularyEdit.html',
  20. controller:'CategoryVocabularyAddCtrl',
  21. controllerAs: 'categoryVocabularyEdit'
  22. })
  23. .when('/category/vocabularyList', {
  24. templateUrl: 'views/category/vocabulary.html',
  25. controller: 'CategoryVocabularylistCtrl',
  26. controllerAs: 'categoryVocabularyList'
  27. })
  28. })
  29. .controller('CategoryVocabularylistCtrl', function ($scope,category_vocabularyService,stringValueService,$location,$mdDialog) {
  30. var controller=this;
  31.  
  32. $scope.row_select = [5, 10, 25];
  33.  
  34. $scope.query = {
  35. filter: '',
  36. order: 'name',
  37. limit: 5,
  38. page: 1
  39. };
  40.  
  41. $scope.init = function(){
  42. console.debug("Init");
  43. controller.listVocabulary();
  44. };
  45.  
  46. controller.listVocabulary=function() {
  47. category_vocabularyService.list().then(function(response) {
  48. $scope.vocabularies=response.data;
  49. console.debug(response.data);
  50. },function(response){
  51. console.debug(response.status);
  52. });
  53. };
  54.  
  55. controller.add = function() {
  56. console.log("add vocabolario ");
  57. $location.path("/category/vocabularyAdd/");
  58. };
  59.  
  60. controller.delete = function(vocabolario) {
  61. var confirm = $mdDialog.confirm()
  62. .title('Vuoi veramente eliminare il vocabolario ' + vocabolario.nameValues[vocabolario.defaultLocale].fieldValue+'?')
  63. .textContent('Una volta effettuata la cancellazione non potrà essere ripristinato')
  64. .ok('Ok!')
  65. .cancel('Cancel');
  66. $mdDialog.show(confirm).then(function() {
  67. category_vocabularyService.delete(vocabolario.id).success(function (data, status, headers, config) {
  68. stringValueService.deleteByObjectId(vocabolario.id).success(function (data, status, headers, config) {
  69. controller.listVocabulary();
  70. });
  71. });
  72. });
  73. };
  74.  
  75. controller.edit=function(id){
  76. console.log("edit vocabolario");
  77. $location.path("/category/vocabularyAdd/"+id);
  78. }
  79. }).controller('CategoryVocabularyAddCtrl', function ($scope,$mdDialog,stringValueService,category_vocabularyService,categoryService,$window,$routeParams) {
  80. this.awesomeThings = [
  81. 'HTML5 Boilerplate',
  82. 'AngularJS',
  83. 'Karma'
  84. ];
  85.  
  86. $scope.init=function(){
  87. $scope.vocabolarioSelected=$routeParams.id;
  88. if($scope.vocabolarioSelected>0){
  89. category_vocabularyService.get($scope.vocabolarioSelected).then(function (response) {
  90. $scope.vocabolario=response.data;
  91. },function(response){
  92. });
  93. categoryService.listByVocabulary($scope.vocabolarioSelected).then(function(response){
  94. $scope.categorie=response.data;
  95. },function(response){
  96. });
  97. }
  98. };
  99.  
  100. $scope.collapsed = false;
  101.  
  102. $scope.toggleCollapse = function() {
  103. $scope.collapsed = !$scope.collapsed;
  104. };
  105.  
  106. this.save = function(vocabolario){
  107. console.log("save vocabolario");
  108. category_vocabularyService.save(vocabolario).then(function(response){
  109. if(vocabolario.id>0) {
  110. var nome=vocabolario.nameValues[vocabolario.defaultLocale];
  111. stringValueService.getByObjectAndFieldUrl(vocabolario.id,nome.fieldUrl).then(function (response) {
  112. stringValueService.save(nome).then(function (response) {
  113. var descrizione=vocabolario.descriptionValues[vocabolario.defaultLocale];
  114. stringValueService.getByObjectAndFieldUrl(vocabolario.id, descrizione.fieldUrl).then(function (response) {
  115. stringValueService.save(descrizione).then(function (response) {
  116. console.log("save catStringValueDescrizione");
  117. $window.location.href = '/#/category/vocabularyList';
  118. });
  119. })
  120. })
  121. })
  122. }else{
  123. var stringValue={};
  124. stringValue.fieldValue=vocabolario.nameValues[vocabolario.defaultLocale].fieldValue;
  125. stringValue.locale=vocabolario.defaultLocale;
  126. stringValue.objectId=response.data.id;
  127. stringValue.fieldUrl="type://it.dstech.category.Vocabulary.name/";
  128. stringValueService.save(stringValue).then(function(response){
  129. stringValue.fieldValue=vocabolario.descriptionValues[vocabolario.defaultLocale].fieldValue;
  130. stringValue.fieldUrl="type://it.dstech.category.Vocabulary.description";
  131. stringValueService.save(stringValue).then(function(response){
  132. $window.location.href = '/#/category/vocabularyList';
  133. });
  134. });
  135. }
  136. })
  137. };
  138. $scope.vocabolario;
  139. $scope.addCategoria = function(categoria){
  140. $mdDialog.show({
  141. clickOutsideToClose: true,
  142. controller: 'DialogCategoriaEdit',
  143. controllerAs: 'editCategoria',
  144. focusOnOpen: false,
  145. locals:{
  146. categoria:categoria
  147. },
  148. templateUrl: 'views/category/categoriaEdit.html'
  149. }).then(function(response) {
  150. /*category_vocabularyService.get($routeParams.id).then(function (response) {
  151. $scope.vocabolario = response.data;
  152. console.log($scope.vocabolario)})*/
  153. categoryService.listByVocabulary($scope.vocabolarioSelected).then(function(response){
  154. $scope.categorie=response.data;})
  155. },function(response){
  156. category_vocabularyService.get($routeParams.id).then(function (response) {
  157.  
  158. $scope.vocabolario = response.data;
  159. console.log($scope.vocabolario)})
  160. });
  161. };
  162.  
  163. $scope.delete=function(categoria) {
  164. var confirm = $mdDialog.confirm()
  165. .title('Vuoi veramente eliminare la categoria ?')
  166. .textContent('Una volta effettuata la cancellazione non potrà essere ripristinata')
  167. .ok('Ok!')
  168. .cancel('Cancel');
  169. $mdDialog.show(confirm).then(function () {
  170. categoryService.delete(categoria).then(function (response) {
  171. stringValueService.deleteByObjectId(categoria.id).then(function (response) {
  172. categoryService.listByVocabulary($scope.vocabolarioSelected).then(function(response){
  173. $scope.categorie=response.data;
  174. },function(response){
  175. });
  176. })
  177. })
  178. });
  179. }
  180. }).controller('DialogCategoriaEdit',function($scope,$mdDialog,categoria,categoryService,stringValueService,$routeParams){
  181.  
  182. $scope.cancel = $mdDialog.cancel;
  183. $scope.categoria=categoria;
  184.  
  185. $scope.save = function(categoria){
  186. categoria.vocabolaryId=$routeParams.id;
  187. console.log("save categoria");
  188. categoryService.salva(categoria).then(function (response){
  189. if(categoria.id>0){
  190. var nome=categoria.nameValues[categoria.defaultLocale];
  191. stringValueService.getByObjectAndFieldUrl(categoria.id,nome.fieldUrl).then(function (response) {
  192. stringValueService.save(nome).then(function (response) {
  193. var descrizione=categoria.descriptionValues[categoria.defaultLocale];
  194. stringValueService.getByObjectAndFieldUrl(categoria.id, descrizione.fieldUrl).then(function (response) {
  195. stringValueService.save(descrizione).then(function (response) {
  196. $mdDialog.hide();
  197. });
  198. });
  199. });
  200. });
  201. }else{
  202. var stringValue={};
  203. stringValue.fieldValue=categoria.nameValues[categoria.defaultLocale].fieldValue;
  204. stringValue.locale=categoria.defaultLocale;
  205. stringValue.objectId=response.data.id;
  206. stringValue.fieldUrl="type://it.dstech.category.Category.name/";
  207. stringValueService.save(stringValue).then(function(response){
  208. stringValue.fieldValue=categoria.descriptionValues[categoria.defaultLocale].fieldValue;
  209. stringValue.fieldUrl="type://it.dstech.category.Category.description/";
  210. stringValueService.save(stringValue).then(function(response){
  211.  
  212. $mdDialog.hide();
  213. });
  214. });
  215. }
  216. });
  217. }
  218. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement