notification.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. define(['app'], function (app) {
  2. app.directive('uploadImgFile', function ($rootScope) {
  3. return {
  4. restrict: 'A',
  5. scope: true,
  6. link: function (scope, element, attr) {
  7. element.on('change', function (event) {
  8. var files = event.target.files;
  9. if ($rootScope.imageFormat.indexOf(files[0].type) != -1) {
  10. $rootScope.prodimage = files[0];
  11. }else {
  12. $rootScope.$apply(function () {
  13. $rootScope.modalShown = true;
  14. $rootScope.message = "Please select Image format only"
  15. angular.element("input[type='file']").val(null);
  16. })
  17. }
  18. })
  19. }
  20. }
  21. })
  22. function readURL(input) {
  23. var num = current_imageObject.attr('data-id');
  24. if (input.files && input.files[0]) {
  25. var reader = new FileReader();
  26. reader.onload = function (e) {
  27. $('#store_image_' + num)
  28. .attr('src', e.target.result)
  29. .width(119)
  30. .height(112);
  31. }
  32. reader.readAsDataURL(input.files[0]);
  33. }
  34. }
  35. app.directive('thumbUploadFile', function ($rootScope) {
  36. return {
  37. restrict: 'A',
  38. scope: true,
  39. link: function (scope, element, attr) {
  40. element.on('change', function (event) {
  41. var files = event.target.files;
  42. if ($rootScope.imageFormat.indexOf(files[0].type) != -1) {
  43. $rootScope.uploadthumbimage.push(files[0]);
  44. }else {
  45. $rootScope.$apply(function () {
  46. $rootScope.modalShown = true;
  47. $rootScope.message = "Please select image format only"
  48. angular.element("input[type='file']").val(null);
  49. })
  50. }
  51. })
  52. }
  53. }
  54. })
  55. app.directive('uploadingFileContent', function ($rootScope) {
  56. return {
  57. restrict: 'A',
  58. scope: true,
  59. link: function (scope, element, attr) {
  60. element.on('change', function (event) {
  61. var files = event.target.files;
  62. if ($rootScope.filetype_format == 1) {
  63. }if ($rootScope.fileFormat.indexOf(files[0].type) != -1) {
  64. $rootScope.uploadfile.push(files[0]);
  65. }else {
  66. $rootScope.$apply(function () {
  67. $rootScope.modalShown = true;
  68. $rootScope.message = "Please select Pdf/Video/Doc format only"
  69. angular.element("input[type='file']").val(null);
  70. })
  71. }
  72. })
  73. }
  74. }
  75. })
  76. app.service("UploadProdService", function ($http, $rootScope, $timeout) {
  77. var service = {}
  78. service.upload = upload;
  79. var returnfun;
  80. function upload(formData, scope) {
  81. //console.log("File : ",formData);
  82. returnfun = scope
  83. $rootScope.loadingCont = true;
  84. var xhr;
  85. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  86. xhr = new XMLHttpRequest();
  87. }else {// code for IE6, IE5
  88. xhr = new ActiveXObject("Microsoft.XMLHTTP");
  89. }
  90. //this._scope['formLoad'] = false;
  91. xhr.upload.addEventListener("progress", uploadProgress, false)
  92. xhr.addEventListener("load", function (evt) {
  93. returnfun(evt.target.responseText);
  94. }, false)
  95. xhr.addEventListener("error", uploadFailed, false)
  96. xhr.addEventListener("abort", uploadCanceled, false)
  97. xhr.open("POST", "../services/products.php")
  98. $rootScope.progressVisible = true
  99. xhr.send(formData);
  100. }
  101. function uploadProgress(evt) {
  102. $rootScope.$apply(function () {
  103. if (evt.lengthComputable) {
  104. } else {
  105. }
  106. })
  107. }
  108. function uploadComplete(evt) {
  109. }
  110. function uploadFailed(evt) {
  111. $rootScope.$apply(function () {
  112. $rootScope.loadingCont = false;
  113. })
  114. }
  115. function uploadCanceled(evt) {
  116. $rootScope.$apply(function () {
  117. $rootScope.loadingCont = false;
  118. })
  119. }
  120. return service;
  121. })
  122. app.controller('NotificationCtrl', function ($scope, $rootScope, AppData, $location, UploadProdService) {
  123. //Every module Set Same Variable//
  124. $rootScope.menucont = true;
  125. $rootScope.pageLoadComp = false;
  126. $scope.formLoad = false;
  127. $scope.listFound = false;
  128. $scope.pageData = notificationData[$rootScope.selLanguage];
  129. $scope.formAction = "Add";
  130. $rootScope.sideselect = $scope.pageData.sidemenu[0];
  131. $scope.itemdetail = [];
  132. $scope.selectedIndex = null;
  133. $rootScope.cofirmWindow = false;
  134. $scope.submenu = $scope.pageData.sidemenu;
  135. $scope.tblheading = $rootScope.sideselect.headingText;
  136. $scope.url = "../senddata/log/";
  137. $scope.pageurl = "../senddata/notification/";
  138. $scope.commonurl = "../senddata/common/";
  139. $scope.cat_error = '';
  140. $scope.topic_error = '';
  141. //filter data
  142. $scope.common_filter = [];
  143. $scope.zonearr = [];
  144. $scope.search_box = true;
  145. $rootScope.modalShown = false;
  146. $rootScope.cofirmWindow = false;
  147. //pagination
  148. $scope.viewby = '10';
  149. $scope.currentPage = 1;
  150. $scope.pageSize = 10;
  151. $scope.maxSize = 5;
  152. $scope.itemsPerPage = $scope.viewby;
  153. $scope.maxSize = 5;
  154. $scope.choice = {};
  155. $scope.choice.filelang = '';
  156. //Check Session//
  157. $scope.formData = {}
  158. $rootScope.formData = {}
  159. $scope.formData.roleList = [];
  160. $rootScope.formData.roleList = [];
  161. $scope.formData.ismenuload = "Yes";
  162. if ($rootScope.items == undefined || $rootScope.items == null) {
  163. $scope.formData.ismenuload = "No";
  164. }
  165. $scope.formData.funName = "checksession";
  166. $scope.formData.lang = $rootScope.selLanguage;
  167. // $scope.formData.start = 0;
  168. // $scope.formData.limit = 2;
  169. AppData.sendData($scope.url, $scope.formData, function (res) {
  170. if (res.cont) {
  171. if ($rootScope.items == undefined || $rootScope.items == null) {
  172. $rootScope.items = res.item.control;
  173. }
  174. for (var i = 0; i < $rootScope.items.length; i++) {
  175. if ($location.path() == $rootScope.items[i].modulepath) {
  176. $rootScope.modulename = $rootScope.items[i].modulename;
  177. $scope.usercontrol = String($rootScope.items[i].permission).split("|");
  178. }
  179. }
  180. $scope.listFound = true;
  181. $scope.statusobj = res.item.status;
  182. $rootScope.username = res.item.username;
  183. $scope.notificationList = function () {
  184. $scope.formData.pn = $scope.currentPage;
  185. $scope.formData.nr = $scope.itemsPerPage;
  186. $scope.searchvalue = ($scope.formData.mymodel != '') ? $scope.formData.mymodel : "";
  187. $scope.formData.funName = "notificationlist";
  188. $scope.formData.key = $scope.searchvalue;
  189. AppData.sendData($scope.pageurl, $scope.formData, function (res) {
  190. console.log(res);
  191. if (res.cont) {
  192. if (res.item != undefined) {
  193. $scope.notificationListdata = res.item.notification;
  194. console.log($scope.notificationListdata);
  195. if ($rootScope.sideselect.id != 2) {
  196. $scope.totalItems = res.item.total_records;
  197. }
  198. }
  199. } else {
  200. $scope.listFound = false;
  201. }
  202. })
  203. }
  204. $scope.notificationList();
  205. $scope.setPage = function (pageNo) {
  206. $scope.currentPage = pageNo;
  207. };
  208. $scope.pageChanged = function () {
  209. $scope.notificationList();
  210. };
  211. $scope.setItemsPerPage = function (num) {
  212. $scope.itemsPerPage = num;
  213. $scope.currentPage = 1; //reset to first page
  214. $scope.notificationList();
  215. }
  216. $scope.filterData = function () {
  217. $scope.notificationList();
  218. }
  219. } else {
  220. $location.path("/login");
  221. }
  222. })
  223. $scope.getRole = function () {
  224. var obj = {};
  225. // obj.funName = "role";
  226. obj.funName = "contentrole";
  227. obj.lang = $rootScope.selLanguage;
  228. obj.type = "dse"
  229. AppData.sendData($scope.commonurl, obj, function (res) {
  230. if (res.cont) {
  231. if (res.item != undefined) {
  232. $scope.role = res.item;
  233. }
  234. }
  235. })
  236. }
  237. $scope.addFun = function () {
  238. //$scope.choices = [{ "filelang": "1" }];
  239. //$scope.call($scope.choices)
  240. $scope.formLoad = true;
  241. $scope.listFound = false;
  242. $scope.formAction = "Add";
  243. $scope.is_edit_region = false;
  244. $scope.is_edit_dealer = false;
  245. //$scope.title = $rootScope.sideselect.title[0];
  246. $scope.formData = {};
  247. $scope.zoneList = [];
  248. //$rootScope.uploadfile = []
  249. //$rootScope.uploadthumbimage = [];
  250. $scope.formData.roleList = [];
  251. $rootScope.formData.roleList = [];
  252. $scope.formLoad = true;
  253. $scope.formData.funName = "addnotification";
  254. $scope.formTitle = "ADD NOTIFICATION";
  255. //angular.element("input[type='file']").val(null);
  256. //$scope.getLanguage();
  257. $scope.getRole();
  258. //$scope.getZone();
  259. }
  260. $rootScope.notifyChange = function () {
  261. if ($rootScope.formData.notification) {
  262. $rootScope.roleVisible = true;
  263. $rootScope.roleGroup = $scope.formData.roleList;
  264. if ($rootScope.roleGroup.length > 0) {
  265. angular.forEach($rootScope.roleGroup, function (element) {
  266. $rootScope.formData.roleList[element.id] = true;
  267. });
  268. }
  269. } else {
  270. $rootScope.roleVisible = false;
  271. }
  272. }
  273. $scope.deleterow = function (id) {
  274. $scope.formData.id = id;
  275. $scope.deleteFun();
  276. }
  277. $scope.editFun = function () {
  278. $scope.filerequired = false;
  279. $scope.thmbrequired = false;
  280. $scope.formAction = "Edit";
  281. $scope.is_edit_region = true;
  282. $scope.is_edit_dealer = true;
  283. //$(".clsbuttoncont .clsbutton").addClass("disable_btn");
  284. $scope.formLoad = true;
  285. $scope.listFound = false;
  286. //angular.element("input[type='file']").val(null);
  287. if ($scope.selectedIndex != null) {
  288. if ($rootScope.sideselect.id == 1) {
  289. $scope.formTitle = "EDIT TOPIC";
  290. $scope.categoryList();
  291. $scope.image_url = $scope.formData.image_url;
  292. } else if ($rootScope.sideselect.id == 2) {
  293. $scope.formTitle = "EDIT CONTENT";
  294. $scope.getLanguage();
  295. $scope.getRole();
  296. $scope.getZone();
  297. $rootScope.uploadfile = [];
  298. $rootScope.uploadthumbimage = [];
  299. $scope.zoneList = [];
  300. $scope.formData.zoneList = {};
  301. $scope.formData.roleList = $scope.formData.filter_role_name;
  302. //console.log($scope.formData.roleList, "$scope.formData.roleList ", $scope.formData.filter_role_name)
  303. // angular.forEach($scope.formData.file, function (element, i) {
  304. // $scope.filepath_url = element.filepath_url;
  305. // $scope.file_show = i;
  306. // //$scope.call(element.language_id)
  307. // });
  308. // $scope.choices = $scope.formData.file;
  309. }
  310. } else {
  311. $rootScope.modalShown = true;
  312. $rootScope.message = $scope.pageData.errorMsg[0];
  313. }
  314. }
  315. $scope.editrow = function (obj, i) {
  316. //console.log(obj);
  317. $scope.formData.assettopicid = obj.assettopicid;
  318. $scope.notificationList();
  319. $scope.formData = obj;
  320. //console.log($scope.formData.filetypeid)
  321. //$scope.formData.catename = obj.catename;
  322. //$scope.formData.filetypeid = obj.filetypeid;
  323. $scope.selectedIndex = i;
  324. $scope.search_box = false;
  325. $scope.listFound = false;
  326. $scope.formLoad = true;
  327. $scope.formAction = "Edit";
  328. //angular.element("input[type='file']").val(null);
  329. //$rootScope.prodimage = '';
  330. $scope.editFun();
  331. }
  332. $scope.deleteFun = function () {
  333. $scope.formData.funName = "deletenotification";
  334. $scope.formData.lang = $rootScope.selLanguage;
  335. AppData.sendData($scope.pageurl, $scope.formData, function (res) {
  336. if (res.cont) {
  337. var index = $scope.notificationListdata.indexOf($scope.formData.id);
  338. if (index == -1) {
  339. $scope.notificationListdata.splice(index, 1);
  340. }
  341. }
  342. });
  343. }
  344. $scope.listClick = function (obj) {
  345. $scope.searchtext = '';
  346. $scope.formData = {}
  347. $scope.currentPage = 1;
  348. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  349. $scope.formLoad = false;
  350. $rootScope.sideselect = obj;
  351. $scope.selectedIndex = null;
  352. $rootScope.sideselect.name = obj.name;
  353. $scope.notificationList();
  354. }
  355. $scope.clearErrorMsg = function () {
  356. $scope.title_error = '';
  357. $scope.description_error = '';
  358. }
  359. $scope.closeForm = function () {
  360. $scope.formLoad = false;
  361. $scope.formData = {};
  362. $scope.selectedIndex = null;
  363. $scope.search_box = true;
  364. $scope.listFound = true;
  365. $scope.clearErrorMsg();
  366. }
  367. $scope.fieldValidation = function () {
  368. $scope.title_error = ($scope.formData.notificationtitle == undefined || $scope.formData.notificationtitle == '') ? $scope.pageData.errorMsg[0] : '';
  369. $scope.description_error = ($scope.formData.notificationtext == undefined || $scope.formData.notificationtext == '') ? $scope.pageData.errorMsg[1] : '';
  370. return ($scope.title_error == '' && $scope.description_error == '') ? true : false;
  371. }
  372. ///////// User Submit //////////////
  373. $scope.notificationSubmit = function(){
  374. $scope.clearErrorMsg();
  375. //console.log($scope.fieldValidation());
  376. if($scope.fieldValidation()){
  377. if ($scope.formData.roleList.length != 0) {
  378. var rolearr = [];
  379. for (var id = 0; id < $scope.formData.roleList.length; id++) {
  380. rolearr.push($scope.formData.roleList[id].id)
  381. }
  382. $scope.formData.filter_role = rolearr.toString();
  383. }
  384. AppData.sendData($scope.pageurl,$scope.formData,function(res){
  385. if(res.cont){
  386. $rootScope.modalShown =true;
  387. $rootScope.message=(res.mess);
  388. $scope.notificationList();
  389. $scope.selectedIndex = null;
  390. $scope.formLoad = false;
  391. $scope.listFound = true;
  392. }else{
  393. $rootScope.modalShown =true;
  394. $rootScope.message=(res.mess);
  395. }
  396. })
  397. }
  398. }
  399. });
  400. });