PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/PatientCare.UI/js/directives.js

https://gitlab.com/justbediego/PatientCare
JavaScript | 487 lines | 367 code | 48 blank | 72 comment | 15 complexity | 0467efb1aba5bc6774c0ee6f8f76961b MD5 | raw file
  1. /**
  2. * pageTitle - Directive for set Page title - mata title
  3. */
  4. function pageTitle($rootScope, $timeout) {
  5. return {
  6. link: function(scope, element) {
  7. var listener = function(event, toState, toParams, fromState, fromParams) {
  8. // Default title - load on Dashboard 1
  9. var title = 'INSPINIA | Responsive Admin Theme';
  10. // Create your own title pattern
  11. if (toState.data && toState.data.pageTitle) title = 'INSPINIA | ' + toState.data.pageTitle;
  12. $timeout(function() {
  13. element.text(title);
  14. });
  15. };
  16. $rootScope.$on('$stateChangeStart', listener);
  17. }
  18. }
  19. };
  20. /**
  21. * sideNavigation - Directive for run metsiMenu on sidebar navigation
  22. */
  23. function sideNavigation($timeout) {
  24. return {
  25. restrict: 'A',
  26. link: function(scope, element) {
  27. // Call the metsiMenu plugin and plug it to sidebar navigation
  28. $timeout(function(){
  29. element.metisMenu();
  30. });
  31. // Enable initial fixed sidebar
  32. //var sidebar = element.parent();
  33. //sidebar.slimScroll({
  34. // height: '100%',
  35. // railOpacity: 0.9,
  36. //});
  37. }
  38. };
  39. };
  40. /**
  41. * responsibleVideo - Directive for responsive video
  42. */
  43. function responsiveVideo() {
  44. return {
  45. restrict: 'A',
  46. link: function(scope, element) {
  47. var figure = element;
  48. var video = element.children();
  49. video
  50. .attr('data-aspectRatio', video.height() / video.width())
  51. .removeAttr('height')
  52. .removeAttr('width')
  53. //We can use $watch on $window.innerWidth also.
  54. $(window).resize(function() {
  55. var newWidth = figure.width();
  56. video
  57. .width(newWidth)
  58. .height(newWidth * video.attr('data-aspectRatio'));
  59. }).resize();
  60. }
  61. }
  62. }
  63. /**
  64. * minimalizaSidebar - Directive for minimalize sidebar
  65. */
  66. function minimalizaSidebar($timeout) {
  67. return {
  68. restrict: 'A',
  69. template: '<a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="" ng-click="minimalize()"><i class="fa fa-bars"></i></a>',
  70. controller: function ($scope, $element) {
  71. $scope.minimalize = function () {
  72. $("body").toggleClass("mini-navbar");
  73. if (!$('body').hasClass('mini-navbar') || $('body').hasClass('body-small')) {
  74. // Hide menu in order to smoothly turn on when maximize menu
  75. $('#side-menu').hide();
  76. // For smoothly turn on menu
  77. setTimeout(
  78. function () {
  79. $('#side-menu').fadeIn(400);
  80. }, 200);
  81. } else if ($('body').hasClass('fixed-sidebar')){
  82. $('#side-menu').hide();
  83. setTimeout(
  84. function () {
  85. $('#side-menu').fadeIn(400);
  86. }, 100);
  87. } else {
  88. // Remove all inline style from jquery fadeIn function to reset menu state
  89. $('#side-menu').removeAttr('style');
  90. }
  91. }
  92. }
  93. };
  94. };
  95. function closeOffCanvas() {
  96. return {
  97. restrict: 'A',
  98. template: '<a class="close-canvas-menu" ng-click="closeOffCanvas()"><i class="fa fa-times"></i></a>',
  99. controller: function ($scope, $element) {
  100. $scope.closeOffCanvas = function () {
  101. $("body").toggleClass("mini-navbar");
  102. }
  103. }
  104. };
  105. }
  106. /**
  107. * vectorMap - Directive for Vector map plugin
  108. */
  109. function vectorMap() {
  110. return {
  111. restrict: 'A',
  112. scope: {
  113. myMapData: '=',
  114. },
  115. link: function (scope, element, attrs) {
  116. var map = element.vectorMap({
  117. map: 'world_mill_en',
  118. backgroundColor: "transparent",
  119. regionStyle: {
  120. initial: {
  121. fill: '#e4e4e4',
  122. "fill-opacity": 0.9,
  123. stroke: 'none',
  124. "stroke-width": 0,
  125. "stroke-opacity": 0
  126. }
  127. },
  128. series: {
  129. regions: [
  130. {
  131. values: scope.myMapData,
  132. scale: ["#1ab394", "#22d6b1"],
  133. normalizeFunction: 'polynomial'
  134. }
  135. ]
  136. },
  137. });
  138. var destroyMap = function(){
  139. element.remove();
  140. };
  141. scope.$on('$destroy', function() {
  142. destroyMap();
  143. });
  144. }
  145. }
  146. }
  147. /**
  148. * sparkline - Directive for Sparkline chart
  149. */
  150. function sparkline() {
  151. return {
  152. restrict: 'A',
  153. scope: {
  154. sparkData: '=',
  155. sparkOptions: '=',
  156. },
  157. link: function (scope, element, attrs) {
  158. scope.$watch(scope.sparkData, function () {
  159. render();
  160. });
  161. scope.$watch(scope.sparkOptions, function(){
  162. render();
  163. });
  164. var render = function () {
  165. $(element).sparkline(scope.sparkData, scope.sparkOptions);
  166. };
  167. }
  168. }
  169. };
  170. /**
  171. * icheck - Directive for custom checkbox icheck
  172. */
  173. function icheck($timeout) {
  174. return {
  175. restrict: 'A',
  176. require: 'ngModel',
  177. link: function($scope, element, $attrs, ngModel) {
  178. return $timeout(function() {
  179. var value;
  180. value = $attrs['value'];
  181. $scope.$watch($attrs['ngModel'], function(newValue){
  182. $(element).iCheck('update');
  183. })
  184. return $(element).iCheck({
  185. checkboxClass: 'icheckbox_square-green',
  186. radioClass: 'iradio_square-green'
  187. }).on('ifChanged', function(event) {
  188. if ($(element).attr('type') === 'checkbox' && $attrs['ngModel']) {
  189. $scope.$apply(function() {
  190. return ngModel.$setViewValue(event.target.checked);
  191. });
  192. }
  193. if ($(element).attr('type') === 'radio' && $attrs['ngModel']) {
  194. return $scope.$apply(function() {
  195. return ngModel.$setViewValue(value);
  196. });
  197. }
  198. });
  199. });
  200. }
  201. };
  202. }
  203. /**
  204. * ionRangeSlider - Directive for Ion Range Slider
  205. */
  206. function ionRangeSlider() {
  207. return {
  208. restrict: 'A',
  209. scope: {
  210. rangeOptions: '='
  211. },
  212. link: function (scope, elem, attrs) {
  213. elem.ionRangeSlider(scope.rangeOptions);
  214. }
  215. }
  216. }
  217. /**
  218. * dropZone - Directive for Drag and drop zone file upload plugin
  219. */
  220. function dropZone() {
  221. return {
  222. restrict: 'C',
  223. link: function(scope, element, attrs) {
  224. var config = {
  225. url: 'http://localhost:8080/upload',
  226. maxFilesize: 100,
  227. paramName: "uploadfile",
  228. maxThumbnailFilesize: 10,
  229. parallelUploads: 1,
  230. autoProcessQueue: false
  231. };
  232. var eventHandlers = {
  233. 'addedfile': function(file) {
  234. scope.file = file;
  235. if (this.files[1]!=null) {
  236. this.removeFile(this.files[0]);
  237. }
  238. scope.$apply(function() {
  239. scope.fileAdded = true;
  240. });
  241. },
  242. 'success': function (file, response) {
  243. }
  244. };
  245. dropzone = new Dropzone(element[0], config);
  246. angular.forEach(eventHandlers, function(handler, event) {
  247. dropzone.on(event, handler);
  248. });
  249. scope.processDropzone = function() {
  250. dropzone.processQueue();
  251. };
  252. scope.resetDropzone = function() {
  253. dropzone.removeAllFiles();
  254. }
  255. }
  256. }
  257. }
  258. /**
  259. * chatSlimScroll - Directive for slim scroll for small chat
  260. */
  261. function chatSlimScroll($timeout) {
  262. return {
  263. restrict: 'A',
  264. link: function(scope, element) {
  265. $timeout(function(){
  266. element.slimscroll({
  267. height: '234px',
  268. railOpacity: 0.4
  269. });
  270. });
  271. }
  272. };
  273. }
  274. /**
  275. * customValid - Directive for custom validation example
  276. */
  277. function customValid(){
  278. return {
  279. require: 'ngModel',
  280. link: function(scope, ele, attrs, c) {
  281. scope.$watch(attrs.ngModel, function() {
  282. // You can call a $http method here
  283. // Or create custom validation
  284. var validText = "Inspinia";
  285. if(scope.extras == validText) {
  286. c.$setValidity('cvalid', true);
  287. } else {
  288. c.$setValidity('cvalid', false);
  289. }
  290. });
  291. }
  292. }
  293. }
  294. /**
  295. * fullScroll - Directive for slimScroll with 100%
  296. */
  297. function fullScroll($timeout){
  298. return {
  299. restrict: 'A',
  300. link: function(scope, element) {
  301. $timeout(function(){
  302. element.slimscroll({
  303. height: '100%',
  304. railOpacity: 0.9
  305. });
  306. });
  307. }
  308. };
  309. }
  310. /**
  311. * slimScroll - Directive for slimScroll with custom height
  312. */
  313. function slimScroll($timeout){
  314. return {
  315. restrict: 'A',
  316. scope: {
  317. boxHeight: '@'
  318. },
  319. link: function(scope, element) {
  320. $timeout(function(){
  321. element.slimscroll({
  322. height: scope.boxHeight,
  323. railOpacity: 0.9
  324. });
  325. });
  326. }
  327. };
  328. }
  329. /**
  330. * clockPicker - Directive for clock picker plugin
  331. */
  332. function clockPicker() {
  333. return {
  334. restrict: 'A',
  335. link: function(scope, element) {
  336. element.clockpicker();
  337. }
  338. };
  339. };
  340. /**
  341. * landingScrollspy - Directive for scrollspy in landing page
  342. */
  343. function landingScrollspy(){
  344. return {
  345. restrict: 'A',
  346. link: function (scope, element, attrs) {
  347. element.scrollspy({
  348. target: '.navbar-fixed-top',
  349. offset: 80
  350. });
  351. }
  352. }
  353. }
  354. /**
  355. * fitHeight - Directive for set height fit to window height
  356. */
  357. function fitHeight(){
  358. return {
  359. restrict: 'A',
  360. link: function(scope, element) {
  361. element.css("height", $(window).height() + "px");
  362. element.css("min-height", $(window).height() + "px");
  363. }
  364. };
  365. }
  366. /**
  367. * truncate - Directive for truncate string
  368. */
  369. function truncate($timeout){
  370. return {
  371. restrict: 'A',
  372. scope: {
  373. truncateOptions: '='
  374. },
  375. link: function(scope, element) {
  376. $timeout(function(){
  377. element.dotdotdot(scope.truncateOptions);
  378. });
  379. }
  380. };
  381. }
  382. /**
  383. * touchSpin - Directive for Bootstrap TouchSpin
  384. */
  385. function touchSpin() {
  386. return {
  387. restrict: 'A',
  388. scope: {
  389. spinOptions: '='
  390. },
  391. link: function (scope, element, attrs) {
  392. scope.$watch(scope.spinOptions, function(){
  393. render();
  394. });
  395. var render = function () {
  396. $(element).TouchSpin(scope.spinOptions);
  397. };
  398. }
  399. }
  400. };
  401. /**
  402. * markdownEditor - Directive for Bootstrap Markdown
  403. */
  404. function markdownEditor() {
  405. return {
  406. restrict: "A",
  407. require: 'ngModel',
  408. link: function (scope, element, attrs, ngModel) {
  409. $(element).markdown({
  410. savable:false,
  411. onChange: function(e){
  412. ngModel.$setViewValue(e.getContent());
  413. }
  414. });
  415. }
  416. }
  417. };
  418. angular
  419. .module('PatientCare')
  420. .directive('pageTitle', pageTitle)
  421. .directive('sideNavigation', sideNavigation)
  422. .directive('minimalizaSidebar', minimalizaSidebar)
  423. .directive('vectorMap', vectorMap)
  424. .directive('sparkline', sparkline)
  425. .directive('icheck', icheck)
  426. .directive('ionRangeSlider', ionRangeSlider)
  427. .directive('dropZone', dropZone)
  428. .directive('responsiveVideo', responsiveVideo)
  429. .directive('chatSlimScroll', chatSlimScroll)
  430. .directive('customValid', customValid)
  431. .directive('fullScroll', fullScroll)
  432. .directive('closeOffCanvas', closeOffCanvas)
  433. .directive('clockPicker', clockPicker)
  434. .directive('landingScrollspy', landingScrollspy)
  435. .directive('fitHeight', fitHeight)
  436. .directive('slimScroll', slimScroll)
  437. .directive('truncate', truncate)
  438. .directive('touchSpin', touchSpin)
  439. .directive('markdownEditor', markdownEditor);