content.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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. }
  12. else {
  13. $rootScope.$apply(function () {
  14. $rootScope.modalShown = true;
  15. $rootScope.message = "Please select Image format only"
  16. angular.element("input[type='file']").val(null);
  17. })
  18. }
  19. })
  20. }
  21. }
  22. }
  23. )
  24. function readURL(input) {
  25. var num = current_imageObject.attr('data-id');
  26. if (input.files && input.files[0]) {
  27. var reader = new FileReader();
  28. reader.onload = function (e) {
  29. $('#store_image_' + num)
  30. .attr('src', e.target.result)
  31. .width(119)
  32. .height(112);
  33. }
  34. reader.readAsDataURL(input.files[0]);
  35. }
  36. }
  37. app.directive('thumbUploadFile', function ($rootScope) {
  38. return {
  39. restrict: 'A',
  40. scope: true,
  41. link: function (scope, element, attr) {
  42. element.on('change', function (event) {
  43. var files = event.target.files;
  44. if ($rootScope.imageFormat.indexOf(files[0].type) != -1) {
  45. $rootScope.uploadthumbimage.push(files[0]);
  46. }
  47. else {
  48. $rootScope.$apply(function () {
  49. $rootScope.modalShown = true;
  50. $rootScope.message = "Please select image format only"
  51. angular.element("input[type='file']").val(null);
  52. })
  53. }
  54. })
  55. }
  56. }
  57. }
  58. )
  59. app.directive('uploadingFileContent', function ($rootScope) {
  60. return {
  61. restrict: 'A',
  62. scope: true,
  63. link: function (scope, element, attr) {
  64. element.on('change', function (event) {
  65. var files = event.target.files;
  66. if ($rootScope.filetype_format == 1) {
  67. }
  68. if ($rootScope.fileFormat.indexOf(files[0].type) != -1) {
  69. $rootScope.uploadfile.push(files[0]);
  70. }
  71. else {
  72. $rootScope.$apply(function () {
  73. $rootScope.modalShown = true;
  74. $rootScope.message = "Please select Pdf/Video/Doc format only"
  75. angular.element("input[type='file']").val(null);
  76. })
  77. }
  78. })
  79. }
  80. }
  81. }
  82. )
  83. app.service("UploadProdService", function ($http, $rootScope, $timeout) {
  84. var service = {}
  85. service.upload = upload;
  86. var returnfun;
  87. function upload(formData, scope) {
  88. //console.log("File : ",formData);
  89. returnfun = scope
  90. $rootScope.loadingCont = true;
  91. var xhr;
  92. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  93. xhr = new XMLHttpRequest();
  94. }
  95. else {// code for IE6, IE5
  96. xhr = new ActiveXObject("Microsoft.XMLHTTP");
  97. }
  98. //this._scope['formLoad'] = false;
  99. xhr.upload.addEventListener("progress", uploadProgress, false)
  100. xhr.addEventListener("load", function (evt) {
  101. returnfun(evt.target.responseText);
  102. }, false)
  103. xhr.addEventListener("error", uploadFailed, false)
  104. xhr.addEventListener("abort", uploadCanceled, false)
  105. xhr.open("POST", "../services/products.php")
  106. $rootScope.progressVisible = true
  107. xhr.send(formData);
  108. }
  109. function uploadProgress(evt) {
  110. $rootScope.$apply(function () {
  111. if (evt.lengthComputable) {
  112. //$rootScope.progress = Math.round((evt.loaded * 100 )/ evt.total)
  113. } else {
  114. //$rootScope.progress = 'unable to compute'
  115. }
  116. })
  117. }
  118. function uploadComplete(evt) {
  119. //scope.showAlert();
  120. }
  121. function uploadFailed(evt) {
  122. $rootScope.$apply(function () {
  123. $rootScope.loadingCont = false;
  124. })
  125. }
  126. function uploadCanceled(evt) {
  127. $rootScope.$apply(function () {
  128. $rootScope.loadingCont = false;
  129. })
  130. }
  131. return service;
  132. })
  133. app.service("UploadContentService", function ($http, $rootScope, $timeout) {
  134. var service = {}
  135. service.upload = upload;
  136. var returnfun;
  137. function upload(formData, scope) {
  138. var urllink = "services/content.php"
  139. //console.log("File : ",formData);
  140. returnfun = scope
  141. $rootScope.loadingCont = true;
  142. var xhr;
  143. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  144. xhr = new XMLHttpRequest();
  145. }
  146. else {// code for IE6, IE5
  147. xhr = new ActiveXObject("Microsoft.XMLHTTP");
  148. }
  149. //this._scope['formLoad'] = false;
  150. xhr.upload.addEventListener("progress", uploadProgress, false)
  151. xhr.addEventListener("load", function (evt) {
  152. returnfun(evt.target.responseText);
  153. }, false)
  154. xhr.addEventListener("error", uploadFailed, false)
  155. xhr.addEventListener("abort", uploadCanceled, false)
  156. xhr.open("POST", "../services/content.php") //live
  157. // xhr.open("POST", $rootScope.static_url + urllink) //local
  158. $rootScope.progressVisible = true
  159. xhr.send(formData);
  160. }
  161. function uploadProgress(evt) {
  162. $rootScope.$apply(function () {
  163. if (evt.lengthComputable) {
  164. //$rootScope.progress = Math.round((evt.loaded * 100 )/ evt.total)
  165. } else {
  166. //$rootScope.progress = 'unable to compute'
  167. }
  168. })
  169. }
  170. function uploadComplete(evt) {
  171. //scope.showAlert();
  172. }
  173. function uploadFailed(evt) {
  174. $rootScope.$apply(function () {
  175. $rootScope.loadingCont = false;
  176. })
  177. }
  178. function uploadCanceled(evt) {
  179. $rootScope.$apply(function () {
  180. $rootScope.loadingCont = false;
  181. })
  182. }
  183. return service;
  184. })
  185. app.controller('ContentCtrl', function ($scope, $rootScope, AppData, $location, UploadContentService, UploadProdService) {
  186. //Every module Set Same Variable//
  187. $rootScope.menucont = true;
  188. $rootScope.pageLoadComp = false;
  189. $scope.formLoad = false;
  190. $scope.listFound = false;
  191. $scope.pageData = contentData[$rootScope.selLanguage];
  192. $scope.formAction = "Add";
  193. $rootScope.sideselect = $scope.pageData.sidemenu[0];
  194. $scope.itemdetail = [];
  195. $scope.selectedIndex = null;
  196. $rootScope.cofirmWindow = false;
  197. $scope.submenu = $scope.pageData.sidemenu;
  198. $scope.tblheading = $rootScope.sideselect.headingText;
  199. $scope.url = "../senddata/log/";
  200. $scope.pageurl = "../senddata/product/";
  201. $scope.commonurl = "../senddata/common/";
  202. $scope.contenturl = "../senddata/content/";
  203. $rootScope.imageFormat = ["image/jpeg", "image/png"]
  204. $rootScope.pdfFormat = ["application/pdf"];
  205. $rootScope.fileFormat = ["video/mp4", "application/pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx"];
  206. $rootScope.docFormat = ["doc", "docx", "xls", "xlsx", "ppt", "pptx"];
  207. $rootScope.prodimage = '';
  208. $rootScope.uploadfile = [];
  209. $rootScope.uploadthumbimage = [];
  210. $scope.enableeditbox = false;
  211. $scope.cat_error = '';
  212. $scope.topic_error = '';
  213. //filter data
  214. $scope.common_filter = [];
  215. $scope.zonearr = [];
  216. $scope.regionList = [];
  217. $scope.dealerList = [];
  218. $scope.search_box = true;
  219. $rootScope.modalShown = false;
  220. $rootScope.cofirmWindow = false;
  221. //pagination
  222. $scope.viewby = '10';
  223. $scope.currentPage = 1;
  224. $scope.itemsPerPage = $scope.viewby;
  225. $scope.maxSize = 5; //Number of pager buttons to show
  226. $scope.choice = {};
  227. $scope.choice.filelang = '';
  228. //Check Session//
  229. $scope.formData = {}
  230. $rootScope.formData = {}
  231. $scope.formData.roleList = [];
  232. $rootScope.formData.roleList = [];
  233. $scope.formData.ismenuload = "Yes";
  234. if ($rootScope.items == undefined || $rootScope.items == null) {
  235. $scope.formData.ismenuload = "No";
  236. }
  237. $scope.formData.funName = "checksession";
  238. $scope.formData.lang = $rootScope.selLanguage;
  239. $scope.formData.start = 0;
  240. $scope.formData.limit = 2;
  241. AppData.sendData($scope.url, $scope.formData, function (res) {
  242. if (res.cont) {
  243. if ($rootScope.items == undefined || $rootScope.items == null) {
  244. $rootScope.items = res.item.control;
  245. }
  246. for (var i = 0; i < $rootScope.items.length; i++) {
  247. if ($location.path() == $rootScope.items[i].modulepath) {
  248. $rootScope.modulename = $rootScope.items[i].modulename;
  249. $scope.usercontrol = String($rootScope.items[i].permission).split("|");
  250. }
  251. }
  252. $scope.listFound = true;
  253. $scope.statusobj = res.item.status;
  254. $rootScope.username = res.item.username;
  255. $scope.functionCall = function(){
  256. for(let i=0;i<$scope.productList.length;i++){
  257. if($scope.formData.assettopicid==$scope.productList[i].assettopicid){
  258. $scope.topicdata=$scope.productList[i].segment;
  259. }
  260. }
  261. console.log('topic'+$scope.topicdata)
  262. }
  263. $scope.productsList = function () {
  264. $scope.searchvalue = ($scope.formData.mymodel != '') ? $scope.formData.mymodel : "";
  265. $scope.formData.funName = "productlist";
  266. if ($rootScope.sideselect.id == 1) {
  267. console.log("outtttt")
  268. $scope.formData.pn = $scope.currentPage;
  269. $scope.formData.nr = $scope.itemsPerPage;
  270. } else {
  271. console.log("innnnn")
  272. $scope.formData.pn = '';
  273. $scope.formData.nr = '';
  274. }
  275. $scope.formData.key = $scope.searchvalue;
  276. AppData.sendData($scope.pageurl, $scope.formData, function (res) {
  277. if (res.cont) {
  278. if (res.item != undefined) {
  279. $scope.productList = res.item.product;
  280. console.log($scope.productList);
  281. if ($rootScope.sideselect.id != 2) {
  282. $scope.totalItems = res.item.total_records;
  283. }
  284. // $scope.listFound = true;
  285. }
  286. } else {
  287. $scope.listFound = false;
  288. }
  289. })
  290. }
  291. $scope.productsList();
  292. $scope.setPage = function (pageNo) {
  293. $scope.currentPage = pageNo;
  294. };
  295. $scope.pageChanged = function () {
  296. if ($rootScope.sideselect.id == 1) {
  297. $scope.productsList();
  298. } else if ($rootScope.sideselect.id == 2) {
  299. $scope.contentList();
  300. }
  301. };
  302. $scope.setItemsPerPage = function (num) {
  303. $scope.itemsPerPage = num;
  304. $scope.currentPage = 1; //reset to first page
  305. if ($rootScope.sideselect.id == 1) {
  306. $scope.productsList();
  307. } else if ($rootScope.sideselect.id == 2) {
  308. $scope.contentList();
  309. }
  310. }
  311. $scope.filterData = function () {
  312. if ($rootScope.sideselect.id == 1) {
  313. $scope.productsList();
  314. } else if ($rootScope.sideselect.id == 2) {
  315. $scope.contentList();
  316. }
  317. }
  318. } else {
  319. $location.path("/login");
  320. }
  321. })
  322. $scope.categoryList = function () {
  323. //$scope.formData = {};
  324. $scope.formData.funName = "category";
  325. $scope.formData.lang = $rootScope.selLanguage;
  326. AppData.sendData($scope.commonurl, $scope.formData, function (res) {
  327. if (res.cont) {
  328. if (res.item != undefined) {
  329. $scope.catList = res.item;
  330. }
  331. }
  332. })
  333. }
  334. $scope.getLanguage = function () {
  335. var obj = {};
  336. obj.funName = "language";
  337. obj.lang = $rootScope.selLanguage;
  338. AppData.sendData($scope.commonurl, obj, function (res) {
  339. if (res.cont) {
  340. if (res.item != undefined) {
  341. $scope.langList = res.item;
  342. $scope.choice.filelang = '1';
  343. //$scope.isDisabled('1')
  344. }
  345. }
  346. })
  347. }
  348. $scope.choices = [
  349. { filelang: '1' }
  350. ];
  351. $scope.addNewChoice = function () {
  352. var newItemNo = $scope.choices.length + 1;
  353. $scope.choices.push({});
  354. };
  355. $scope.removeChoice = function (item) {
  356. var lastItem = $scope.choices.length - 1;
  357. $scope.choices.splice(lastItem);
  358. $scope.inUse.splice(lastItem);
  359. };
  360. $scope.inUse = [];
  361. $scope.isDisabled = function (name) {
  362. return $scope.inUse.indexOf(name) !== -1;
  363. }
  364. $scope.call = function (val) {
  365. $scope.inUse = [];
  366. for (var i = 0; i < $scope.choices.length; i++) {
  367. var val = $scope.choices[i];
  368. $scope.inUse.push(val.filelang);
  369. }
  370. }
  371. $scope.getRole = function () {
  372. var obj = {};
  373. // obj.funName = "role";
  374. obj.funName = "contentrole";
  375. obj.lang = $rootScope.selLanguage;
  376. obj.type = "dse"
  377. AppData.sendData($scope.commonurl, obj, function (res) {
  378. if (res.cont) {
  379. if (res.item != undefined) {
  380. $scope.role = res.item;
  381. }
  382. }
  383. })
  384. }
  385. $scope.getZone = function () {
  386. var zobj = {};
  387. zobj.funName = "zone";
  388. zobj.lang = $rootScope.selLanguage;
  389. AppData.sendData($scope.commonurl, zobj, function (res) {
  390. if (res.cont) {
  391. if (res.item != undefined) {
  392. $scope.zoneList = res.item;
  393. }
  394. }
  395. })
  396. }
  397. // $scope.ischecked = 0;
  398. // $scope.selectallzone = function (){
  399. // // console.log('zone list:' + $scope.zoneList);
  400. // console.log('Zone length:' + $scope.zoneList.length);
  401. // console.log($scope.zoneList)
  402. // return false
  403. // angular.forEach($scope.zoneList, function (item) {
  404. // console.log(item)
  405. // if (zone.indexOf(item.zone) > -1) {
  406. // item.checked = true;
  407. // }
  408. // });
  409. // }
  410. $scope.zoneChanged = function (item, i) {
  411. console.log(item)
  412. var obj = {};
  413. obj.cont = true;
  414. angular.forEach($scope.regionList, function (cityname, index) {
  415. if (item.zone == cityname.title) {
  416. angular.forEach(cityname.child, function (city, ind) {
  417. for (var k in $scope.formData.regionList) {
  418. if (city == k) {
  419. $scope.formData.regionList[k] = false;
  420. }
  421. }
  422. })
  423. console.log("helloooo", $scope.regionList)
  424. $scope.regionList.splice(index, 1);
  425. obj.cont = false;
  426. }
  427. })
  428. var fobj = {};
  429. fobj.lang = $rootScope.selLanguage;
  430. fobj.funName = "city";
  431. var zonename = item.zone;
  432. fobj.zone = (zonename == undefined) ? "" : zonename;
  433. if (obj.cont) {
  434. AppData.sendData($scope.commonurl, fobj, function (res) {
  435. $rootScope.pageLoadComp = true;
  436. if (res.cont) {
  437. if (res.item != undefined) {
  438. $scope.stateVisible = true;
  439. var arr = [];
  440. for (var id = 0; id < res.item.length; id++) {
  441. arr.push(res.item[id].city);
  442. }
  443. console.log(res.item, arr, "helloooo", $scope.regionList)
  444. $scope.regionList.push({ "title": zonename, "child": arr });
  445. console.log($scope.regionList)
  446. } else {
  447. $scope.regionList = [];
  448. $scope.dealerList = [];
  449. $scope.stateVisible = false;
  450. $scope.dealerVisible = false;
  451. }
  452. }
  453. });
  454. } else {
  455. //angular.forEach($scope.dealerList,function(item,index){
  456. if ($scope.dealerList.length != undefined) {
  457. for (i = 0; i < $scope.dealerList.length; i++) {
  458. for (var k in $scope.formData.regionList) {
  459. if ($scope.dealerList.length != undefined && $scope.dealerList.length > 0) {
  460. if (k == $scope.dealerList[i].title) {
  461. if ($scope.formData.regionList[k] == false) {
  462. angular.forEach($scope.dealerList[i].child, function (dealer, ind) {
  463. for (var j in $scope.formData.dealerList) {
  464. if (j == dealer.dealer_code) {
  465. $scope.formData.dealerList[j] = false;
  466. }
  467. }
  468. $scope.dealerList.splice(i, 1);
  469. })
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }
  478. $scope.regionChanged = function (item, i) {
  479. console.log(item)
  480. var dobj = {};
  481. dobj.cont = true;
  482. if ($scope.dealerList != undefined) {
  483. angular.forEach($scope.dealerList, function (dealername, index) {
  484. if (item == dealername.title) {
  485. angular.forEach(dealername.child, function (dealer, ind) {
  486. for (var k in $scope.formData.dealerList) {
  487. if (dealer.dealer_code == k) {
  488. $scope.formData.dealerList[k] = false;
  489. }
  490. }
  491. })
  492. console.log("helloooo", $scope.dealerList)
  493. $scope.dealerList.splice(index, 1);
  494. dobj.cont = false;
  495. }
  496. })
  497. }
  498. var fobj = {};
  499. fobj.lang = $rootScope.selLanguage;
  500. fobj.funName = "dealer";
  501. var dealer_name = item;
  502. // if($scope.is_edit_dealer==false){
  503. // }else{
  504. // var dealer_name = item.toString();
  505. // $scope.is_edit_dealer= false;
  506. // }
  507. fobj.city = (dealer_name == undefined) ? "" : dealer_name;
  508. if (dobj.cont) {
  509. AppData.sendData($scope.commonurl, fobj, function (res) {
  510. $rootScope.pageLoadComp = true;
  511. if (res.cont) {
  512. if (res.item != undefined) {
  513. $scope.dealerVisible = true;
  514. var arr = [];
  515. for (var id = 0; id < res.item.length; id++) {
  516. var obj = {};
  517. obj.dealer_name = res.item[id].dealer_name;
  518. obj.dealer_code = res.item[id].dealer_code;
  519. arr.push(obj);
  520. }
  521. $scope.dealerList.push({ "title": dealer_name, "child": arr });
  522. console.log($scope.dealerList)
  523. } else {
  524. $scope.dealerVisible = false;
  525. $scope.dealerList = [];
  526. }
  527. }
  528. });
  529. } else {
  530. }
  531. }
  532. $scope.addFun = function () {
  533. $scope.choices = [{ "filelang": "1" }];
  534. $scope.call($scope.choices)
  535. $scope.formLoad = true;
  536. $scope.listFound = false;
  537. $scope.formAction = "Add";
  538. $scope.is_edit_region = false;
  539. $scope.is_edit_dealer = false;
  540. //$scope.title = $rootScope.sideselect.title[0];
  541. $scope.formData = {};
  542. $scope.zoneList = [];
  543. $scope.regionList = [];
  544. $scope.dealerList = [];
  545. $scope.formData.regionList = {};
  546. $scope.formData.dealerList = {};
  547. $rootScope.uploadfile = []
  548. $rootScope.uploadthumbimage = [];
  549. $scope.formData.roleList = [];
  550. $rootScope.formData.roleList = [];
  551. if ($rootScope.sideselect.id == 1) {
  552. $scope.formLoad = true;
  553. $scope.formData.funName = "addproduct";
  554. $scope.formTitle = "ADD TOPIC";
  555. angular.element("input[type='file']").val(null);
  556. $scope.categoryList();
  557. } else if ($rootScope.sideselect.id == 2) {
  558. $scope.formLoad = true;
  559. $scope.formTitle = "ADD CONTENT";
  560. $scope.formData.funName = "addcontent";
  561. angular.element("input[type='file']").val(null);
  562. $scope.getLanguage();
  563. $scope.getRole();
  564. $scope.getZone();
  565. $scope.productsList();
  566. }
  567. }
  568. $rootScope.notifyChange = function () {
  569. if ($rootScope.formData.notification) {
  570. $rootScope.roleVisible = true;
  571. $rootScope.roleGroup = $scope.formData.roleList;
  572. if ($rootScope.roleGroup.length > 0) {
  573. angular.forEach($rootScope.roleGroup, function (element) {
  574. $rootScope.formData.roleList[element.id] = true;
  575. });
  576. }
  577. } else {
  578. $rootScope.roleVisible = false;
  579. }
  580. }
  581. $scope.deleterow = function (obj, i) {
  582. $scope.formData = obj;
  583. $scope.selectedIndex = i;
  584. $scope.deleteFun();
  585. }
  586. $scope.editFun = function () {
  587. $scope.filerequired = false;
  588. $scope.thmbrequired = false;
  589. $scope.formAction = "Edit";
  590. $scope.is_edit_region = true;
  591. $scope.is_edit_dealer = true;
  592. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  593. $scope.formLoad = true;
  594. $scope.listFound = false;
  595. angular.element("input[type='file']").val(null);
  596. if ($scope.selectedIndex != null) {
  597. if ($rootScope.sideselect.id == 1) {
  598. $scope.formTitle = "EDIT TOPIC";
  599. $scope.categoryList();
  600. $scope.image_url = $scope.formData.image_url;
  601. } else if ($rootScope.sideselect.id == 2) {
  602. $scope.formTitle = "EDIT CONTENT";
  603. $scope.getLanguage();
  604. $scope.getRole();
  605. $scope.getZone();
  606. $rootScope.uploadfile = [];
  607. $rootScope.uploadthumbimage = [];
  608. $scope.zoneList = [];
  609. $scope.regionList = [];
  610. $scope.dealerList = [];
  611. $scope.formData.zoneList = {};
  612. $scope.formData.regionList = {};
  613. $scope.formData.dealerList = {};
  614. if ($scope.formData.filter_zone.length > 0) {
  615. angular.forEach($scope.formData.filter_zone, function (element, index) {
  616. console.log(element, "zoneee")
  617. $scope.formData.zoneList[element.zone] = true;
  618. if (element != '') {
  619. $scope.zoneChanged(element, index);
  620. }
  621. });
  622. } else {
  623. $scope.stateVisible = false;
  624. $scope.dealerVisible = false;
  625. }
  626. if ($scope.formData.filter_region.length > 0) {
  627. angular.forEach($scope.formData.filter_region, function (element, index) {
  628. $scope.formData.regionList[element.city] = true;
  629. if (element != '') {
  630. $scope.regionChanged(element['city'], index);
  631. }
  632. });
  633. } else {
  634. $scope.dealerVisible = false;
  635. }
  636. if ($scope.formData.filter_dealer.length > 0) {
  637. angular.forEach($scope.formData.filter_dealer, function (element) {
  638. console.log(element)
  639. $scope.formData.dealerList[element.dealer_code] = true;
  640. });
  641. $scope.dealerVisible = true;
  642. }
  643. $scope.formData.roleList = $scope.formData.filter_role_name;
  644. console.log($scope.formData.roleList, "$scope.formData.roleList ", $scope.formData.filter_role_name)
  645. angular.forEach($scope.formData.file, function (element, i) {
  646. $scope.filepath_url = element.filepath_url;
  647. $scope.thumbpath_url = element.thumbpath_url;
  648. $scope.file_show = i;
  649. $scope.call(element.language_id)
  650. });
  651. $scope.choices = $scope.formData.file;
  652. }
  653. } else {
  654. $rootScope.modalShown = true;
  655. $rootScope.message = $scope.pageData.errorMsg[0];
  656. }
  657. }
  658. $scope.editrow = function (obj, i,data) {
  659. if(data == 0){
  660. $scope.enableeditbox = true;
  661. }else{
  662. $scope.enableeditbox = false;
  663. }
  664. console.log(obj);
  665. $scope.formData.assettopicid = obj.assettopicid;
  666. console.log($scope.formData.assettopicid)
  667. $scope.productsList();
  668. $scope.functionCall(function(){
  669. },1000);
  670. console.log($scope.productList);
  671. $scope.formData = obj;
  672. console.log($scope.formData.filetypeid)
  673. $scope.formData.catename = obj.catename;
  674. $scope.formData.filetypeid = obj.filetypeid;
  675. $scope.selectedIndex = i;
  676. $scope.search_box = false;
  677. $scope.listFound = false;
  678. $scope.formLoad = true;
  679. $scope.formAction = "Edit";
  680. angular.element("input[type='file']").val(null);
  681. $rootScope.prodimage = '';
  682. $scope.editFun();
  683. }
  684. $scope.deleteFun = function () {
  685. if ($scope.selectedIndex != null) {
  686. $rootScope.cofirmWindow = true;
  687. $rootScope.modalShown = true;
  688. $rootScope.message = $scope.pageData.errorMsg[1];
  689. } else {
  690. $rootScope.modalShown = true;
  691. $rootScope.message = $scope.pageData.errorMsg[0];
  692. }
  693. }
  694. $scope.$on("confirmDelete", function () {
  695. if ($rootScope.sideselect.id == 1) {
  696. $scope.formData.funName = "deleteproduct";
  697. $scope.url = $scope.pageurl
  698. } else if ($rootScope.sideselect.id == 2) {
  699. $scope.formData.funName = "deletecontent";
  700. $scope.url = $scope.contenturl
  701. }
  702. $scope.formData.lang = $rootScope.selLanguage;
  703. AppData.sendData($scope.url, $scope.formData, function (res) {
  704. if (res.cont) {
  705. if ($rootScope.sideselect.id == 1) {
  706. var index = $scope.productList.indexOf($scope.formData);
  707. if (index != -1) {
  708. $scope.productList.splice(index, 1);
  709. }
  710. } else if ($rootScope.sideselect.id == 2) {
  711. var index = $scope.contentdata.indexOf($scope.formData);
  712. if (index != -1) {
  713. $scope.contentdata.splice(index, 1);
  714. }
  715. }
  716. $rootScope.modalShown = true;
  717. $rootScope.cofirmWindow = false;
  718. $rootScope.message = (res.mess);
  719. } else {
  720. $rootScope.modalShown = true;
  721. $rootScope.message = (res.mess);
  722. }
  723. })
  724. })
  725. $scope.onSearchChange = function () {
  726. if ($rootScope.sideselect.id == 1) {
  727. $scope.productsList();
  728. } else if ($rootScope.sideselect.id == 2) {
  729. $scope.contentList();
  730. // $scope.productsList();
  731. }
  732. }
  733. $scope.contentList = function () {
  734. $scope.searchvalue = ($scope.formData.mymodel != '') ? $scope.formData.mymodel : "";
  735. $scope.formData.funName = "contentlist";
  736. if ($rootScope.sideselect.id == 2) {
  737. $scope.formData.pn = $scope.currentPage;
  738. $scope.formData.nr = $scope.itemsPerPage;
  739. } else {
  740. $scope.formData.pn = '';
  741. $scope.formData.nr = '';
  742. }
  743. $scope.formData.key = $scope.searchvalue;
  744. AppData.sendData($scope.contenturl, $scope.formData, function (res) {
  745. if (res.cont) {
  746. if (res.item != undefined) {
  747. $scope.contentdata = res.item.content;
  748. console.log($scope.contentdata)
  749. $scope.totalItems = res.item.total_records;
  750. $scope.listFound = true;
  751. }
  752. } else {
  753. $scope.listFound = false;
  754. }
  755. })
  756. }
  757. $scope.onModalHide=function(event){
  758. console.log(event)
  759. $scope.contentList();
  760. }
  761. $scope.viewfile=function(obj, id){
  762. console.log(obj.contentid)
  763. angular.forEach($scope.contentdata,function(element) {
  764. if(element.contentid==obj.contentid){
  765. $scope.content_view = element;
  766. console.log($scope.content_view.file[0].filepath_url)
  767. $scope.filename=$scope.content_view.file[0].filepath_url
  768. }
  769. });
  770. }
  771. $scope.listClick = function (obj) {
  772. $scope.searchtext = '';
  773. $scope.formData = {}
  774. $scope.currentPage = 1;
  775. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  776. $scope.formLoad = false;
  777. $rootScope.sideselect = obj;
  778. $scope.selectedIndex = null;
  779. $rootScope.sideselect.name = obj.name;
  780. if (obj.id == 1) {
  781. $scope.tblheading = obj.headingText;
  782. $scope.productsList();
  783. } else if (obj.id == 2) {
  784. $scope.tblheading = obj.headingText;
  785. $scope.contentList();
  786. // $scope.productsList();
  787. }
  788. }
  789. $scope.fieldValidationTopic = function () {
  790. console.log('prodimage',$rootScope.prodimage)
  791. $scope.cat_error = ($scope.formData.cateid == undefined || $scope.formData.cateid == '') ? $scope.pageData.errorMsg[0] : '';
  792. $scope.topic_error = ($scope.formData.topicname == undefined || $scope.formData.topicname == '') ? $scope.pageData.errorMsg[2] : '';
  793. $scope.segment_error = ($scope.formData.segment == undefined || $scope.formData.segment == '') ? $scope.pageData.errorMsg[0] : '';
  794. $scope.topic_order_error = ($scope.formData.listorder == undefined || $scope.formData.listorder == '') ? "Choose Order by" : '';
  795. $scope.topic_image_error = ($rootScope.prodimage == undefined || $rootScope.prodimage == '') ? 'Please Add Image' : '';
  796. return ($scope.cat_error == '' && $scope.topic_error == '' && $scope.topic_order_error=='' && $scope.topic_image_error=='' && $scope.segment_error=='') ? true : false;
  797. }
  798. $scope.clearErrorMsg = function () {
  799. $scope.cat_error = '';
  800. $scope.topic_error = '';
  801. $scope.topic_order_error='';
  802. $scope.topic_image_error='';
  803. $scope.segment_error ='';
  804. }
  805. $scope.topicSubmit = function () {
  806. if ($scope.fieldValidationTopic()) {
  807. var formData = new FormData();
  808. if ($scope.formAction == "Add") {
  809. formData.append("funName", "addproduct");
  810. } else if ($scope.formAction == "Edit") {
  811. formData.append("assettopicid", $scope.formData.assettopicid);
  812. formData.append("funName", "updateproduct");
  813. }
  814. formData.append("lang", $rootScope.selLanguage);
  815. formData.append("cateid", $scope.formData.cateid);
  816. formData.append("file", $rootScope.prodimage);
  817. formData.append("topicname", $scope.formData.topicname);
  818. formData.append("segment", $scope.formData.segment);
  819. formData.append("listorder", $scope.formData.listorder);
  820. UploadProdService.upload(formData, function (data) {
  821. var response = JSON.parse(data)
  822. $scope.$apply(function () {
  823. $scope.formLoad = false;
  824. $scope.listFound = true;
  825. $scope.formData = {}
  826. $scope.productsList();
  827. $scope.selectedIndex = null;
  828. $rootScope.loadingCont = false;
  829. $rootScope.pageLoadComp = true;
  830. $rootScope.modalShown = true;
  831. $rootScope.message = response.mess;
  832. })
  833. });
  834. }
  835. }
  836. $scope.closeForm = function () {
  837. console.log('I am closed')
  838. $scope.formLoad = false;
  839. $scope.formData = {};
  840. $scope.selectedIndex = null;
  841. $scope.search_box = true;
  842. $scope.listFound = true;
  843. $scope.choices = [];
  844. $scope.zoneList = [];
  845. $scope.regionList = [];
  846. $scope.dealerList = [];
  847. $scope.clearErrorMsg();
  848. // $scope.contentList();
  849. // $scope.productsList();
  850. }
  851. $scope.fieldValidation = function () {
  852. $scope.ftype_error = ($scope.formData.filetypeid == undefined || $scope.formData.filetypeid == '') ? "Please choose the file" : '';
  853. $scope.topic_error = ($scope.formData.assettopicid == undefined || $scope.formData.assettopicid == '') ? $scope.pageData.errorMsg[2] : '';
  854. $scope.segment_error = ($scope.formData.segment == undefined || $scope.formData.segment == '') ? $scope.pageData.errorMsg[0] : '';
  855. $scope.thumb_error = ($rootScope.uploadthumbimage.length == 0) ? 'Upload the thumb image ' : '';
  856. $scope.pdf_error = ($rootScope.uploadfile[0] == undefined ||$rootScope.uploadfile[0] == '') ? 'Please upload the pdf' : '';
  857. return ($scope.ftype_error == '' && $scope.topic_error == '' && $scope.thumb_error == '' && $scope.pdf_error == '' && $scope.segment_error=='') ? true : false;
  858. }
  859. $scope.contentSubmit = function () {
  860. if ($scope.fieldValidation()) {
  861. var formData = new FormData();
  862. if ($scope.formAction == "Add") {
  863. formData.append("funName", "addcontent");
  864. } else if ($scope.formAction == "Edit") {
  865. formData.append("contentid", $scope.formData.contentid);
  866. formData.append("funName", "updatecontent");
  867. }
  868. formData.append("lang", $rootScope.selLanguage);
  869. formData.append("assettopicid", $scope.formData.assettopicid);
  870. formData.append("segment", $scope.formData.segment);
  871. formData.append("title", $scope.formData.title);
  872. formData.append("description", $scope.formData.description);
  873. formData.append("filetypeid", $scope.formData.filetypeid);
  874. if ($rootScope.uploadfile.length != 0) {
  875. formData.append("file_en_us", $rootScope.uploadfile[0]);
  876. }
  877. if ($rootScope.uploadthumbimage.length != 0) {
  878. formData.append("thumb_en_us", $rootScope.uploadthumbimage[0]);
  879. }
  880. if ($scope.formData.filetypeid == 3) {
  881. formData.append("url", $scope.formData.url);
  882. }
  883. if ($scope.formData.cityList != undefined) {
  884. var cityarr = [];
  885. for (k in $scope.formData.cityList) {
  886. if ($scope.formData.cityList[k] == true) {
  887. cityarr.push(k)
  888. }
  889. }
  890. if (cityarr.length != 0) {
  891. formData.append("filter_city", cityarr.toString());
  892. }
  893. }
  894. if ($scope.formData.regionList != undefined) {
  895. var statearr = [];
  896. for (k in $scope.formData.regionList) {
  897. if ($scope.formData.regionList[k] == true) {
  898. statearr.push(k)
  899. }
  900. }
  901. if (statearr.length != 0) {
  902. formData.append("filter_region", statearr.toString());
  903. }
  904. }
  905. if ($scope.formData.dealerList != undefined) {
  906. var dealerarr = [];
  907. for (k in $scope.formData.dealerList) {
  908. if ($scope.formData.dealerList[k] == true) {
  909. dealerarr.push(k)
  910. }
  911. }
  912. if (dealerarr.length != 0) {
  913. formData.append("filter_dealer", dealerarr.toString());
  914. }
  915. }
  916. if ($scope.formData.zoneList != undefined) {
  917. var zonearr = [];
  918. for (k in $scope.formData.zoneList) {
  919. if ($scope.formData.zoneList[k] == true) {
  920. zonearr.push(k)
  921. }
  922. }
  923. if (zonearr.length != 0) {
  924. formData.append("filter_zone", zonearr.toString());
  925. }
  926. }
  927. if ($scope.formData.roleList.length != 0) {
  928. var rolearr = [];
  929. for (var id = 0; id < $scope.formData.roleList.length; id++) {
  930. rolearr.push($scope.formData.roleList[id].id)
  931. }
  932. formData.append("filter_role", rolearr.toString());
  933. }
  934. UploadContentService.upload(formData, function (data) {
  935. console.log($scope.formData);
  936. console.log(data);
  937. var response = JSON.parse(data);
  938. if (response.cont) {
  939. var obj = response.item;
  940. $scope.$apply(function () {
  941. if ($rootScope.uploadfile.length > 1) {
  942. $scope.uploadDataToServer(1, obj[0].contentid, obj[0].assettopicid);
  943. } else {
  944. $scope.formData = {};
  945. $scope.contentList();
  946. }
  947. $scope.formData.assettopicid = '';
  948. $scope.listFound = true;
  949. $scope.formLoad = false;
  950. $rootScope.uploadFiletype = null;
  951. $rootScope.modalShown = true;
  952. $rootScope.message = response.mess;
  953. // $scope.contentList();
  954. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  955. })
  956. }
  957. });
  958. }
  959. $scope.uploadDataToServer = function (id, contentid, topicid) {
  960. var formData = new FormData();
  961. formData.append("funName", "uploadcontentfile");
  962. formData.append("num", id);
  963. formData.append("lang", $rootScope.selLanguage);
  964. formData.append("contentid", contentid);
  965. formData.append("assettopicid", topicid);
  966. formData.append("filetypeid", $scope.formData.filetypeid);
  967. if ($rootScope.uploadfile.length != 0) {
  968. formData.append("file", $rootScope.uploadfile[id]);
  969. }
  970. formData.append("language_id", $scope.choices[id].filelang);
  971. if ($rootScope.uploadthumbimage.length != 0) {
  972. formData.append("thumb", $rootScope.uploadthumbimage[id]);
  973. }
  974. UploadContentService.upload(formData, function (data) {
  975. $rootScope.$apply(function () {
  976. var response = JSON.parse(data)
  977. $rootScope.loadingCont = false;
  978. $scope.selectedIndex = null;
  979. if (response.cont) {
  980. if (id == $rootScope.uploadfile.length - 1) {
  981. $scope.listFound = true;
  982. $scope.formLoad = false;
  983. $rootScope.uploadFiletype = null;
  984. if ($scope.formAction == "Add") {
  985. $scope.contentData.push(response.item);
  986. } else {
  987. $scope.contentData[$scope.selectedIndex] = response.item;
  988. }
  989. } else {
  990. $scope.listFound = true;
  991. $scope.formLoad = false;
  992. $rootScope.modalShown = true;
  993. $rootScope.message = response.mess;
  994. }
  995. if (id < $rootScope.uploadfile.length - 1) {
  996. id++;
  997. $scope.uploadDataToServer(id, contentid, topicid);
  998. } else {
  999. $rootScope.modalShown = true;
  1000. $rootScope.message = response.mess;
  1001. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  1002. $scope.contentList();
  1003. }
  1004. }
  1005. })
  1006. })
  1007. }
  1008. }
  1009. });
  1010. });