選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

app.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. name: 'home.name',
  131. type: 'toggle',
  132. pages: [{
  133. id: 'toogle_1_link_1',
  134. name: 'home.name',
  135. state: 'home'
  136. }, {
  137. id: 'toogle_1_link_2',
  138. name: 'Home 1 2',
  139. state: 'home.1.2',
  140. hidden: true
  141. }, {
  142. id: 'toogle_1_link_3',
  143. name: 'home.name',
  144. state: 'home.1.3'
  145. }]
  146. }]
  147. }, {
  148. id: 'link_1',
  149. name: 'home.name',
  150. state: 'home.2',
  151. type: 'link',
  152. icon: 'fa fa-check'
  153. }, {
  154. id: 'link_2',
  155. name: 'home.name',
  156. state: 'home.3',
  157. type: 'link'
  158. }, {
  159. id: 'link_3',
  160. name: 'home.name',
  161. state: 'common.link3',
  162. type: 'link',
  163. hidden: true
  164. }, {
  165. id: 'toogle_2',
  166. name: 'pkguids.name',
  167. type: 'heading',
  168. children: [{
  169. name: 'pkguids.name',
  170. type: 'toggle',
  171. pages: [{
  172. id: 'toogle_2_link_1',
  173. name: 'common.all',
  174. state: 'pkguids'
  175. },{
  176. id: 'toogle_2_link_1',
  177. name: 'common.new',
  178. state: 'pkguids_add'
  179. }]
  180. }]
  181. }]);
  182. $stateProvider.state('root', {
  183. abstract: true,
  184. template: '<div ui-view=""></div>',
  185. // resolve: ['luticateAuthUsers', function(luticateAuthUsers)
  186. // {
  187. // return luticateAuthUsers.loadUserData(null);
  188. // }]
  189. });
  190. $stateProvider.state('home', {
  191. url:'/',
  192. parent: 'root',
  193. title: "home.name",
  194. reloadOnSearch: false,
  195. templateUrl:'views/home.html',
  196. controller:'HomeController'
  197. });
  198. addCrudStates($stateProvider, 'pkguids');
  199. $urlRouterProvider.otherwise('/');
  200. }])
  201. .run(['$rootScope', '$transitions', 'AppUtilsBusiness', 'ssSideNav', '$translate', 'luRequest', '$mdDialog',
  202. 'luNotificationsBusiness', '$mdToast', '$state', 'pkguidsBusiness',
  203. function ($rootScope, $transitions, AppUtilsBusiness, ssSideNav, $translate, luRequest, $mdDialog,
  204. luNotificationsBusiness, $mdToast, $state, pkguidsBusiness) {
  205. AppUtilsBusiness.addApiVersionChangedCallback(function(oldVersion, newVersion) {
  206. $mdDialog.show(
  207. $mdDialog.alert()
  208. .title(AppUtilsBusiness.tr('common.updateDetected.title'))
  209. .textContent(AppUtilsBusiness.tr('common.updateDetected.text',
  210. {oldVersion: oldVersion, newVersion: newVersion}))
  211. .ok(AppUtilsBusiness.tr('common.ok')));
  212. });
  213. luNotificationsBusiness.init({
  214. 'pkguids': pkguidsBusiness
  215. });
  216. addCrudNotifications(luNotificationsBusiness, AppUtilsBusiness, $mdToast, $state, 'pkguids');
  217. $translate('common.appName').then(function() {
  218. for (var i = 0; i < ssSideNav.sections.length; ++i) {
  219. var a = ssSideNav.sections[i];
  220. a.name = AppUtilsBusiness.tr(a.name);
  221. if (a.children != null) {
  222. for (var j = 0; j < a.children.length; ++j) {
  223. var b = a.children[j];
  224. b.name = AppUtilsBusiness.tr(b.name);
  225. if (b.pages != null) {
  226. for (var k = 0; k < b.pages.length; ++k) {
  227. var c = b.pages[k];
  228. c.name = AppUtilsBusiness.tr(c.name);
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }, function (error) {
  235. console.error(error);
  236. });
  237. $transitions.onEnter({}, function($transitions)
  238. {
  239. var toState = $transitions.$to();
  240. var title = toState.title != null ? toState.title : toState.toolbarTitle != null ? toState.toolbarTitle : null;
  241. var toolbarTitle = toState.toolbarTitle != null ? toState.toolbarTitle : toState.title != null ? toState.title : null;
  242. $translate('common.appName').then(function() {
  243. if (title != null) {
  244. AppUtilsBusiness.setTitle(AppUtilsBusiness.tr(title));
  245. }
  246. if (toolbarTitle != null) {
  247. AppUtilsBusiness.setToolbarTitle(AppUtilsBusiness.tr(toolbarTitle));
  248. }
  249. }, function (error) {
  250. console.error(error);
  251. });
  252. });
  253. }]);