Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. 'ngSanitize',
  83. 'SignalR',
  84. // 'luticateAuth',
  85. 'appSdk'
  86. ])
  87. .config(['$stateProvider', '$urlRouterProvider', 'ssSideNavSectionsProvider', '$mdThemingProvider',
  88. '$mdIconProvider', '$translateProvider', '$provide',
  89. function($stateProvider, $urlRouterProvider, ssSideNavSectionsProvider, $mdThemingProvider,
  90. $mdIconProvider, $translateProvider, $provide) {
  91. // $mdThemingProvider
  92. // .theme('default')
  93. // .primaryPalette('blue', {
  94. // 'default': '700'
  95. // });
  96. // $mdThemingProvider.theme('default')
  97. // .primaryPalette('blue')
  98. // .accentPalette('pink');
  99. $provide.decorator('$mdDialog', ['$delegate', function ($delegate) {
  100. // Get a handle of the show method
  101. var c = $delegate.show;
  102. function decorateDialogShow () {
  103. var args = angular.extend({}, arguments[0], {
  104. skipHide: true
  105. });
  106. if (args._options != null) {
  107. args._options = angular.extend({}, args._options, {
  108. skipHide: true
  109. });
  110. }
  111. return c(args);
  112. }
  113. $delegate.show = decorateDialogShow;
  114. return $delegate;
  115. }]);
  116. $translateProvider.useSanitizeValueStrategy('escapeParameters');
  117. $translateProvider.useMessageFormatInterpolation();
  118. $translateProvider.useStaticFilesLoader({
  119. prefix: 'translations/',
  120. suffix: '.json'
  121. });
  122. $translateProvider.preferredLanguage('en');
  123. $mdIconProvider
  124. .icon('md-toggle-arrow', 'img/arrow.svg');
  125. ssSideNavSectionsProvider.initWithTheme($mdThemingProvider);
  126. ssSideNavSectionsProvider.initWithSections([{
  127. id: 'toogle_1',
  128. name: 'home.categories',
  129. type: 'heading',
  130. children: [{
  131. id: 'persons.name',
  132. name: 'persons.name',
  133. state: 'persons',
  134. type: 'link'
  135. }, {
  136. id: 'locations.name',
  137. name: 'locations.name',
  138. state: 'locations',
  139. type: 'link'
  140. }, {
  141. id: 'countries.name',
  142. name: 'countries.name',
  143. state: 'countries',
  144. type: 'link'
  145. }]
  146. }]);
  147. $stateProvider.state('root', {
  148. abstract: true,
  149. template: '<div ui-view=""></div>',
  150. // resolve: ['luticateAuthUsers', function(luticateAuthUsers)
  151. // {
  152. // return luticateAuthUsers.loadUserData(null);
  153. // }]
  154. });
  155. $stateProvider.state('home', {
  156. url:'/',
  157. parent: 'root',
  158. title: 'home.name',
  159. reloadOnSearch: false,
  160. templateUrl:'views/home.html',
  161. controller:'HomeController'
  162. });
  163. $stateProvider.state('locations', {
  164. url:'/locations',
  165. parent: 'root',
  166. title: 'locations.name',
  167. reloadOnSearch: false,
  168. templateUrl:'views/articlesCategory.html',
  169. controller:'articleCategoryController',
  170. params: {
  171. type: 'locations'
  172. }
  173. });
  174. $stateProvider.state('persons', {
  175. url:'/persons',
  176. parent: 'root',
  177. title: 'persons.name',
  178. reloadOnSearch: false,
  179. templateUrl:'views/articlesCategory.html',
  180. controller:'articleCategoryController',
  181. params: {
  182. type: 'persons'
  183. }
  184. });
  185. $stateProvider.state('countries', {
  186. url:'/countries',
  187. parent: 'root',
  188. title: 'countries.name',
  189. reloadOnSearch: false,
  190. templateUrl:'views/articlesCategory.html',
  191. controller:'articleCategoryController',
  192. params: {
  193. type: 'countries'
  194. }
  195. });
  196. $stateProvider.state('articles_view', {
  197. url:'/articles/:id',
  198. parent: 'root',
  199. title: 'articles.name',
  200. reloadOnSearch: false,
  201. templateUrl:'views/articlesview.html',
  202. controller:'articlesViewController',
  203. params: {
  204. id: null,
  205. item: null
  206. }
  207. });
  208. addCrudStates($stateProvider, 'articles');
  209. $urlRouterProvider.otherwise('/');
  210. }])
  211. .run(['$rootScope', '$transitions', 'AppUtilsBusiness', 'ssSideNav', '$translate', 'luRequest', '$mdDialog',
  212. 'luNotificationsBusiness', '$mdToast', '$state', 'articlesBusiness',
  213. function ($rootScope, $transitions, AppUtilsBusiness, ssSideNav, $translate, luRequest, $mdDialog,
  214. luNotificationsBusiness, $mdToast, $state, articlesBusiness) {
  215. AppUtilsBusiness.addApiVersionChangedCallback(function(oldVersion, newVersion) {
  216. $mdDialog.show(
  217. $mdDialog.alert()
  218. .title(AppUtilsBusiness.tr('common.updateDetected.title'))
  219. .textContent(AppUtilsBusiness.tr('common.updateDetected.text',
  220. {oldVersion: oldVersion, newVersion: newVersion}))
  221. .ok(AppUtilsBusiness.tr('common.ok')));
  222. });
  223. luNotificationsBusiness.init({
  224. 'articles': articlesBusiness
  225. });
  226. addCrudNotifications(luNotificationsBusiness, AppUtilsBusiness, $mdToast, $state, 'articles');
  227. $translate('common.appName').then(function() {
  228. for (var i = 0; i < ssSideNav.sections.length; ++i) {
  229. var a = ssSideNav.sections[i];
  230. a.name = AppUtilsBusiness.tr(a.name);
  231. if (a.children != null) {
  232. for (var j = 0; j < a.children.length; ++j) {
  233. var b = a.children[j];
  234. b.name = AppUtilsBusiness.tr(b.name);
  235. if (b.pages != null) {
  236. for (var k = 0; k < b.pages.length; ++k) {
  237. var c = b.pages[k];
  238. c.name = AppUtilsBusiness.tr(c.name);
  239. }
  240. }
  241. }
  242. }
  243. }
  244. }, function (error) {
  245. console.error(error);
  246. });
  247. $transitions.onEnter({}, function($transitions)
  248. {
  249. var toState = $transitions.$to();
  250. var title = toState.title != null ? toState.title : toState.toolbarTitle != null ? toState.toolbarTitle : null;
  251. var toolbarTitle = toState.toolbarTitle != null ? toState.toolbarTitle : toState.title != null ? toState.title : null;
  252. $translate('common.appName').then(function() {
  253. if (title != null) {
  254. AppUtilsBusiness.setTitle(AppUtilsBusiness.tr(title));
  255. }
  256. if (toolbarTitle != null) {
  257. AppUtilsBusiness.setToolbarTitle(AppUtilsBusiness.tr(toolbarTitle));
  258. }
  259. }, function (error) {
  260. console.error(error);
  261. });
  262. });
  263. }]);