Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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.categories',
  128. type: 'heading',
  129. children: [{
  130. id: 'persons.name',
  131. name: 'persons.name',
  132. state: 'persons',
  133. type: 'link'
  134. }, {
  135. id: 'locations.name',
  136. name: 'locations.name',
  137. state: 'locations',
  138. type: 'link'
  139. }, {
  140. id: 'countries.name',
  141. name: 'countries.name',
  142. state: 'countries',
  143. type: 'link'
  144. }]
  145. },
  146. {
  147. id: 'toogle_2',
  148. name: 'articles.name',
  149. type: 'heading',
  150. children: [{
  151. id: 'toogle_2_link_1',
  152. name: 'common.all',
  153. state: 'articles',
  154. type: 'link'
  155. },{
  156. id: 'toogle_2_link_1',
  157. name: 'common.new',
  158. state: 'articles_add',
  159. type: 'link'
  160. }]
  161. }]);
  162. $stateProvider.state('root', {
  163. abstract: true,
  164. template: '<div ui-view=""></div>',
  165. // resolve: ['luticateAuthUsers', function(luticateAuthUsers)
  166. // {
  167. // return luticateAuthUsers.loadUserData(null);
  168. // }]
  169. });
  170. $stateProvider.state('home', {
  171. url:'/',
  172. parent: 'root',
  173. title: 'home.name',
  174. reloadOnSearch: false,
  175. templateUrl:'views/home.html',
  176. controller:'HomeController'
  177. });
  178. $stateProvider.state('locations', {
  179. url:'/locations',
  180. parent: 'root',
  181. title: 'locations.name',
  182. reloadOnSearch: false,
  183. templateUrl:'views/articlesCategory.html',
  184. controller:'articleCategoryController',
  185. params: {
  186. type: 'locations'
  187. }
  188. });
  189. $stateProvider.state('persons', {
  190. url:'/persons',
  191. parent: 'root',
  192. title: 'persons.name',
  193. reloadOnSearch: false,
  194. templateUrl:'views/articlesCategory.html',
  195. controller:'articleCategoryController',
  196. params: {
  197. type: 'persons'
  198. }
  199. });
  200. $stateProvider.state('countries', {
  201. url:'/countries',
  202. parent: 'root',
  203. title: 'countries.name',
  204. reloadOnSearch: false,
  205. templateUrl:'views/articlesCategory.html',
  206. controller:'articleCategoryController',
  207. params: {
  208. type: 'countries'
  209. }
  210. });
  211. $stateProvider.state('articles_view', {
  212. url:'/articles/:id',
  213. parent: 'root',
  214. title: 'articles.name',
  215. reloadOnSearch: false,
  216. templateUrl:'views/articlesview.html',
  217. controller:'articlesViewController',
  218. params: {
  219. id: null,
  220. item: null
  221. }
  222. });
  223. addCrudStates($stateProvider, 'articles');
  224. $urlRouterProvider.otherwise('/');
  225. }])
  226. .run(['$rootScope', '$transitions', 'AppUtilsBusiness', 'ssSideNav', '$translate', 'luRequest', '$mdDialog',
  227. 'luNotificationsBusiness', '$mdToast', '$state', 'articlesBusiness',
  228. function ($rootScope, $transitions, AppUtilsBusiness, ssSideNav, $translate, luRequest, $mdDialog,
  229. luNotificationsBusiness, $mdToast, $state, articlesBusiness) {
  230. AppUtilsBusiness.addApiVersionChangedCallback(function(oldVersion, newVersion) {
  231. $mdDialog.show(
  232. $mdDialog.alert()
  233. .title(AppUtilsBusiness.tr('common.updateDetected.title'))
  234. .textContent(AppUtilsBusiness.tr('common.updateDetected.text',
  235. {oldVersion: oldVersion, newVersion: newVersion}))
  236. .ok(AppUtilsBusiness.tr('common.ok')));
  237. });
  238. luNotificationsBusiness.init({
  239. 'articles': articlesBusiness
  240. });
  241. addCrudNotifications(luNotificationsBusiness, AppUtilsBusiness, $mdToast, $state, 'articles');
  242. $translate('common.appName').then(function() {
  243. for (var i = 0; i < ssSideNav.sections.length; ++i) {
  244. var a = ssSideNav.sections[i];
  245. a.name = AppUtilsBusiness.tr(a.name);
  246. if (a.children != null) {
  247. for (var j = 0; j < a.children.length; ++j) {
  248. var b = a.children[j];
  249. b.name = AppUtilsBusiness.tr(b.name);
  250. if (b.pages != null) {
  251. for (var k = 0; k < b.pages.length; ++k) {
  252. var c = b.pages[k];
  253. c.name = AppUtilsBusiness.tr(c.name);
  254. }
  255. }
  256. }
  257. }
  258. }
  259. }, function (error) {
  260. console.error(error);
  261. });
  262. $transitions.onEnter({}, function($transitions)
  263. {
  264. var toState = $transitions.$to();
  265. var title = toState.title != null ? toState.title : toState.toolbarTitle != null ? toState.toolbarTitle : null;
  266. var toolbarTitle = toState.toolbarTitle != null ? toState.toolbarTitle : toState.title != null ? toState.title : null;
  267. $translate('common.appName').then(function() {
  268. if (title != null) {
  269. AppUtilsBusiness.setTitle(AppUtilsBusiness.tr(title));
  270. }
  271. if (toolbarTitle != null) {
  272. AppUtilsBusiness.setToolbarTitle(AppUtilsBusiness.tr(toolbarTitle));
  273. }
  274. }, function (error) {
  275. console.error(error);
  276. });
  277. });
  278. }]);