sales.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 excel file 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.file_Format.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 Excel 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/excelupload.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('SalesCtrl', 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.commonurl = "../senddata/common/";
  138. $scope.cat_error = '';
  139. $scope.topic_error = '';
  140. //filter data
  141. $scope.common_filter = [];
  142. $scope.zonearr = [];
  143. $scope.search_box = true;
  144. $rootScope.modalShown = false;
  145. $rootScope.cofirmWindow = false;
  146. //pagination
  147. $scope.viewby = '10';
  148. $scope.currentPage = 1;
  149. $scope.pageSize = 10;
  150. $scope.maxSize = 5;
  151. $scope.itemsPerPage = $scope.viewby;
  152. $scope.maxSize = 5;
  153. $scope.choice = {};
  154. $scope.choice.filelang = '';
  155. //Check Session//
  156. $scope.formData = {}
  157. $rootScope.file_Format = ["xls", "xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
  158. $rootScope.uploadfile = [];
  159. $rootScope.formData = {}
  160. $scope.formData.roleList = [];
  161. $rootScope.formData.roleList = [];
  162. $scope.topic_error = '';
  163. $scope.formData.ismenuload = "Yes";
  164. if ($rootScope.items == undefined || $rootScope.items == null) {
  165. $scope.formData.ismenuload = "No";
  166. }
  167. $scope.formData.funName = "checksession";
  168. $scope.formData.lang = $rootScope.selLanguage;
  169. // $scope.formData.start = 0;
  170. // $scope.formData.limit = 2;
  171. AppData.sendData($scope.url, $scope.formData, function (res) {
  172. if (res.cont) {
  173. if ($rootScope.items == undefined || $rootScope.items == null) {
  174. $rootScope.items = res.item.control;
  175. }
  176. for (var i = 0; i < $rootScope.items.length; i++) {
  177. if ($location.path() == $rootScope.items[i].modulepath) {
  178. $rootScope.modulename = $rootScope.items[i].modulename;
  179. $scope.usercontrol = String($rootScope.items[i].permission).split("|");
  180. }
  181. }
  182. $scope.listFound = true;
  183. $scope.statusobj = res.item.status;
  184. $rootScope.username = res.item.username;
  185. } else {
  186. $location.path("/login");
  187. }
  188. })
  189. $scope.filesubmmit = function () {
  190. if ($scope.fieldValidationTopic()) {
  191. var formData = new FormData();
  192. formData.append("funName", "dsedata");
  193. if ($rootScope.uploadfile.length != 0) {
  194. formData.append("file", $rootScope.uploadfile[0]);
  195. // console.log($rootScope.uploadfile[0])
  196. }
  197. console.log(formData);
  198. UploadProdService.upload(formData, function (data) {
  199. //console.log(data)
  200. var response = JSON.parse(data)
  201. $scope.$apply(function () {
  202. $scope.formData = {}
  203. $rootScope.modalShown = true;
  204. $rootScope.message = response.mess;
  205. //$scope.filesubmmit();
  206. $scope.formLoad = false;
  207. $rootScope.loadingCont = false;
  208. $rootScope.pageLoadComp = true;
  209. })
  210. });
  211. }
  212. }
  213. $scope.fieldValidationTopic = function () {
  214. $scope.topic_image_error = ($rootScope.uploadfile[0] == undefined || $rootScope.uploadfile[0] == '') ? 'Please choose the file' : '';
  215. return ($scope.topic_image_error == '') ? true : false;
  216. }
  217. });
  218. });