newNotificationCtrl.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. angular.module('push')
  2. .controller('newNotificationCtrl', function ($scope, $sce, $stateParams, ResourceLibraryService, $ionicPopup, UserService, CommentService, AccountService, $ionicActionSheet, UtilService, $timeout, CommonService) {
  3. //$scope.notice为空即新增,非空即编辑
  4. $scope.notice = $stateParams.notice;
  5. $scope.noticecontent = $sce.trustAsHtml($scope.notice.content);
  6. ResourceLibraryService.getPictureList($scope.notice.unique, $scope.notice.creator).then(function (res) {
  7. if(res.code == 3350) {
  8. $scope.picturelist = res.data;
  9. angular.forEach($scope.picturelist, function(picture){
  10. angular.forEach($scope.formList, function(form){
  11. if(form.doctype == picture.doctype){
  12. form.imageSaveList.push(picture);
  13. }
  14. })
  15. })
  16. }
  17. })
  18. //富文本
  19. var editor = CKEDITOR.replace('editor');
  20. $scope.notification = {};
  21. $scope.notification.title = $scope.notice.newtitle;
  22. $scope.notification.region = $scope.notice.address;
  23. $scope.params = {};
  24. //发送通知公告
  25. $scope.sendNotice = function () {
  26. if (!$scope.notification.title) {
  27. $ionicPopup.alert({
  28. title: '提示',
  29. template: "请填写通知公告标题"
  30. })
  31. return;
  32. }
  33. //notice.snowflakeID存在,即代表编辑功能
  34. if ($stateParams.notice.snowflakeID) {
  35. $scope.params.resid = $stateParams.notice.unique;
  36. }
  37. $scope.notification.context = editor.getData();
  38. $scope.notification.summary = editor.document.getBody().getText();
  39. $scope.params.data = $scope.notification;
  40. $scope.params.userid = UserService.id;
  41. $scope.params.node = UserService.node;
  42. $scope.params.formList = $scope.formList;
  43. AccountService.publicNotification($scope.params).then(function (res) {
  44. if (res.code == 3350) {
  45. if($scope.notice.title){
  46. $scope.template = '编辑成功';
  47. }else{
  48. $scope.template = '发布成功';
  49. }
  50. $ionicPopup.alert({
  51. title: '提示',
  52. template: $scope.template
  53. })
  54. $scope.go("notification");
  55. }
  56. })
  57. }
  58. //以下皆为添加附件相关方法
  59. $scope.formList = [{
  60. title: '附件',
  61. content: '[]',
  62. type: 'upload',
  63. needed: true,
  64. imagelist: [],
  65. imageSaveList: [],
  66. imageDeleteList: [],
  67. doctype: 4902,
  68. remarkType: 'normal',
  69. rowMargin: true
  70. }, {
  71. title: '图片',
  72. content: '[]',
  73. type: 'upload',
  74. needed: false,
  75. imagelist: [],
  76. imageSaveList: [],
  77. imageDeleteList: [],
  78. doctype: 4901,
  79. remarkType: 'add'
  80. }
  81. ];
  82. $scope.addImage = function (index) {
  83. listIndex = index;
  84. if ($scope.app) {
  85. var list = [
  86. {text: '<a class="action-sheet-push">拍照</a>'},
  87. {text: '<a class="action-sheet-push">从相册上传</a>'},
  88. ];
  89. var clickfunction = function (indx) {
  90. if (indx == 0) {
  91. $scope.openCamera();
  92. } else {
  93. getPictures();
  94. }
  95. return true;
  96. }
  97. } else {
  98. // var list = [
  99. // {text: '<a class="action-sheet-push">从相册上传</a>'},
  100. // ];
  101. // var clickfunction = function (indx) {
  102. // if (indx == 0) {
  103. var files;
  104. if (index == 0) {
  105. files = document.getElementById('file');
  106. } else {
  107. files = document.getElementById('img');
  108. }
  109. files.click();
  110. $(files).unbind().on('change', function (e) {
  111. // console.log(e);
  112. if (index == 1) {
  113. var str=document.getElementById('img').value.split('.');
  114. if(str&&str.length>0&&str[1]!='jpg'&&str[1]!='gif'&&str[1]!='bmp'&&str[1]!='png'&&str[1]!='jpeg'&&str[1]!='tiff'&&str[1]!='pjp'&& str[1]!='pjpeg'&&str[1]!='jfif'&&str[1]!='tif'&&str[1]!='svg'&&str[1]!='svgz'&&str[1]!='webp'&&str[1]!='ico'&&str[1]!='xbm'&&str[1]!='dib') {
  115. $ionicPopup.alert({
  116. title: '提示',
  117. template: '请上传图片!'
  118. });
  119. return;
  120. }
  121. }
  122. $.each(e.target.files, function (i, file) {
  123. var url = null;
  124. if (window.createObjectURL != undefined) { // basic
  125. url = window.createObjectURL(file);
  126. } else if (window.URL != undefined) { // mozilla(firefox)
  127. url = window.URL.createObjectURL(file);
  128. } else if (window.webkitURL != undefined) { // webkit or chrome
  129. url = window.webkitURL.createObjectURL(file);
  130. }
  131. $scope.formList[listIndex].imagelist.push({photoName: url, originalName: url});
  132. })
  133. $.each(e.target.files, function (i, file) {
  134. var data = new FormData();
  135. data.append('file', file);
  136. CommonService.webUploadImage(data).then(function (res) {
  137. var temp = {
  138. id: 0,
  139. title: res.title,
  140. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  141. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  142. photoName: res.photoName,
  143. originalName: res.originalName,
  144. sourceName: res.sourceName,
  145. sourceSize: res.sourceSize
  146. }
  147. $scope.formList[listIndex].imageSaveList.push(temp);
  148. // console.log(temp);
  149. // console.log($scope.formList[listIndex]);
  150. })
  151. });
  152. })
  153. // }
  154. return true;
  155. // }
  156. }
  157. $ionicActionSheet.show({
  158. buttons: list,
  159. cancelText: '取消',
  160. buttonClicked: clickfunction
  161. })
  162. }
  163. $scope.openCamera = function () {
  164. if ($scope.formList[listIndex].imagelist.length >= 9) {
  165. if ($scope.app) {
  166. UtilService.showMess("最多选取9张图片");
  167. } else {
  168. CommonService.showMessage("最多选取9张图片", $scope)
  169. }
  170. return;
  171. }
  172. UtilService.getPicture(1).then(function (results) {
  173. $scope.showLoadingToast();
  174. $scope.formList[listIndex].imagelist.push({photoName: results, originalName: results})
  175. UtilService.uploadFile([results], 0, "image/jpeg").then(function (response) {
  176. angular.forEach(response, function (value) {
  177. $scope.formList[listIndex].imageSaveList.push({
  178. id: 0,
  179. title: response.getTitle(),
  180. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  181. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  182. photoName: value.photoName,
  183. originalName: value.originalName,
  184. sourceName: value.sourceName,
  185. sourceSize: value.sourceSize
  186. })
  187. })
  188. $scope.hideLoadingToast();
  189. }, function () {
  190. $scope.hideLoadingToast();
  191. if ($scope.app) {
  192. UtilService.showMess("网络不给力,请重试");
  193. } else {
  194. CommonService.showMessage("网络不给力,请重试", $scope)
  195. }
  196. });
  197. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  198. }, function (err) {
  199. });
  200. }
  201. var getPictures = function () {
  202. if (device.platform == "Android") {
  203. verifyStorage();
  204. } else {
  205. getPic();
  206. }
  207. };
  208. var verifyStorage = function () {
  209. window.imagePicker.verifyStorage(
  210. function (results) {
  211. if (results == "1") {
  212. getPic();
  213. }
  214. }, function (error) {
  215. }
  216. );
  217. };
  218. var getPic = function () {
  219. var imagelistLength = $scope.formList[listIndex].imagelist.length;
  220. if (imagelistLength >= 9) {
  221. if ($scope.app) {
  222. UtilService.showMess("最多选取9张图片");
  223. } else {
  224. CommonService.showMessage("最多选取9张图片", $scope)
  225. }
  226. return;
  227. }
  228. UtilService.getPictureList(9 - imagelistLength).then(function (results) {
  229. $scope.showLoadingToast();
  230. angular.forEach(results, function (val, i) {
  231. $scope.formList[listIndex].imagelist.push({photoName: val, originalName: val});
  232. })
  233. UtilService.uploadFile(results, 0, "image/jpeg").then(function (response) {
  234. angular.forEach(response, function (value) {
  235. if (value.status) {
  236. $scope.formList[listIndex].imageSaveList.push({
  237. id: 0,
  238. title: response.getTitle(),
  239. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  240. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  241. photoName: value.photoName,
  242. originalName: value.originalName,
  243. sourceName: value.sourceName,
  244. sourceSize: value.sourceSize
  245. });
  246. }
  247. })
  248. $scope.hideLoadingToast();
  249. }, function () {
  250. $scope.hideLoadingToast();
  251. if ($scope.app) {
  252. UtilService.showMess("网络不给力,请重试");
  253. } else {
  254. CommonService.showMessage("网络不给力,请重试", $scope)
  255. }
  256. });
  257. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  258. }, function (err) {
  259. });
  260. };
  261. //删除图片
  262. $scope.deletePhoto = function (index, outerIndex) {
  263. console.log($scope.formList[outerIndex]);
  264. if ($scope.formList[outerIndex].imageSaveList[index].id != 0) {
  265. $scope.formList[outerIndex].imageSaveList[index].isenabled = 2;
  266. $scope.formList[outerIndex].imageDeleteList.push($scope.formList[outerIndex].imageSaveList[index]);
  267. }
  268. $scope.formList[outerIndex].imagelist.splice(index, 1);
  269. $scope.formList[outerIndex].imageSaveList.splice(index, 1);
  270. // console.log($scope.formList[outerIndex].imagelist);
  271. // console.log($scope.formList[outerIndex].imageSaveList);
  272. // console.log($scope.formList[outerIndex].imageDeleteList);
  273. }
  274. $scope.uploadPic = function (e) {
  275. // console.log(2);
  276. // console.log(e.target);
  277. }
  278. })
  279. ;