图书馆智能管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
7.5 KiB

5 months ago
  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. 'use strict';
  14. var flowableApp = angular.module('flowableLanding', [
  15. 'ngCookies',
  16. 'ngResource',
  17. 'ngSanitize',
  18. 'ngRoute',
  19. 'mgcrea.ngStrap',
  20. 'ngAnimate',
  21. 'pascalprecht.translate'
  22. ]);
  23. var flowableModule = flowableApp;
  24. flowableApp
  25. // Initialize routes
  26. .config(['$provide', '$routeProvider', '$selectProvider', '$datepickerProvider', '$translateProvider', function ($provide, $routeProvider, $selectProvider, $datepickerProvider, $translateProvider) {
  27. var appName = '';
  28. $provide.value('appName', appName);
  29. var ctx = FLOWABLE.CONFIG.landingContextRoot;
  30. var appResourceRoot = ctx + (ctx && ctx.charAt(ctx.length - 1) !== '/' ? '/' : '');
  31. $provide.value('appResourceRoot', appResourceRoot);
  32. // Override caret for bs-select directive
  33. angular.extend($selectProvider.defaults, {
  34. caretHtml: '&nbsp;<i class="icon icon-caret-down"></i>'
  35. });
  36. // Override carets for bs-datepicker directive
  37. angular.extend($datepickerProvider.defaults, {
  38. iconLeft: 'icon icon-caret-left',
  39. iconRight: 'icon icon-caret-right'
  40. });
  41. $routeProvider
  42. .when('/', {
  43. templateUrl: 'views/landing.html',
  44. controller: 'LandingController'
  45. })
  46. .otherwise({
  47. redirectTo: FLOWABLE.CONFIG.appDefaultRoute || '/'
  48. });
  49. // Initialize angular-translate
  50. $translateProvider.useStaticFilesLoader({
  51. prefix: './i18n/',
  52. suffix: '.json'
  53. })
  54. /*
  55. This can be used to map multiple browser language keys to a
  56. angular translate language key.
  57. */
  58. // .registerAvailableLanguageKeys(['en'], {
  59. // 'en-*': 'en'
  60. // })
  61. .useSanitizeValueStrategy('escapeParameters')
  62. .uniformLanguageTag('bcp47')
  63. .determinePreferredLanguage();
  64. }])
  65. .run(['$rootScope', '$timeout', '$translate', '$location', '$http', '$window', '$popover', 'appResourceRoot', 'RuntimeAppDefinitionService',
  66. function($rootScope, $timeout, $translate, $location, $http, $window, $popover, appResourceRoot, RuntimeAppDefinitionService) {
  67. // set angular translate fallback language
  68. $translate.fallbackLanguage(['en']);
  69. $rootScope.appResourceRoot = appResourceRoot;
  70. // Alerts
  71. $rootScope.alerts = {
  72. queue: []
  73. };
  74. $rootScope.webRootUrl = function() {
  75. return FLOWABLE.CONFIG.webContextRoot;
  76. };
  77. $rootScope.restRootUrl = function() {
  78. return FLOWABLE.CONFIG.contextRoot;
  79. };
  80. $rootScope.showAlert = function(alert) {
  81. if(alert.queue.length > 0) {
  82. alert.current = alert.queue.shift();
  83. // Start timout for message-pruning
  84. alert.timeout = $timeout(function() {
  85. if(alert.queue.length == 0) {
  86. alert.current = undefined;
  87. alert.timeout = undefined;
  88. } else {
  89. $rootScope.showAlert(alert);
  90. }
  91. }, (alert.current.type == 'error' ? 5000 : 1000));
  92. } else {
  93. $rootScope.alerts.current = undefined;
  94. }
  95. };
  96. $rootScope.addAlert = function(message, type) {
  97. var newAlert = {message: message, type: type};
  98. if(!$rootScope.alerts.timeout) {
  99. // Timeout for message queue is not running, start one
  100. $rootScope.alerts.queue.push(newAlert);
  101. $rootScope.showAlert($rootScope.alerts);
  102. } else {
  103. $rootScope.alerts.queue.push(newAlert);
  104. }
  105. };
  106. $rootScope.dismissAlert = function() {
  107. if(!$rootScope.alerts.timeout) {
  108. $rootScope.alerts.current = undefined;
  109. } else {
  110. $timeout.cancel($rootScope.alerts.timeout);
  111. $rootScope.alerts.timeout = undefined;
  112. $rootScope.showAlert($rootScope.alerts);
  113. }
  114. };
  115. $rootScope.addAlertPromise = function(promise, type) {
  116. if(promise) {
  117. promise.then(function(data) {
  118. $rootScope.addAlert(data, type);
  119. });
  120. }
  121. };
  122. $rootScope.logout = function () {
  123. $rootScope.authenticated = false;
  124. $rootScope.authenticationError = false;
  125. $window.location.href = FLOWABLE.CONFIG.contextRoot + '/app/logout';
  126. };
  127. $http.get(FLOWABLE.CONFIG.landingContextRoot + '/app/rest/account')
  128. .success(function (data, status, headers, config) {
  129. $rootScope.account = data;
  130. $rootScope.invalidCredentials = false;
  131. $rootScope.authenticated = true;
  132. });
  133. }])
  134. .run(['$rootScope', '$location', '$window', '$translate', '$modal',
  135. function($rootScope, $location, $window, $translate, $modal) {
  136. /* Auto-height */
  137. $rootScope.window = {};
  138. var updateWindowSize = function() {
  139. $rootScope.window.width = $window.innerWidth;
  140. $rootScope.window.height = $window.innerHeight;
  141. };
  142. // Window resize hook
  143. angular.element($window).bind('resize', function() {
  144. $rootScope.$apply(updateWindowSize());
  145. });
  146. $rootScope.$watch('window.forceRefresh', function(newValue) {
  147. if(newValue) {
  148. $timeout(function() {
  149. updateWindowSize();
  150. $rootScope.window.forceRefresh = false;
  151. });
  152. }
  153. });
  154. updateWindowSize();
  155. /* Capabilities */
  156. $rootScope.backToLanding = function() {
  157. var baseUrl = $location.absUrl();
  158. var index = baseUrl.indexOf('/#');
  159. if (index >= 0) {
  160. baseUrl = baseUrl.substring(0, index);
  161. baseUrl += '/';
  162. }
  163. $window.location.href = baseUrl;
  164. };
  165. }])
  166. .filter('username', function() {
  167. return function(user) {
  168. if (user) {
  169. if (user.fullName) {
  170. return user.fullName;
  171. } else if(user.firstName) {
  172. return user.firstName + " " + user.lastName;
  173. } else if(user.lastName) {
  174. return user.lastName;
  175. } else if (user.email) {
  176. return user.email
  177. } else if (typeof user === 'string') {
  178. var _user = user.split(".");
  179. if (_user.length > 1){
  180. user = _user[0].charAt(0).toUpperCase() + _user[0].slice(1) +" "+ _user[1].charAt(0).toUpperCase() + _user[1].slice(1);
  181. } else {
  182. user = _user[0].charAt(0).toUpperCase() + _user[0].slice(1);
  183. }
  184. return user;
  185. } else {
  186. return user.id;
  187. }
  188. }
  189. return '';
  190. };
  191. });
  192. ;