Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. 'use strict';
  2. /* App Module */
  3. function addCrudStates($stateProvider, itemType, listState, addState, editState) {
  4. if (listState == null || listState === true) {
  5. $stateProvider.state(itemType, {
  6. url: '/' + itemType,
  7. parent: 'root',
  8. title: itemType + '.name',
  9. templateUrl: 'views/' + itemType + '.html',
  10. controller: itemType + 'Controller'
  11. });
  12. }
  13. if (addState == null || addState === true) {
  14. $stateProvider.state(itemType + '_add', {
  15. url: '/' + itemType + '/add',
  16. parent: 'root',
  17. title: itemType + '.add.defaultTitle',
  18. toolbarTitle: itemType + '.add.defaultToolbarTitle',
  19. templateUrl: 'views/' + itemType + 'edit.html',
  20. controller: itemType + 'EditController',
  21. params: {
  22. item: null
  23. }
  24. });
  25. }
  26. if (editState == null || editState === true) {
  27. $stateProvider.state(itemType + '_edit', {
  28. url: '/' + itemType + '/edit/:id',
  29. parent: 'root',
  30. title: itemType + '.edit.defaultTitle',
  31. toolbarTitle: itemType + '.edit.defaultToolbarTitle',
  32. templateUrl: 'views/' + itemType + 'edit.html',
  33. controller: itemType + 'EditController',
  34. params: {
  35. item: null
  36. }
  37. });
  38. }
  39. }
  40. function addCrudNotifications(luNotificationsBusiness, AppUtilsBusiness, $mdToast, $state, itemType) {
  41. luNotificationsBusiness.addEventCrudCallback(itemType, function(eventName, entityType, oldEntity, newEntity)
  42. {
  43. var text = null;
  44. if (eventName == luNotificationsBusiness.EVENT_CREATE) {
  45. text = AppUtilsBusiness.tr(itemType + '.notifications.create', {text: newEntity.toString()});
  46. }
  47. else if (eventName == luNotificationsBusiness.EVENT_UPDATE) {
  48. text = AppUtilsBusiness.tr(itemType + '.notifications.update', {text: newEntity.toString()});
  49. }
  50. else if (eventName == luNotificationsBusiness.EVENT_DELETE) {
  51. text = AppUtilsBusiness.tr(itemType + '.notifications.delete', {text: oldEntity.toString()});
  52. }
  53. var toast = $mdToast.simple()
  54. .textContent(text)
  55. .action(eventName == luNotificationsBusiness.EVENT_DELETE ? AppUtilsBusiness.tr('common.undo') : AppUtilsBusiness.tr('common.view'))
  56. .highlightAction(true)
  57. .highlightClass('md-accent')
  58. .position('bottom right');
  59. $mdToast.show(toast).then(function(response) {
  60. if (response == 'ok') {
  61. if (eventName == luNotificationsBusiness.EVENT_DELETE) {
  62. oldEntity.id = null;
  63. $state.go(itemType + '_add', {item: oldEntity});
  64. }
  65. else {
  66. $state.go(itemType + '_edit', {id: newEntity.id, item: newEntity});
  67. }
  68. }
  69. }, function (error) {console.log(error)});
  70. });
  71. }
  72. angular.module('app', [
  73. 'ui.bootstrap',
  74. 'ui.router',
  75. 'LocalStorageModule',
  76. 'ngMaterial',
  77. 'md.data.table',
  78. 'sasrio.angular-material-sidenav',
  79. 'pascalprecht.translate',
  80. 'angular-busy',
  81. 'luticate2Utils',
  82. 'SignalR',
  83. // 'luticateAuth',
  84. 'appSdk'
  85. ])
  86. .config(['$stateProvider', '$urlRouterProvider', 'ssSideNavSectionsProvider', '$mdThemingProvider',
  87. '$mdIconProvider', '$translateProvider', '$provide',
  88. function($stateProvider, $urlRouterProvider, ssSideNavSectionsProvider, $mdThemingProvider,
  89. $mdIconProvider, $translateProvider, $provide) {
  90. // $mdThemingProvider
  91. // .theme('default')
  92. // .primaryPalette('blue', {
  93. // 'default': '700'
  94. // });
  95. // $mdThemingProvider.theme('default')
  96. // .primaryPalette('blue')
  97. // .accentPalette('pink');
  98. $provide.decorator("$mdDialog", ['$delegate', function ($delegate) {
  99. // Get a handle of the show method
  100. var c = $delegate.show;
  101. function decorateDialogShow () {
  102. var args = angular.extend({}, arguments[0], {
  103. skipHide: true
  104. });
  105. if (args._options != null) {
  106. args._options = angular.extend({}, args._options, {
  107. skipHide: true
  108. });
  109. }
  110. return c(args);
  111. }
  112. $delegate.show = decorateDialogShow;
  113. return $delegate;
  114. }]);
  115. $translateProvider.useSanitizeValueStrategy('escapeParameters');
  116. $translateProvider.useMessageFormatInterpolation();
  117. $translateProvider.useStaticFilesLoader({
  118. prefix: 'translations/',
  119. suffix: '.json'
  120. });
  121. $translateProvider.preferredLanguage('en');
  122. $mdIconProvider
  123. .icon('md-toggle-arrow', 'img/arrow.svg');
  124. ssSideNavSectionsProvider.initWithTheme($mdThemingProvider);
  125. ssSideNavSectionsProvider.initWithSections([{
  126. id: 'toogle_1',
  127. name: 'home.name',
  128. type: 'heading',
  129. children: [{
  130. id: 'link_1',
  131. name: 'home.name',
  132. state: 'home.2',
  133. type: 'link'
  134. }, {
  135. id: 'link_1',
  136. name: 'home.name',
  137. state: 'home.2',
  138. type: 'link'
  139. }]
  140. },
  141. {
  142. id: 'toogle_2',
  143. name: 'articles.name',
  144. type: 'heading',
  145. children: [{
  146. id: 'toogle_2_link_1',
  147. name: 'common.all',
  148. state: 'articles',
  149. type: 'link'
  150. },{
  151. id: 'toogle_2_link_1',
  152. name: 'common.new',
  153. state: 'articles_add',
  154. type: 'link'
  155. }]
  156. }]);
  157. $stateProvider.state('root', {
  158. abstract: true,
  159. template: '<div ui-view=""></div>',
  160. // resolve: ['luticateAuthUsers', function(luticateAuthUsers)
  161. // {
  162. // return luticateAuthUsers.loadUserData(null);
  163. // }]
  164. });
  165. $stateProvider.state('home', {
  166. url:'/',
  167. parent: 'root',
  168. title: "home.name",
  169. reloadOnSearch: false,
  170. templateUrl:'views/home.html',
  171. controller:'HomeController'
  172. });
  173. addCrudStates($stateProvider, 'articles');
  174. $urlRouterProvider.otherwise('/');
  175. }])
  176. .run(['$rootScope', '$transitions', 'AppUtilsBusiness', 'ssSideNav', '$translate', 'luRequest', '$mdDialog',
  177. 'luNotificationsBusiness', '$mdToast', '$state', 'articlesBusiness',
  178. function ($rootScope, $transitions, AppUtilsBusiness, ssSideNav, $translate, luRequest, $mdDialog,
  179. luNotificationsBusiness, $mdToast, $state, articlesBusiness) {
  180. AppUtilsBusiness.addApiVersionChangedCallback(function(oldVersion, newVersion) {
  181. $mdDialog.show(
  182. $mdDialog.alert()
  183. .title(AppUtilsBusiness.tr('common.updateDetected.title'))
  184. .textContent(AppUtilsBusiness.tr('common.updateDetected.text',
  185. {oldVersion: oldVersion, newVersion: newVersion}))
  186. .ok(AppUtilsBusiness.tr('common.ok')));
  187. });
  188. luNotificationsBusiness.init({
  189. 'articles': articlesBusiness
  190. });
  191. addCrudNotifications(luNotificationsBusiness, AppUtilsBusiness, $mdToast, $state, 'articles');
  192. $translate('common.appName').then(function() {
  193. for (var i = 0; i < ssSideNav.sections.length; ++i) {
  194. var a = ssSideNav.sections[i];
  195. a.name = AppUtilsBusiness.tr(a.name);
  196. if (a.children != null) {
  197. for (var j = 0; j < a.children.length; ++j) {
  198. var b = a.children[j];
  199. b.name = AppUtilsBusiness.tr(b.name);
  200. if (b.pages != null) {
  201. for (var k = 0; k < b.pages.length; ++k) {
  202. var c = b.pages[k];
  203. c.name = AppUtilsBusiness.tr(c.name);
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }, function (error) {
  210. console.error(error);
  211. });
  212. $transitions.onEnter({}, function($transitions)
  213. {
  214. var toState = $transitions.$to();
  215. var title = toState.title != null ? toState.title : toState.toolbarTitle != null ? toState.toolbarTitle : null;
  216. var toolbarTitle = toState.toolbarTitle != null ? toState.toolbarTitle : toState.title != null ? toState.title : null;
  217. $translate('common.appName').then(function() {
  218. if (title != null) {
  219. AppUtilsBusiness.setTitle(AppUtilsBusiness.tr(title));
  220. }
  221. if (toolbarTitle != null) {
  222. AppUtilsBusiness.setToolbarTitle(AppUtilsBusiness.tr(toolbarTitle));
  223. }
  224. }, function (error) {
  225. console.error(error);
  226. });
  227. });
  228. }]);