factory.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. starter.factory('Notice', function ($http, $q, cfg, global, formatFilter, Tool) {
  2. var NoticeDetailsData = null;
  3. var curDate = new Date();
  4. var tmday = new Date((curDate / 1000 + 86400) * 1000);
  5. var savedata = {
  6. "user_id": global.user.usrid,
  7. "title": "",
  8. "content": "",
  9. "address": null,
  10. "create_dd": null,
  11. "readtimes": 0,
  12. "commenttimes": 0,
  13. "back_title": null,
  14. "back_enddd": tmday,
  15. "vote_title": null,
  16. "vote_selecttype": 1,
  17. "vote_selectdata": "",
  18. "vote_enddd": tmday,
  19. "allid": 0,
  20. "groupid": null,
  21. "readusrs": [],
  22. "noticefiles": [],
  23. "setbtnstyle": {
  24. vote: false,
  25. back: false
  26. },
  27. "selectitems": [],
  28. "deleteimages": {
  29. "oldimages": [],
  30. "newimages": []
  31. },
  32. "disablededit": {
  33. showadditem: true,
  34. showeditback: true
  35. }
  36. };
  37. var countDetails = {
  38. usrCountList: [],
  39. selectItem: null
  40. };
  41. function pick() {
  42. }
  43. function setdata(data) {
  44. if (Tool.trim(data.vote_title).length == 0) {
  45. data.vote_title = null;
  46. data.vote_enddd = null;
  47. }
  48. if (Tool.trim(data.back_title).length == 0) {
  49. data.back_title = null;
  50. data.back_enddd = null;
  51. }
  52. }
  53. return {
  54. getCreateUsrs: function () {
  55. var url = formatFilter('{0}notice/createusrs/', cfg.api);
  56. return Tool.get(url);
  57. },
  58. post_NoticeCreateUsrs: function (add_usrs) {
  59. var url = formatFilter('{0}notice/createusrs/', cfg.api);
  60. return Tool.post(url, add_usrs);
  61. },
  62. delete_NoticeCreateUsrs: function (delete_usrs) {
  63. var data = [{
  64. "op": "del",
  65. "values": delete_usrs
  66. }];
  67. var url = formatFilter('{0}notice/createusrs/', cfg.api);
  68. return Tool.patch(url, data);
  69. },
  70. post_NoticeMf: function (data) {
  71. console.log(Tool.cloneObj(data));
  72. console.log(data);
  73. data = _.pick(data,
  74. "user_id",
  75. "title",
  76. "content",
  77. "address",
  78. "create_dd",
  79. "commenttimes",
  80. "back_title",
  81. "back_enddd",
  82. "vote_title",
  83. "vote_selecttype",
  84. "vote_selectdata",
  85. "vote_enddd",
  86. "allid",
  87. "groupid",
  88. "update_dd",
  89. "readusrs");
  90. var url = formatFilter('{0}notice/', cfg.api);
  91. setdata(data);
  92. return Tool.post(url, data);
  93. },
  94. post_NoticeReadList: function (data) {
  95. var url = formatFilter('{0}notice/readlist/', cfg.api);
  96. return Tool.post(url, data);
  97. },
  98. getReceive: function () {
  99. var url = formatFilter('{0}notice/list/?type=receive', cfg.api);
  100. return Tool.get(url);
  101. },
  102. getRelease: function () {
  103. var url = formatFilter('{0}notice/list/', cfg.api);
  104. return Tool.get(url);
  105. },
  106. getNext: function(url) {
  107. return Tool.get(url);
  108. },
  109. getDetails: function (id) {
  110. var url = formatFilter('{0}notice/{1}/', cfg.api, id);
  111. var deferred = $q.defer();
  112. $http.get(url).then(function (res) {
  113. deferred.resolve(res.data);
  114. NoticeDetailsData = Tool.cloneObj(res.data);
  115. NoticeDetailsData.setbtnstyle = {
  116. vote: false,
  117. back: false
  118. };
  119. NoticeDetailsData.selectitems = [];
  120. if (NoticeDetailsData.vote_title !== null) {
  121. NoticeDetailsData.setbtnstyle.vote = true;
  122. var selectitems = NoticeDetailsData.vote_selectdata.split(';');
  123. _.each(selectitems, function (item) {
  124. NoticeDetailsData.selectitems.push({
  125. "text": item
  126. });
  127. });
  128. }
  129. if (NoticeDetailsData.back_title != null) {
  130. NoticeDetailsData.setbtnstyle.back = true;
  131. }
  132. NoticeDetailsData.showvoteDelete = false;
  133. NoticeDetailsData.showbackDelete = false;
  134. if (NoticeDetailsData.vote_title != null) {
  135. NoticeDetailsData.showvoteDelete = true;
  136. } else {
  137. NoticeDetailsData.vote_enddd = tmday;
  138. }
  139. if (NoticeDetailsData.back_title != null) {
  140. NoticeDetailsData.showbackDelete = true;
  141. } else {
  142. NoticeDetailsData.back_enddd = tmday;
  143. }
  144. NoticeDetailsData.deleteimages = {
  145. "oldimages": [],
  146. "newimages": []
  147. };
  148. NoticeDetailsData.disablededit = {
  149. showadditem: true,
  150. showeditback: true
  151. };
  152. console.log(NoticeDetailsData)
  153. },
  154. function (err) {
  155. deferred.reject(err);
  156. });
  157. return deferred.promise;
  158. },
  159. getLoalDetails: function (op) {
  160. return NoticeDetailsData;
  161. },
  162. getsavedata: savedata,
  163. getstructdata: function () {
  164. var structdata = {
  165. "user_id": global.user.usrid,
  166. "title": "",
  167. "content": "",
  168. "address": null,
  169. "create_dd": null,
  170. "readtimes": 0,
  171. "commenttimes": 0,
  172. "back_title": null,
  173. "back_enddd": tmday,
  174. "vote_title": null,
  175. "vote_selecttype": 1,
  176. "vote_selectdata": "",
  177. "vote_enddd": tmday,
  178. "allid": 0,
  179. "groupid": null,
  180. "readusrs": [],
  181. "noticefiles": [],
  182. "setbtnstyle": {
  183. vote: false,
  184. back: false
  185. },
  186. "selectitems": [],
  187. "deleteimages": {
  188. "oldimages": [],
  189. "newimages": []
  190. },
  191. "disablededit": {
  192. showadditem: true,
  193. showeditback: true
  194. }
  195. };
  196. return Tool.cloneObj(structdata);
  197. },
  198. put_NoticeMf: function (data) {
  199. data = _.pick(data, "id",
  200. "title",
  201. "content",
  202. "address",
  203. "back_enddd",
  204. "back_title",
  205. "vote_title",
  206. "vote_selecttype",
  207. "vote_selectdata",
  208. "vote_enddd",
  209. "allid",
  210. "groupid",
  211. "update_dd",
  212. "readusrs",
  213. "del_files");
  214. var url = formatFilter('{0}notice/{1}/', cfg.api, data.id);
  215. setdata(data);
  216. return Tool.put(url, data);
  217. },
  218. delete_NoticeMf: function (id) {
  219. var url = formatFilter('{0}notice/{1}/', cfg.api, id);
  220. return Tool.delete(url);
  221. },
  222. getUsrCount: function (id, type, index) {
  223. var url = formatFilter('{0}notice/stat/detail/?notice_id={1}&type={2}', cfg.api, id, type);
  224. if (type == 7 && index != undefined) {
  225. url = formatFilter('{0}notice/stat/detail/?notice_id={1}&type={2}&index={3}', cfg.api, id, type, index);
  226. }
  227. return Tool.get(url, true, 'noticecount');
  228. },
  229. getCountDetails: function () {
  230. countDetails.usrCountList = Tool.getTempData('noticecount');
  231. return countDetails;
  232. },
  233. getCount: function (id) {
  234. var url = formatFilter('{0}notice/stat/?notice_id={1}', cfg.api, id);
  235. return Tool.get(url);
  236. },
  237. getRecord: function (id) {
  238. var url = formatFilter('{0}notice/record/?noticeid={1}', cfg.api, id);
  239. return Tool.get(url);
  240. },
  241. postRecord: function (data) {
  242. var url = formatFilter('{0}notice/record/', cfg.api);
  243. return Tool.post(url, data);
  244. },
  245. getCreateUsrsState: function () {
  246. var url = formatFilter('{0}notice/createusrs/?type={1}', cfg.api, 'state');
  247. return Tool.get(url);
  248. }
  249. }
  250. });