app.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. var vstartdate = [];
  2. var datefor = null;
  3. var testcal = "";
  4. define(['angularAMD', 'angular-route', 'angular-animate', 'angular-bootstrap', 'moment', 'angularTreeview','angularjs-dropdown-multiselect'], function (angularAMD) {
  5. var app = angular.module("tti", ['ngRoute', 'ui.bootstrap', 'angularTreeview','angularjs-datetime-picker','angularjs-dropdown-multiselect']);
  6. app.config(function ($routeProvider) {
  7. $routeProvider
  8. .when("/login", angularAMD.route({
  9. templateUrl: 'module/login/login.html', controller: 'LoginCtrl', controllerUrl: 'module/login/js/login', languageUrl: "language/logdata"
  10. }))
  11. .when("/user", angularAMD.route({
  12. templateUrl: 'module/user/user.html', controller: 'UserCtrl', controllerUrl: 'module/user/js/user', languageUrl: "language/userdata"
  13. }))
  14. .when("/dealer", angularAMD.route({
  15. templateUrl: 'module/dealer/dealer.html', controller: 'DealerCtrl', controllerUrl: 'module/dealer/js/dealer', languageUrl: "language/dealerdata"
  16. }))
  17. .when("/question", angularAMD.route({
  18. templateUrl: 'module/question/question.html', controller: 'QuestionCtrl', controllerUrl: 'module/question/js/question', languageUrl: "language/questiondata"
  19. }))
  20. .when("/assessment", angularAMD.route({
  21. templateUrl: 'module/assessment/assessment.html', controller: 'AssessmentCtrl', controllerUrl: 'module/assessment/js/assessment', languageUrl: "language/assessmentdata"
  22. }))
  23. .when("/content", angularAMD.route({
  24. templateUrl: 'module/content/content.html', controller: 'ContentCtrl', controllerUrl: 'module/content/js/content', languageUrl: "language/contentdata"
  25. }))
  26. .when("/training", angularAMD.route({
  27. templateUrl: 'module/training/training.html', controller: 'TrainingCtrl', controllerUrl: 'module/training/js/training', languageUrl: "language/trainingdata"
  28. }))
  29. .when("/survey", angularAMD.route({
  30. templateUrl: 'module/survey/survey.html', controller: 'SurveyCtrl', controllerUrl: 'module/survey/js/survey', languageUrl: "language/surveydata"
  31. }))
  32. .when("/bulletin", angularAMD.route({
  33. templateUrl: 'module/bulletin/bulletin.html', controller: 'BulletinCtrl', controllerUrl: 'module/bulletin/js/bulletin', languageUrl: "language/bulletindata"
  34. }))
  35. .when("/redeem", angularAMD.route({
  36. templateUrl: 'module/redeem/redeem.html', controller: 'RedeemCtrl', controllerUrl: 'module/redeem/js/redeem', languageUrl: "language/redeemdata"
  37. }))
  38. .when("/user-registartion", angularAMD.route({
  39. templateUrl: 'module/report/user-registration/user-registration.html', controller: 'UserRegistrationCtrl', controllerUrl: 'module/report/user-registration/js/user-registration', languageUrl: "language/user-registration-data"
  40. }))
  41. .when("/user-report", angularAMD.route({
  42. templateUrl: 'module/report/user-report/user-report.html', controller: 'UserReportCtrl', controllerUrl: 'module/report/user-report/js/user-report', languageUrl: "language/user-report-data"
  43. }))
  44. .when("/content-report", angularAMD.route({
  45. templateUrl: 'module/report/content-report/content-report.html', controller: 'ContentReportCtrl', controllerUrl: 'module/report/content-report/js/content-report', languageUrl: "language/user-content-data"
  46. }))
  47. .when("/assessment-report", angularAMD.route({
  48. templateUrl: 'module/report/assessment-report/assessment-report.html', controller: 'AssessmentReportCtrl', controllerUrl: 'module/report/assessment-report/js/assessment-report', languageUrl: "language/user-assessment-data"
  49. }))
  50. .when("/sales-report", angularAMD.route({
  51. templateUrl: 'module/report/sales-report/sales-report.html', controller: 'SalesReportCtrl', controllerUrl: 'module/report/sales-report/js/sales-report', languageUrl: "language/user-sales-data"
  52. }))
  53. .when("/certification-report", angularAMD.route({
  54. templateUrl: 'module/report/certification-report/certification-report.html', controller: 'CertificationReportCtrl', controllerUrl: 'module/report/certification-report/js/certification-report', languageUrl: "language/user-certification-data"
  55. }))
  56. .when("/setsales-report", angularAMD.route({
  57. templateUrl: 'module/report/setsales-report/setsales-report.html', controller: 'SetsalesReportCtrl', controllerUrl: 'module/report/setsales-report/js/setsales-report', languageUrl: "language/user-setsales-data"
  58. }))
  59. .when("/redeem-report", angularAMD.route({
  60. templateUrl: 'module/report/redeem-report/redeem-report.html', controller: 'RedeemReportCtrl', controllerUrl: 'module/report/redeem-report/js/redeem-report', languageUrl: "language/redeem-report-data"
  61. }))
  62. .when("/attrition-report", angularAMD.route({
  63. templateUrl: 'module/report/attrition-report/attrition-report.html', controller: 'AttritionReportCtrl', controllerUrl: 'module/report/attrition-report/js/attrition-report', languageUrl: "language/attrition-data"
  64. }))
  65. .when("/customer-experience-report", angularAMD.route({
  66. templateUrl: 'module/report/customer-experience-report/customer-experience-report.html', controller: 'ExperienceReportCtrl', controllerUrl: 'module/report/customer-experience-report/js/customer-experience-report', languageUrl: "language/experience-data"
  67. }))
  68. .when("/current-login-report", angularAMD.route({
  69. templateUrl: 'module/report/current-login-report/current-login-report.html', controller: 'CurrentloginReportCtrl', controllerUrl: 'module/report/current-login-report/js/current-login-report', languageUrl: "language/user-current-login-report-data"
  70. }))
  71. .when("/bulletin-report", angularAMD.route({
  72. templateUrl: 'module/report/bulletin-report/bulletin-report.html', controller: 'BulletinReportCtrl', controllerUrl: 'module/report/bulletin-report/js/bulletin-report', languageUrl: "language/user-bulletin-report-data"
  73. }))
  74. .when("/enquiry-report", angularAMD.route({
  75. templateUrl: 'module/report/enquiry-report/enquiry-report.html', controller: 'EnquiryReportCtrl', controllerUrl: 'module/report/enquiry-report/js/enquiry-report', languageUrl: "language/user-enquiry-report-data"
  76. }))
  77. .when("/notification", angularAMD.route({
  78. templateUrl: 'module/report/notification/notification.html', controller: 'NotificationCtrl', controllerUrl: 'module/report/notification/js/notification', languageUrl: "language/notification"
  79. }))
  80. .when("/ilearning", angularAMD.route({
  81. templateUrl: 'module/ilearning/ilearning.html', controller: 'IlearningCtrl', controllerUrl: 'module/ilearning/js/ilearning', languageUrl: "language/ilearning"
  82. }))
  83. .when("/sales", angularAMD.route({
  84. templateUrl: 'module/import/sales/sales.html', controller: 'SalesCtrl', controllerUrl: 'module/import/sales/js/sales', languageUrl: "language/sales"
  85. }))
  86. .when("/dsesales", angularAMD.route({
  87. templateUrl: 'module/import/dsesales/dsesales.html', controller: 'DSESalesCtrl', controllerUrl: 'module/import/dsesales/js/dsesales', languageUrl: "language/dsesales"
  88. }))
  89. .otherwise({ redirectTo: "/login" });
  90. });
  91. app.run(function ($rootScope, $templateCache, $location, $route) {
  92. // alert($rootScope.is_logged)
  93. $rootScope.modalLogShown = false;
  94. $rootScope.cofirmWindow = false;
  95. $rootScope.selLanguage = "en_us";
  96. $rootScope.is_logged = true;
  97. $rootScope.sidemenuhigh = window.innerHeight - (180);
  98. $rootScope.logoutfn = function () {
  99. $rootScope.log = false;
  100. // console.log($rootScope.log)
  101. $rootScope.cofirmWindow = true;
  102. $rootScope.modalLogShown = true;
  103. $rootScope.message = "Are you sure you want to logout ?";
  104. }
  105. $rootScope.$on("cofirm", function () {
  106. $rootScope.cofirmWindow = false;
  107. $rootScope.modalLogShown = false;
  108. $rootScope.is_logged = false;
  109. // console.log($rootScope.log)
  110. $location.path("/login");
  111. })
  112. });
  113. app.directive('modalDialog', function ($rootScope) {
  114. return {
  115. templateUrl: "module/alert.html",
  116. restrict: 'E',
  117. transclude: true,
  118. replace: true,
  119. backdrop: 'static',
  120. scope: {
  121. show: '=',
  122. type: '=',
  123. },
  124. replace: true, // Replace with the template below
  125. transclude: true, // we want to insert custom content inside the directive
  126. link: function ($scope, element, attrs) {
  127. $('#' + attrs.id).css('display', 'block');
  128. $scope.dialogStyle = {};
  129. if (attrs.width)
  130. $scope.dialogStyle.width = attrs.width;
  131. if (attrs.height)
  132. $scope.dialogStyle.height = attrs.height;
  133. $scope.hideModal = function () {
  134. $scope.show = false;
  135. $scope.type = false;
  136. };
  137. $scope.okClickModal = function () {
  138. // console.log(attrs.id)
  139. $rootScope.$broadcast('confirmDelete');
  140. $scope.show = false;
  141. $scope.type = false;
  142. };
  143. }
  144. };
  145. });
  146. app.directive('modalPublishForm', function ($rootScope) {
  147. return {
  148. templateUrl: "module/publish_form.html",
  149. restrict: 'E',
  150. transclude: true,
  151. replace: true,
  152. backdrop: 'static',
  153. scope: {
  154. show: '=',
  155. type: '=',
  156. },
  157. replace: true, // Replace with the template below
  158. transclude: true, // we want to insert custom content inside the directive
  159. link: function ($scope, element, attrs) {
  160. $('#' + attrs.id).css('display', 'block');
  161. // console.log(attrs.id)
  162. $scope.dialogStyle = {};
  163. if (attrs.width)
  164. $scope.dialogStyle.width = attrs.width;
  165. if (attrs.height)
  166. $scope.dialogStyle.height = attrs.height;
  167. $scope.hideModal = function () {
  168. $scope.show = false;
  169. $scope.type = false;
  170. $rootScope.num = 1;
  171. // console.log($rootScope.num)
  172. };
  173. $scope.okModal = function () {
  174. // console.log("here")
  175. $rootScope.$broadcast('confirmPublish');
  176. $scope.show = false;
  177. $scope.type = false;
  178. };
  179. }
  180. };
  181. });
  182. app.directive('modalLogpopup', function ($rootScope) {
  183. return {
  184. templateUrl: "module/logout.html",
  185. restrict: 'E',
  186. transclude: true,
  187. replace: true,
  188. backdrop: 'static',
  189. scope: {
  190. show: '=',
  191. type: '=',
  192. },
  193. replace: true, // Replace with the template below
  194. transclude: true, // we want to insert custom content inside the directive
  195. link: function ($scope, element, attrs) {
  196. $('#' + attrs.id).css('display', 'block');
  197. $scope.dialogStyle = {};
  198. if (attrs.width) {
  199. $scope.dialogStyle.width = attrs.width;
  200. }
  201. if (attrs.height) {
  202. $scope.dialogStyle.height = attrs.height;
  203. }
  204. $scope.$watch(function (value) {
  205. $scope.title = $rootScope.popuptitle;
  206. });
  207. $scope.hideModal = function () {
  208. $scope.show = false;
  209. $scope.type = false;
  210. };
  211. $scope.okModal = function () {
  212. $rootScope.$broadcast('cofirm');
  213. $scope.show = false;
  214. $scope.type = false;
  215. };
  216. }
  217. };
  218. });
  219. app.directive('ngDatepickermin', function ($rootScope) {
  220. return {
  221. restrict: 'A',
  222. require: '?ngModel',
  223. scope: {
  224. },
  225. link: function ($scope, element, attrs, ngModel) {
  226. if (attrs.isblockdate == "true") {
  227. element.datepicker({
  228. dateFormat: 'yy-mm-dd',
  229. minDate: '01-01-1900',
  230. maxDate: '+3m',
  231. onSelect: function (date) {
  232. if (attrs.name == "dob") {
  233. $scope.$parent.formData.date_of_join = date;
  234. } else if (attrs.name == "start_date") {
  235. $scope.$parent.formData.publisheddate = date;
  236. } else if (attrs.name == "clsstartdate") {
  237. $scope.$parent.formData.startdate = date;
  238. }
  239. $scope.$parent.$apply();
  240. }
  241. });
  242. } else if (attrs.isblockdate == "false") {
  243. //console.log("Yes calender 2",attrs.isblockdate)
  244. element.datepicker({
  245. minDate: '01-01-16',
  246. dateFormat: 'dd-mm-yy',
  247. /*onSelect: function (date) {
  248. testcal=date;
  249. //vstartdate = String(date).split("-");
  250. datefor = date;
  251. //datefor = new Date("2016-7-20");
  252. //datefor = new Date(vstartdate[2],vstartdate[1]-1,vstartdate[0]);
  253. $scope.$parent.$apply();
  254. }*/
  255. onSelect: function (selected) {
  256. /*var date2 = $('#vechcal1').datepicker('getDate');
  257. date2.setDate(date2.getDate()+4);
  258. $("#vechcal2").datepicker("option","maxDate", date2)
  259. $("#vechcal2").datepicker("option","minDate", selected)*/
  260. $rootScope.startdate = selected;
  261. //$scope.vstdate = selected;
  262. //$scope.$parent.formData.enddates = selected;
  263. //$scope.$parent.$apply();
  264. //console.log(vstdate)
  265. }
  266. });
  267. }
  268. }
  269. }
  270. })
  271. app.directive('ngDatepickermax', function ($rootScope) {
  272. return {
  273. restrict: 'A',
  274. require: '?ngModel',
  275. scope: {
  276. },
  277. link: function ($scope, element, attrs, ngModel) {
  278. if (attrs.isblockdate == "true") {
  279. element.datepicker({
  280. dateFormat: 'yy-mm-dd',
  281. minDate: 0,
  282. maxDate: '+3m',
  283. onSelect: function (date) {
  284. if (attrs.name == "clspublishdate") {
  285. $scope.$parent.formData.publishdate = date;
  286. } else if (attrs.name == "clsenddate") {
  287. $scope.$parent.formData.enddate = date;
  288. } else if (attrs.name == "clsstartdate") {
  289. $scope.$parent.formData.start_date = date;
  290. } else if (attrs.name == "clsend_date") {
  291. $scope.$parent.formData.end_date = date;
  292. }
  293. $scope.$parent.$apply();
  294. }
  295. });
  296. }
  297. else if (attrs.isblockdate == "false") {
  298. //console.log("Yes calender 2",attrs.isblockdate)
  299. element.datepicker({
  300. dateFormat: 'dd-mm-yy',
  301. /*onSelect: function (date) {
  302. console.log(datefor)
  303. $scope.$parent.$apply();
  304. }
  305. */
  306. onSelect: function (selected) {
  307. /*var date1 = $('#vechcal2').datepicker('getDate');
  308. date1.setDate(date1.getDate()-5);
  309. $("#vechcal1").datepicker({"minDate": date1});*/
  310. $scope.$parent.vendtdate = selected;
  311. //$scope.$parent.formData.publishdates = selected;
  312. //console.log($scope.$parent.vendtdate);
  313. $rootScope.enddate = selected;
  314. //$scope.$parent.$apply();
  315. //$rootScope.vendtdate = selected;
  316. }
  317. });
  318. }
  319. }
  320. }
  321. })
  322. /////////////// Report datepicker /////////////
  323. app.directive('ngReportpickermin', function ($rootScope) {
  324. return {
  325. restrict: 'A',
  326. require: '?ngModel',
  327. scope: {
  328. },
  329. link: function ($scope, element, attrs, ngModel) {
  330. if (attrs.isblockdate == "true") {
  331. element.datepicker({
  332. dateFormat: 'yy-mm-dd',
  333. // minDate: '0',
  334. maxDate: '0',
  335. onSelect: function (date) {
  336. // console.log(date)
  337. if (attrs.name == "fromdate") {
  338. $scope.$parent.formData.from_date = date;
  339. if((new Date($scope.$parent.formData.from_date).getTime() > new Date($scope.$parent.formData.to_date).getTime())){
  340. $scope.$parent.formData.to_date = '';
  341. }
  342. var datearr = date.split('-');
  343. // console.log(datearr, (Number(datearr[0]) + 1) + "-" + datearr[1] + "-" + datearr[2])
  344. $("#todate").datepicker("option", "maxDate", 0);
  345. $('#todate').datepicker("option", 'minDate', datearr[0] + "-" + datearr[1] + "-" + (Number(datearr[2]) + 1));
  346. // $scope.$parent.formData.to_date = ''
  347. } else if (attrs.name == "todate") {
  348. // $("#todate").datepicker("option", "maxDate", (Number(datearr[0]) + 1) + "-" + datearr[1] + "-" + datearr[2]);
  349. $scope.$parent.formData.to_date = date;
  350. if((new Date($scope.$parent.formData.from_date).getTime() > new Date($scope.$parent.formData.to_date).getTime())){
  351. $scope.$parent.formData.from_date = '';
  352. }
  353. }
  354. $scope.$parent.$apply();
  355. }
  356. });
  357. } else if (attrs.isblockdate == "false") {
  358. //console.log("Yes calender 2",attrs.isblockdate)
  359. element.datepicker({
  360. minDate: '01-01-16',
  361. dateFormat: 'dd-mm-yy',
  362. /*onSelect: function (date) {
  363. testcal=date;
  364. //vstartdate = String(date).split("-");
  365. datefor = date;
  366. //datefor = new Date("2016-7-20");
  367. //datefor = new Date(vstartdate[2],vstartdate[1]-1,vstartdate[0]);
  368. $scope.$parent.$apply();
  369. }*/
  370. onSelect: function (selected) {
  371. /*var date2 = $('#vechcal1').datepicker('getDate');
  372. date2.setDate(date2.getDate()+4);
  373. $("#vechcal2").datepicker("option","maxDate", date2)
  374. $("#vechcal2").datepicker("option","minDate", selected)*/
  375. $rootScope.startdate = selected;
  376. //$scope.vstdate = selected;
  377. //$scope.$parent.formData.enddates = selected;
  378. //$scope.$parent.$apply();
  379. //console.log(vstdate)
  380. }
  381. });
  382. }
  383. }
  384. }
  385. })
  386. app.directive('ngReportpickermax', function ($rootScope) {
  387. return {
  388. restrict: 'A',
  389. require: '?ngModel',
  390. scope: {
  391. },
  392. link: function ($scope, element, attrs, ngModel) {
  393. if (attrs.isblockdate == "true") {
  394. element.datepicker({
  395. dateFormat: 'yy-mm-dd',
  396. minDate: 0,
  397. maxDate: '+3m',
  398. onSelect: function (date) {
  399. if (attrs.name == "clspublishdate") {
  400. $scope.$parent.formData.publishdate = date;
  401. } else if (attrs.name == "clsenddate") {
  402. $scope.$parent.formData.enddate = date;
  403. } else if (attrs.name == "clsstartdate") {
  404. $scope.$parent.formData.start_date = date;
  405. } else if (attrs.name == "clsend_date") {
  406. $scope.$parent.formData.end_date = date;
  407. }
  408. $scope.$parent.$apply();
  409. }
  410. });
  411. }
  412. else if (attrs.isblockdate == "false") {
  413. //console.log("Yes calender 2",attrs.isblockdate)
  414. element.datepicker({
  415. dateFormat: 'dd-mm-yy',
  416. /*onSelect: function (date) {
  417. console.log(datefor)
  418. $scope.$parent.$apply();
  419. }
  420. */
  421. onSelect: function (selected) {
  422. /*var date1 = $('#vechcal2').datepicker('getDate');
  423. date1.setDate(date1.getDate()-5);
  424. $("#vechcal1").datepicker({"minDate": date1});*/
  425. $scope.$parent.vendtdate = selected;
  426. //$scope.$parent.formData.publishdates = selected;
  427. //console.log($scope.$parent.vendtdate);
  428. $rootScope.enddate = selected;
  429. //$scope.$parent.$apply();
  430. //$rootScope.vendtdate = selected;
  431. }
  432. });
  433. }
  434. }
  435. }
  436. })
  437. app.directive('ngMonthPick', function ($rootScope) {
  438. return {
  439. restrict: 'A',
  440. require: '?ngModel',
  441. scope: {
  442. date: "=",
  443. onSubmit: "&onSelect"
  444. },
  445. link: function (scope, element, attrs, ngModel) {
  446. element.datepicker({
  447. changeMonth: true,
  448. changeYear: true,
  449. showButtonPanel: true,
  450. viewMode: "months",
  451. minViewMode: "months",
  452. pickTime: false,
  453. dateFormat: 'MM yy',
  454. maxDate:0,
  455. onChangeMonthYear:function(){
  456. $('.ui-datepicker-calendar').css({
  457. display: "none"
  458. })
  459. },
  460. onClose: function(dateText, inst) {
  461. $('.ui-datepicker-calendar').css({
  462. display: "none"
  463. })
  464. function isDonePressed(){
  465. return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
  466. }
  467. if (isDonePressed()){
  468. var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
  469. var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
  470. $(this).datepicker('setDate', new Date(year, month, 1)).trigger('change');
  471. }
  472. },
  473. beforeShow: function(input, ele) {
  474. var rect = input.getBoundingClientRect();
  475. setTimeout(function () {
  476. ele.dpDiv.css({ top: rect.top + 40, left: rect.left + 0 });
  477. }, 0);
  478. $('.ui-datepicker-calendar').css({
  479. display: "none"
  480. })
  481. if ((datestr = $(this).val()).length > 0) {
  482. year = datestr.substring(datestr.length - 4, datestr.length);
  483. month = jQuery.inArray(datestr.substring(0, datestr.length - 5), $(this).datepicker('option', 'monthNames'));
  484. $(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
  485. $(this).datepicker('setDate', new Date(year, month, 1));
  486. }
  487. var other = this.id == "from" ? "#to" : "#from";
  488. var option = this.id == "from" ? "maxDate" : "minDate";
  489. if ((selectedDate = $(other).val()).length > 0) {
  490. year = selectedDate.substring(selectedDate.length - 4, selectedDate.length);
  491. month = jQuery.inArray(selectedDate.substring(0, selectedDate.length - 5), $(this).datepicker('option', 'monthNames'));
  492. $(this).datepicker("option", option, new Date(year, month, 1));
  493. }
  494. }
  495. })
  496. .on("click",function(e){
  497. $('.ui-datepicker-calendar').css({
  498. display: "none"
  499. })
  500. })
  501. $('.custom_month').focusin(function(){
  502. $('.ui-datepicker-calendar').css("display","none");
  503. });
  504. }
  505. }
  506. })
  507. app.directive('monthPick', function ($rootScope) {
  508. return {
  509. restrict: 'A',
  510. require: '?ngModel',
  511. scope: {
  512. },
  513. link: function (scope, element, attrs, ngModel) {
  514. // console.log(element)
  515. element.datepicker({
  516. changeMonth: true,
  517. changeYear: true,
  518. showButtonPanel: true,
  519. dateFormat: 'MM yy',
  520. maxDate:0,
  521. onClose: function(dateText, inst) {
  522. // console.log("inst-->",inst)
  523. $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
  524. }
  525. })
  526. }
  527. }
  528. });
  529. // app.directive('datetimez', function ($rootScope) {
  530. // return {
  531. // restrict: 'A',
  532. // require: 'ngModel',
  533. // link: function (scope, element, attrs, ngModelCtrl) {
  534. // element.datetimepicker({
  535. // format: "MM-yyyy",
  536. // viewMode: "months",
  537. // minViewMode: "months",
  538. // pickTime: false,
  539. // }).on('changeDate', function (e) {
  540. // $('.bootstrap-datetimepicker-widget').css({
  541. // display: "none"
  542. // })
  543. // console.log(e, e.date.getMonth(), attrs)
  544. // ngModelCtrl.$setViewValue(e.date);
  545. // scope.$apply();
  546. // });
  547. // }
  548. // };
  549. // });
  550. app.service("AppData", function ($rootScope, $http, $httpParamSerializerJQLike) {
  551. $http.defaults.transformRequest.unshift($httpParamSerializerJQLike);
  552. $rootScope.loadingCont = false;
  553. //EDIT 20 Sept
  554. var url_str =window.location.href;
  555. if(url_str.indexOf('.cygnusa.in') !== -1)
  556. {
  557. var url_arr=url_str.split("cygnusa.in/");
  558. $rootScope.static_url = url_arr[0]+"cygnusa.in/";
  559. }else{
  560. // $rootScope.static_url = "https://hyper-m-dev.cygnusa.in/";
  561. $rootScope.static_url = "https://hyper-m.cygnusa.in/";
  562. }
  563. var data = {};
  564. data.sendData = sendData;
  565. data.checkArrayValue = checkArrayValue;
  566. function rand() {
  567. return (new Date()).getTime();
  568. }
  569. function checkArrayValue(arr, type, value) {
  570. var obj = {};
  571. obj.cont = false;
  572. for (var id = 0; id < arr.length; id++) {
  573. if (arr[id][type] == value) {
  574. obj.cont = true;
  575. obj.mid = id;
  576. break;
  577. }
  578. }
  579. return obj;
  580. }
  581. function sendData(urllink, data, returnFun) {
  582. // console.log(urllink)
  583. $rootScope.loadingCont = true;
  584. var req = {
  585. method: 'POST',
  586. url: $rootScope.static_url + urllink + rand(),
  587. // url: urllink + rand(),
  588. headers: { "Connection": "Keep-Alive", 'Content-Type': 'application/x-www-form-urlencoded' },
  589. data: data
  590. }
  591. $http(req).then(function (res) {
  592. $rootScope.loadingCont = false
  593. if (returnFun != undefined) {
  594. returnFun(res.data);
  595. }
  596. }, function () {
  597. });
  598. }
  599. return data;
  600. })
  601. app.directive('setHeight', function ($window) {
  602. return {
  603. link: function (scope, element, attrs) {
  604. element.css('height', $window.innerHeight - 105 + 'px');
  605. //element.height($window.innerHeight/3);
  606. }
  607. }
  608. })
  609. app.directive('uibPagination', function ($rootScope) {
  610. return {
  611. templateUrl: "module/pagination.html",
  612. restrict: 'E',
  613. transclude: true,
  614. replace: true,
  615. backdrop: 'static',
  616. scope: {
  617. show: '=',
  618. type: '=',
  619. },
  620. replace: true, // Replace with the template below
  621. transclude: true, // we want to insert custom content inside the directive
  622. link: function ($scope, element, attrs) {
  623. // console.log(attrs)
  624. $('#' + attrs.id).css('display', 'block');
  625. $scope.dialogStyle = {};
  626. if (attrs.width) {
  627. $scope.dialogStyle.width = attrs.width;
  628. }
  629. if (attrs.height) {
  630. $scope.dialogStyle.height = attrs.height;
  631. }
  632. $scope.$watch(function (value) {
  633. });
  634. $scope.hideModal = function () {
  635. $scope.show = false;
  636. $scope.type = false;
  637. };
  638. $scope.okModal = function () {
  639. $rootScope.$broadcast('cofirm');
  640. $scope.show = false;
  641. $scope.type = false;
  642. };
  643. }
  644. };
  645. });
  646. app.directive('multipleAutocomplete', [
  647. '$filter',
  648. '$http',
  649. function ($filter, $http) {
  650. return {
  651. restrict: 'EA',
  652. scope: {
  653. suggestionsArr: '=?',
  654. modelArr: '=ngModel',
  655. apiUrl: '@',
  656. beforeSelectItem: '=?',
  657. afterSelectItem: '=?',
  658. beforeRemoveItem: '=?',
  659. afterRemoveItem: '=?'
  660. },
  661. templateUrl: 'multiple-autocomplete-tpl.html',
  662. link: function (scope, element, attr) {
  663. scope.objectProperty = attr.objectProperty;
  664. scope.selectedItemIndex = 0;
  665. scope.name = attr.name;
  666. scope.isRequired = attr.required;
  667. scope.errMsgRequired = attr.errMsgRequired;
  668. scope.isHover = false;
  669. scope.isFocused = false;
  670. var getSuggestionsList = function () {
  671. var url = scope.apiUrl;
  672. $http({
  673. method: 'GET',
  674. url: url
  675. }).then(function (response) {
  676. scope.suggestionsArr = response.data;
  677. }, function (response) {
  678. });
  679. };
  680. if (scope.suggestionsArr == null || scope.suggestionsArr == "") {
  681. if (scope.apiUrl != null && scope.apiUrl != "")
  682. getSuggestionsList();
  683. else {
  684. }
  685. }
  686. // console.log("scope.modelArr ", scope.modelArr)
  687. if (scope.modelArr == null || scope.modelArr == "" || scope.modelArr == undefined) {
  688. scope.modelArr = [];
  689. }
  690. // console.log(scope.modelArr)
  691. scope.onFocus = function () {
  692. scope.isFocused = true
  693. };
  694. scope.onMouseEnter = function () {
  695. scope.isHover = true
  696. };
  697. scope.onMouseLeave = function () {
  698. scope.isHover = false;
  699. };
  700. scope.onBlur = function () {
  701. scope.isFocused = false;
  702. };
  703. scope.onChange = function () {
  704. scope.selectedItemIndex = 0;
  705. };
  706. scope.keyParser = function ($event) {
  707. var keys = {
  708. 38: 'up',
  709. 40: 'down',
  710. 8: 'backspace',
  711. 13: 'enter',
  712. 9: 'tab',
  713. 27: 'esc'
  714. };
  715. var key = keys[$event.keyCode];
  716. if (key == 'backspace' && scope.inputValue == "") {
  717. if (scope.modelArr.length != 0) {
  718. scope.removeAddedValues(scope.modelArr[scope.modelArr.length - 1]);
  719. //scope.modelArr.pop();
  720. }
  721. }
  722. else if (key == 'down') {
  723. var filteredSuggestionArr = $filter('filter')(scope.suggestionsArr, scope.inputValue);
  724. filteredSuggestionArr = $filter('filter')(filteredSuggestionArr, scope.alreadyAddedValues);
  725. if (scope.selectedItemIndex < filteredSuggestionArr.length - 1)
  726. scope.selectedItemIndex++;
  727. }
  728. else if (key == 'up' && scope.selectedItemIndex > 0) {
  729. scope.selectedItemIndex--;
  730. }
  731. else if (key == 'esc') {
  732. scope.isHover = false;
  733. scope.isFocused = false;
  734. }
  735. else if (key == 'enter') {
  736. var filteredSuggestionArr = $filter('filter')(scope.suggestionsArr, scope.inputValue);
  737. filteredSuggestionArr = $filter('filter')(filteredSuggestionArr, scope.alreadyAddedValues);
  738. if (scope.selectedItemIndex < filteredSuggestionArr.length)
  739. scope.onSuggestedItemsClick(filteredSuggestionArr[scope.selectedItemIndex]);
  740. }
  741. };
  742. scope.onSuggestedItemsClick = function (selectedValue) {
  743. if (scope.modelArr == null || scope.modelArr == "" || scope.modelArr == undefined) {
  744. scope.modelArr = [];
  745. }
  746. if (scope.beforeSelectItem && typeof (scope.beforeSelectItem) == 'function')
  747. scope.beforeSelectItem(selectedValue);
  748. scope.modelArr.push(selectedValue);
  749. // console.log(scope.modelArr)
  750. if (scope.afterSelectItem && typeof (scope.afterSelectItem) == 'function')
  751. scope.afterSelectItem(selectedValue);
  752. scope.inputValue = "";
  753. };
  754. var isDuplicate = function (arr, item) {
  755. var duplicate = false;
  756. if (arr == null || arr == "")
  757. return duplicate;
  758. for (var i = 0; i < arr.length; i++) {
  759. duplicate = angular.equals(arr[i], item);
  760. if (duplicate)
  761. break;
  762. }
  763. return duplicate;
  764. };
  765. scope.alreadyAddedValues = function (item) {
  766. var isAdded = true;
  767. isAdded = !isDuplicate(scope.modelArr, item);
  768. //if(scope.modelArr != null && scope.modelArr != ""){
  769. // isAdded = scope.modelArr.indexOf(item) == -1;
  770. // console.log("****************************");
  771. // console.log(item);
  772. // console.log(scope.modelArr);
  773. // console.log(isAdded);
  774. //}
  775. return isAdded;
  776. };
  777. scope.removeAddedValues = function (item) {
  778. if (scope.modelArr != null && scope.modelArr != "") {
  779. var itemIndex = scope.modelArr.indexOf(item);
  780. if (itemIndex != -1) {
  781. if (scope.beforeRemoveItem && typeof (scope.beforeRemoveItem) == 'function')
  782. scope.beforeRemoveItem(item);
  783. scope.modelArr.splice(itemIndex, 1);
  784. if (scope.afterRemoveItem && typeof (scope.afterRemoveItem) == 'function')
  785. scope.afterRemoveItem(item);
  786. }
  787. }
  788. };
  789. scope.mouseEnterOnItem = function (index) {
  790. scope.selectedItemIndex = index;
  791. };
  792. }
  793. };
  794. }
  795. ]);
  796. return angularAMD.bootstrap(app);
  797. });