PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/xenon/xenon-files/angular/app/js/controllers.js

https://gitlab.com/prostudy/kit
JavaScript | 487 lines | 380 code | 88 blank | 19 comment | 19 complexity | 3d5e2ce746a7b54962d2a30de4c6ed00 MD5 | raw file
  1. 'use strict';
  2. angular.module('xenon.controllers', []).
  3. controller('LoginCtrl', function($scope, $rootScope)
  4. {
  5. $rootScope.isLoginPage = true;
  6. $rootScope.isLightLoginPage = false;
  7. $rootScope.isLockscreenPage = false;
  8. $rootScope.isMainPage = false;
  9. }).
  10. controller('LoginLightCtrl', function($scope, $rootScope)
  11. {
  12. $rootScope.isLoginPage = true;
  13. $rootScope.isLightLoginPage = true;
  14. $rootScope.isLockscreenPage = false;
  15. $rootScope.isMainPage = false;
  16. }).
  17. controller('LockscreenCtrl', function($scope, $rootScope)
  18. {
  19. $rootScope.isLoginPage = false;
  20. $rootScope.isLightLoginPage = false;
  21. $rootScope.isLockscreenPage = true;
  22. $rootScope.isMainPage = false;
  23. }).
  24. controller('MainCtrl', function($scope, $rootScope, $location, $layout, $layoutToggles, $pageLoadingBar, Fullscreen)
  25. {
  26. $rootScope.isLoginPage = false;
  27. $rootScope.isLightLoginPage = false;
  28. $rootScope.isLockscreenPage = false;
  29. $rootScope.isMainPage = true;
  30. $rootScope.layoutOptions = {
  31. horizontalMenu: {
  32. isVisible : false,
  33. isFixed : true,
  34. minimal : false,
  35. clickToExpand : false,
  36. isMenuOpenMobile: false
  37. },
  38. sidebar: {
  39. isVisible : true,
  40. isCollapsed : false,
  41. toggleOthers : true,
  42. isFixed : true,
  43. isRight : false,
  44. isMenuOpenMobile: false,
  45. // Added in v1.3
  46. userProfile : true
  47. },
  48. chat: {
  49. isOpen : false,
  50. },
  51. settingsPane: {
  52. isOpen : false,
  53. useAnimation : true
  54. },
  55. container: {
  56. isBoxed : false
  57. },
  58. skins: {
  59. sidebarMenu : '',
  60. horizontalMenu : '',
  61. userInfoNavbar : ''
  62. },
  63. pageTitles: true,
  64. userInfoNavVisible : false
  65. };
  66. $layout.loadOptionsFromCookies(); // remove this line if you don't want to support cookies that remember layout changes
  67. $scope.updatePsScrollbars = function()
  68. {
  69. var $scrollbars = jQuery(".ps-scrollbar:visible");
  70. $scrollbars.each(function(i, el)
  71. {
  72. if(typeof jQuery(el).data('perfectScrollbar') == 'undefined')
  73. {
  74. jQuery(el).perfectScrollbar();
  75. }
  76. else
  77. {
  78. jQuery(el).perfectScrollbar('update');
  79. }
  80. })
  81. };
  82. // Define Public Vars
  83. public_vars.$body = jQuery("body");
  84. // Init Layout Toggles
  85. $layoutToggles.initToggles();
  86. // Other methods
  87. $scope.setFocusOnSearchField = function()
  88. {
  89. public_vars.$body.find('.search-form input[name="s"]').focus();
  90. setTimeout(function(){ public_vars.$body.find('.search-form input[name="s"]').focus() }, 100 );
  91. };
  92. // Watch changes to replace checkboxes
  93. $scope.$watch(function()
  94. {
  95. cbr_replace();
  96. });
  97. // Watch sidebar status to remove the psScrollbar
  98. $rootScope.$watch('layoutOptions.sidebar.isCollapsed', function(newValue, oldValue)
  99. {
  100. if(newValue != oldValue)
  101. {
  102. if(newValue == true)
  103. {
  104. public_vars.$sidebarMenu.find('.sidebar-menu-inner').perfectScrollbar('destroy')
  105. }
  106. else
  107. {
  108. public_vars.$sidebarMenu.find('.sidebar-menu-inner').perfectScrollbar({wheelPropagation: public_vars.wheelPropagation});
  109. }
  110. }
  111. });
  112. // Page Loading Progress (remove/comment this line to disable it)
  113. $pageLoadingBar.init();
  114. $scope.showLoadingBar = showLoadingBar;
  115. $scope.hideLoadingBar = hideLoadingBar;
  116. // Set Scroll to 0 When page is changed
  117. $rootScope.$on('$stateChangeStart', function()
  118. {
  119. var obj = {pos: jQuery(window).scrollTop()};
  120. TweenLite.to(obj, .25, {pos: 0, ease:Power4.easeOut, onUpdate: function()
  121. {
  122. $(window).scrollTop(obj.pos);
  123. }});
  124. });
  125. // Full screen feature added in v1.3
  126. $scope.isFullscreenSupported = Fullscreen.isSupported();
  127. $scope.isFullscreen = Fullscreen.isEnabled() ? true : false;
  128. $scope.goFullscreen = function()
  129. {
  130. if (Fullscreen.isEnabled())
  131. Fullscreen.cancel();
  132. else
  133. Fullscreen.all();
  134. $scope.isFullscreen = Fullscreen.isEnabled() ? true : false;
  135. }
  136. }).
  137. controller('SidebarMenuCtrl', function($scope, $rootScope, $menuItems, $timeout, $location, $state, $layout)
  138. {
  139. // Menu Items
  140. var $sidebarMenuItems = $menuItems.instantiate();
  141. $scope.menuItems = $sidebarMenuItems.prepareSidebarMenu().getAll();
  142. // Set Active Menu Item
  143. $sidebarMenuItems.setActive( $location.path() );
  144. $rootScope.$on('$stateChangeSuccess', function()
  145. {
  146. $sidebarMenuItems.setActive($state.current.name);
  147. });
  148. // Trigger menu setup
  149. public_vars.$sidebarMenu = public_vars.$body.find('.sidebar-menu');
  150. $timeout(setup_sidebar_menu, 1);
  151. ps_init(); // perfect scrollbar for sidebar
  152. }).
  153. controller('HorizontalMenuCtrl', function($scope, $rootScope, $menuItems, $timeout, $location, $state)
  154. {
  155. var $horizontalMenuItems = $menuItems.instantiate();
  156. $scope.menuItems = $horizontalMenuItems.prepareHorizontalMenu().getAll();
  157. // Set Active Menu Item
  158. $horizontalMenuItems.setActive( $location.path() );
  159. $rootScope.$on('$stateChangeSuccess', function()
  160. {
  161. $horizontalMenuItems.setActive($state.current.name);
  162. $(".navbar.horizontal-menu .navbar-nav .hover").removeClass('hover'); // Close Submenus when item is selected
  163. });
  164. // Trigger menu setup
  165. $timeout(setup_horizontal_menu, 1);
  166. }).
  167. controller('SettingsPaneCtrl', function($rootScope)
  168. {
  169. // Define Settings Pane Public Variable
  170. public_vars.$settingsPane = public_vars.$body.find('.settings-pane');
  171. public_vars.$settingsPaneIn = public_vars.$settingsPane.find('.settings-pane-inner');
  172. }).
  173. controller('ChatCtrl', function($scope, $element)
  174. {
  175. var $chat = jQuery($element),
  176. $chat_conv = $chat.find('.chat-conversation');
  177. $chat.find('.chat-inner').perfectScrollbar(); // perfect scrollbar for chat container
  178. // Chat Conversation Window (sample)
  179. $chat.on('click', '.chat-group a', function(ev)
  180. {
  181. ev.preventDefault();
  182. $chat_conv.toggleClass('is-open');
  183. if($chat_conv.is(':visible'))
  184. {
  185. $chat.find('.chat-inner').perfectScrollbar('update');
  186. $chat_conv.find('textarea').autosize();
  187. }
  188. });
  189. $chat_conv.on('click', '.conversation-close', function(ev)
  190. {
  191. ev.preventDefault();
  192. $chat_conv.removeClass('is-open');
  193. });
  194. }).
  195. controller('UIModalsCtrl', function($scope, $rootScope, $modal, $sce)
  196. {
  197. // Open Simple Modal
  198. $scope.openModal = function(modal_id, modal_size, modal_backdrop)
  199. {
  200. $rootScope.currentModal = $modal.open({
  201. templateUrl: modal_id,
  202. size: modal_size,
  203. backdrop: typeof modal_backdrop == 'undefined' ? true : modal_backdrop
  204. });
  205. };
  206. // Loading AJAX Content
  207. $scope.openAjaxModal = function(modal_id, url_location)
  208. {
  209. $rootScope.currentModal = $modal.open({
  210. templateUrl: modal_id,
  211. resolve: {
  212. ajaxContent: function($http)
  213. {
  214. return $http.get(url_location).then(function(response){
  215. $rootScope.modalContent = $sce.trustAsHtml(response.data);
  216. }, function(response){
  217. $rootScope.modalContent = $sce.trustAsHtml('<div class="label label-danger">Cannot load ajax content! Please check the given url.</div>');
  218. });
  219. }
  220. }
  221. });
  222. $rootScope.modalContent = $sce.trustAsHtml('Modal content is loading...');
  223. }
  224. }).
  225. controller('PaginationDemoCtrl', function($scope)
  226. {
  227. $scope.totalItems = 64;
  228. $scope.currentPage = 4;
  229. $scope.setPage = function (pageNo)
  230. {
  231. $scope.currentPage = pageNo;
  232. };
  233. $scope.pageChanged = function()
  234. {
  235. console.log('Page changed to: ' + $scope.currentPage);
  236. };
  237. $scope.maxSize = 5;
  238. $scope.bigTotalItems = 175;
  239. $scope.bigCurrentPage = 1;
  240. }).
  241. controller('LayoutVariantsCtrl', function($scope, $layout, $cookies)
  242. {
  243. $scope.opts = {
  244. sidebarType: null,
  245. fixedSidebar: null,
  246. sidebarToggleOthers: null,
  247. sidebarVisible: null,
  248. sidebarPosition: null,
  249. horizontalVisible: null,
  250. fixedHorizontalMenu: null,
  251. horizontalOpenOnClick: null,
  252. minimalHorizontalMenu: null,
  253. sidebarProfile: null
  254. };
  255. $scope.sidebarTypes = [
  256. {value: ['sidebar.isCollapsed', false], text: 'Expanded', selected: $layout.is('sidebar.isCollapsed', false)},
  257. {value: ['sidebar.isCollapsed', true], text: 'Collapsed', selected: $layout.is('sidebar.isCollapsed', true)},
  258. ];
  259. $scope.fixedSidebar = [
  260. {value: ['sidebar.isFixed', true], text: 'Fixed', selected: $layout.is('sidebar.isFixed', true)},
  261. {value: ['sidebar.isFixed', false], text: 'Static', selected: $layout.is('sidebar.isFixed', false)},
  262. ];
  263. $scope.sidebarToggleOthers = [
  264. {value: ['sidebar.toggleOthers', true], text: 'Yes', selected: $layout.is('sidebar.toggleOthers', true)},
  265. {value: ['sidebar.toggleOthers', false], text: 'No', selected: $layout.is('sidebar.toggleOthers', false)},
  266. ];
  267. $scope.sidebarVisible = [
  268. {value: ['sidebar.isVisible', true], text: 'Visible', selected: $layout.is('sidebar.isVisible', true)},
  269. {value: ['sidebar.isVisible', false], text: 'Hidden', selected: $layout.is('sidebar.isVisible', false)},
  270. ];
  271. $scope.sidebarPosition = [
  272. {value: ['sidebar.isRight', false], text: 'Left', selected: $layout.is('sidebar.isRight', false)},
  273. {value: ['sidebar.isRight', true], text: 'Right', selected: $layout.is('sidebar.isRight', true)},
  274. ];
  275. $scope.horizontalVisible = [
  276. {value: ['horizontalMenu.isVisible', true], text: 'Visible', selected: $layout.is('horizontalMenu.isVisible', true)},
  277. {value: ['horizontalMenu.isVisible', false], text: 'Hidden', selected: $layout.is('horizontalMenu.isVisible', false)},
  278. ];
  279. $scope.fixedHorizontalMenu = [
  280. {value: ['horizontalMenu.isFixed', true], text: 'Fixed', selected: $layout.is('horizontalMenu.isFixed', true)},
  281. {value: ['horizontalMenu.isFixed', false], text: 'Static', selected: $layout.is('horizontalMenu.isFixed', false)},
  282. ];
  283. $scope.horizontalOpenOnClick = [
  284. {value: ['horizontalMenu.clickToExpand', false], text: 'No', selected: $layout.is('horizontalMenu.clickToExpand', false)},
  285. {value: ['horizontalMenu.clickToExpand', true], text: 'Yes', selected: $layout.is('horizontalMenu.clickToExpand', true)},
  286. ];
  287. $scope.minimalHorizontalMenu = [
  288. {value: ['horizontalMenu.minimal', false], text: 'No', selected: $layout.is('horizontalMenu.minimal', false)},
  289. {value: ['horizontalMenu.minimal', true], text: 'Yes', selected: $layout.is('horizontalMenu.minimal', true)},
  290. ];
  291. $scope.chatVisibility = [
  292. {value: ['chat.isOpen', false], text: 'No', selected: $layout.is('chat.isOpen', false)},
  293. {value: ['chat.isOpen', true], text: 'Yes', selected: $layout.is('chat.isOpen', true)},
  294. ];
  295. $scope.boxedContainer = [
  296. {value: ['container.isBoxed', false], text: 'No', selected: $layout.is('container.isBoxed', false)},
  297. {value: ['container.isBoxed', true], text: 'Yes', selected: $layout.is('container.isBoxed', true)},
  298. ];
  299. $scope.sidebarProfile = [
  300. {value: ['sidebar.userProfile', false], text: 'No', selected: $layout.is('sidebar.userProfile', false)},
  301. {value: ['sidebar.userProfile', true], text: 'Yes', selected: $layout.is('sidebar.userProfile', true)},
  302. ];
  303. $scope.resetOptions = function()
  304. {
  305. $layout.resetCookies();
  306. window.location.reload();
  307. };
  308. var setValue = function(val)
  309. {
  310. if(val != null)
  311. {
  312. val = eval(val);
  313. $layout.setOptions(val[0], val[1]);
  314. }
  315. };
  316. $scope.$watch('opts.sidebarType', setValue);
  317. $scope.$watch('opts.fixedSidebar', setValue);
  318. $scope.$watch('opts.sidebarToggleOthers', setValue);
  319. $scope.$watch('opts.sidebarVisible', setValue);
  320. $scope.$watch('opts.sidebarPosition', setValue);
  321. $scope.$watch('opts.horizontalVisible', setValue);
  322. $scope.$watch('opts.fixedHorizontalMenu', setValue);
  323. $scope.$watch('opts.horizontalOpenOnClick', setValue);
  324. $scope.$watch('opts.minimalHorizontalMenu', setValue);
  325. $scope.$watch('opts.chatVisibility', setValue);
  326. $scope.$watch('opts.boxedContainer', setValue);
  327. $scope.$watch('opts.sidebarProfile', setValue);
  328. }).
  329. controller('ThemeSkinsCtrl', function($scope, $layout)
  330. {
  331. var $body = jQuery("body");
  332. $scope.opts = {
  333. sidebarSkin: $layout.get('skins.sidebarMenu'),
  334. horizontalMenuSkin: $layout.get('skins.horizontalMenu'),
  335. userInfoNavbarSkin: $layout.get('skins.userInfoNavbar')
  336. };
  337. $scope.skins = [
  338. {value: '', name: 'Default' , palette: ['#2c2e2f','#EEEEEE','#FFFFFF','#68b828','#27292a','#323435']},
  339. {value: 'aero', name: 'Aero' , palette: ['#558C89','#ECECEA','#FFFFFF','#5F9A97','#558C89','#255E5b']},
  340. {value: 'navy', name: 'Navy' , palette: ['#2c3e50','#a7bfd6','#FFFFFF','#34495e','#2c3e50','#ff4e50']},
  341. {value: 'facebook', name: 'Facebook' , palette: ['#3b5998','#8b9dc3','#FFFFFF','#4160a0','#3b5998','#8b9dc3']},
  342. {value: 'turquoise', name: 'Truquoise' , palette: ['#16a085','#96ead9','#FFFFFF','#1daf92','#16a085','#0f7e68']},
  343. {value: 'lime', name: 'Lime' , palette: ['#8cc657','#ffffff','#FFFFFF','#95cd62','#8cc657','#70a93c']},
  344. {value: 'green', name: 'Green' , palette: ['#27ae60','#a2f9c7','#FFFFFF','#2fbd6b','#27ae60','#1c954f']},
  345. {value: 'purple', name: 'Purple' , palette: ['#795b95','#c2afd4','#FFFFFF','#795b95','#27ae60','#5f3d7e']},
  346. {value: 'white', name: 'White' , palette: ['#FFFFFF','#666666','#95cd62','#EEEEEE','#95cd62','#555555']},
  347. {value: 'concrete', name: 'Concrete' , palette: ['#a8aba2','#666666','#a40f37','#b8bbb3','#a40f37','#323232']},
  348. {value: 'watermelon', name: 'Watermelon' , palette: ['#b63131','#f7b2b2','#FFFFFF','#c03737','#b63131','#32932e']},
  349. {value: 'lemonade', name: 'Lemonade' , palette: ['#f5c150','#ffeec9','#FFFFFF','#ffcf67','#f5c150','#d9a940']},
  350. ];
  351. $scope.$watch('opts.sidebarSkin', function(val)
  352. {
  353. if(val != null)
  354. {
  355. $layout.setOptions('skins.sidebarMenu', val);
  356. $body.attr('class', $body.attr('class').replace(/\sskin-[a-z]+/)).addClass('skin-' + val);
  357. }
  358. });
  359. $scope.$watch('opts.horizontalMenuSkin', function(val)
  360. {
  361. if(val != null)
  362. {
  363. $layout.setOptions('skins.horizontalMenu', val);
  364. $body.attr('class', $body.attr('class').replace(/\shorizontal-menu-skin-[a-z]+/)).addClass('horizontal-menu-skin-' + val);
  365. }
  366. });
  367. $scope.$watch('opts.userInfoNavbarSkin', function(val)
  368. {
  369. if(val != null)
  370. {
  371. $layout.setOptions('skins.userInfoNavbar', val);
  372. $body.attr('class', $body.attr('class').replace(/\suser-info-navbar-skin-[a-z]+/)).addClass('user-info-navbar-skin-' + val);
  373. }
  374. });
  375. }).
  376. // Added in v1.3
  377. controller('FooterChatCtrl', function($scope, $element)
  378. {
  379. $scope.isConversationVisible = false;
  380. $scope.toggleChatConversation = function()
  381. {
  382. $scope.isConversationVisible = ! $scope.isConversationVisible;
  383. if($scope.isConversationVisible)
  384. {
  385. setTimeout(function()
  386. {
  387. var $el = $element.find('.ps-scrollbar');
  388. if($el.hasClass('ps-scroll-down'))
  389. {
  390. $el.scrollTop($el.prop('scrollHeight'));
  391. }
  392. $el.perfectScrollbar({
  393. wheelPropagation: false
  394. });
  395. $element.find('.form-control').focus();
  396. }, 300);
  397. }
  398. }
  399. });