removeFoldersCtrl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. angular.module('push')
  2. .controller('removeFoldersCtrl', function ($scope, $ionicPopup, UtilService, $stateParams, $timeout, SqliteStorageService, ModelService, HandleService, UserService, ConfigService, DockingService, CloudFolderService) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. $scope.folder = $stateParams.folder;
  7. $scope.tempname = angular.copy($scope.folder.name);
  8. var sharecloudidlist = [];
  9. $scope.ttc = {showcloud: false};
  10. var conninfolist = [];
  11. var tempconninfolist = [];
  12. var getConninfoList = function () {
  13. var sql = "select * from conninfo where status = 2 and localclaid = " + $scope.folder.localid;
  14. SqliteStorageService.queryData(sql).then(function (response) {
  15. tempconninfolist = response;
  16. angular.forEach(response, function (value, index) {
  17. if (value.status == 2) {
  18. conninfolist.push(value);
  19. }
  20. })
  21. }, function () {
  22. });
  23. };
  24. getConninfoList();
  25. //获取云文件夹list
  26. var getCloudFolderList = function () {
  27. CloudFolderService.getCloudFolderList("").then(function (response) {
  28. $scope.cloudFolderList = response.folderlist;
  29. }, function () {
  30. })
  31. };
  32. getCloudFolderList();
  33. //批量更新
  34. var updateBatchData = function (tablename, datalist) {
  35. SqliteStorageService.updateBatchData(tablename, datalist).then(function () {
  36. // console.log("回写成功");
  37. }, function () {
  38. });
  39. };
  40. //批量删除
  41. var deleteBatchData = function (tablename, datalist) {
  42. SqliteStorageService.deleteBatchData(tablename, datalist).then(function () {
  43. // console.log("批量delete成功");
  44. }, function () {
  45. })
  46. };
  47. //删除当前分类
  48. $scope.deleteFolders = function () {
  49. if ($scope.tempname == "默认文件夹") {
  50. UtilService.showMess("无法删除默认文件夹");
  51. return;
  52. }
  53. $ionicPopup.show({
  54. template: "<p style='text-align: center;'>文件夹中记录将被移入废纸篓</p>",
  55. title: "删除此文件夹",
  56. scope: $scope,
  57. buttons: [
  58. {
  59. text: "取消"
  60. },
  61. {
  62. text: "<span class='ionicAction_span'>删除</span>",
  63. type: "button-positive",
  64. onTap: function () {
  65. deleteFolder();
  66. }
  67. }
  68. ]
  69. })
  70. };
  71. var createFolder = function (tempdate) {
  72. var folder = {
  73. localid: tempdate.timestamp,//本地id
  74. userid: UserService.id,
  75. id: 0,
  76. usercomefrom: ConfigService.comefrom,
  77. name: "默认文件夹",
  78. createtime: tempdate.formattime,
  79. status: 0,
  80. isCloud: 0,
  81. synchrotype: 1,// 0:已同步,1:新增,2:修改,3:逻辑删除,4:物理删除
  82. updatetime: tempdate.formattime,//修改时间
  83. counts: 0
  84. };
  85. SqliteStorageService.insertSingleData("conninfofolder", folder).then(function (response) {
  86. folder.cloudfolder = "";
  87. DockingService.singleSync(1, folder).then(function (res) {
  88. // console.log("新建文件夹--单个同步成功");
  89. // console.log(res);
  90. var tfolder = {};
  91. tfolder.localid = res.conn.localid;
  92. tfolder.id = res.conn.id;
  93. tfolder.synchrotype = 0;
  94. updateBatchData("conninfofolder", [tfolder]);
  95. matchConninfo(tfolder.localid, tfolder.id);
  96. }, function () {
  97. SqliteStorageService.updateEditFlg(1);
  98. });
  99. }, function () {
  100. SqliteStorageService.updateEditFlg(1);
  101. });
  102. };
  103. var matchConninfo = function (templocalid, claid) {
  104. //提取分类下对接信息,依次移至废纸篓
  105. var templist = [];
  106. angular.forEach(tempconninfolist, function (value, index) {
  107. var tempdate2 = UtilService.formatDate();
  108. var tempobj2 = angular.copy(value);
  109. tempobj2.claid = claid;
  110. tempobj2.status = 1;
  111. tempobj2.updatetime = tempdate2.formattime;
  112. tempobj2.cloudfolder = "";
  113. tempobj2.localclaid = templocalid;
  114. if (UtilService.isDefined(value.id)) {
  115. tempobj2.synchrotype = 2;
  116. } else {
  117. tempobj2.synchrotype = 1;
  118. }
  119. templist.push(tempobj2);
  120. });
  121. SqliteStorageService.updateBatchData("conninfo", templist).then(function () {
  122. DockingService.singleSync(2, templist).then(function (res) {
  123. // console.log("修改记录--批量同步成功");
  124. // console.log(res);
  125. if (angular.isDefined(res.recordReturnList) && res.recordReturnList.length > 0) {
  126. var tempconnlist_up = [];
  127. var tempconnlist_del = [];
  128. angular.forEach(res.recordReturnList, function (value, index) {
  129. var tconn = {};
  130. tconn.localid = value.localid;
  131. tconn.id = value.id;
  132. if (value.synchrotype == 4) {
  133. tempconnlist_del.push(tconn);
  134. } else {
  135. tconn.synchrotype = 0;
  136. tempconnlist_up.push(tconn);
  137. }
  138. });
  139. updateBatchData("conninfo", tempconnlist_up);
  140. deleteBatchData("conninfo", tempconnlist_del);
  141. }
  142. SqliteStorageService.updateEditFlg(1);
  143. }, function () {
  144. SqliteStorageService.updateEditFlg(1);
  145. });
  146. HandleService.changeflg = true;
  147. SqliteStorageService.updateEditFlg(1);
  148. }, function () {
  149. });
  150. };
  151. var deleteFolder = function () {
  152. //删除分类
  153. var tempdate = UtilService.formatDate();
  154. var tempobj = angular.copy($scope.folder);
  155. tempobj.synchrotype = 4;
  156. tempobj.updatetime = tempdate.formattime;
  157. SqliteStorageService.updateSingleData("conninfofolder", tempobj).then(function () {
  158. tempobj.cloudfolder = "";
  159. DockingService.singleSync(1, tempobj).then(function (res) {
  160. // console.log("删除文件夹--单个同步成功");
  161. // console.log(res);
  162. var tfolder = {};
  163. tfolder.localid = res.conn.localid;
  164. tfolder.id = res.conn.id;
  165. tfolder.synchrotype = 0;
  166. deleteBatchData("conninfofolder", [tfolder]);
  167. }, function () {
  168. SqliteStorageService.updateEditFlg(1);
  169. });
  170. UtilService.showMess("删除文件夹成功");
  171. $timeout(function () {
  172. $scope.goback();
  173. }, 1500);
  174. HandleService.changeflg = true;
  175. }, function () {
  176. });
  177. if (tempconninfolist.length > 0) {
  178. //提取默认分类的localid
  179. var templocalid = "";
  180. var claid = 0;
  181. //删除的分类更新
  182. angular.forEach(ModelService.getLocalFolderList(), function (value, index) {
  183. if (value.name == "默认文件夹") {
  184. templocalid = value.localid;
  185. claid = value.id;
  186. }
  187. });
  188. if (!UtilService.isDefined(templocalid)) {
  189. templocalid = tempdate.timestamp + "";
  190. createFolder(tempdate);
  191. } else {
  192. matchConninfo(templocalid, claid);
  193. }
  194. }
  195. };
  196. var updateFolder = function () {
  197. var tempdate = UtilService.formatDate();
  198. var folder = {
  199. localid: $scope.folder.localid,//本地id
  200. name: $scope.folder.name,
  201. id: $scope.folder.id,
  202. updatetime: tempdate.formattime//修改时间
  203. };
  204. if (UtilService.isDefined($scope.folder.id)) {
  205. folder.synchrotype = 2;
  206. } else {
  207. folder.synchrotype = 1;
  208. }
  209. SqliteStorageService.updateSingleData("conninfofolder", folder).then(function () {
  210. var ttempfolder = angular.copy($scope.folder);
  211. ttempfolder.cloudfolder = sharecloudidlist.join(",");
  212. ttempfolder.synchrotype = folder.synchrotype;
  213. ttempfolder.updatetime = folder.updatetime;
  214. DockingService.singleSync(1, ttempfolder).then(function (res) {
  215. // console.log("修改文件夹--单个同步成功");
  216. // console.log(res);
  217. var tfolder = {};
  218. tfolder.localid = res.conn.localid;
  219. tfolder.id = res.conn.id;
  220. tfolder.synchrotype = 0;
  221. updateBatchData("conninfofolder", [tfolder]);
  222. }, function () {
  223. SqliteStorageService.updateEditFlg(1);
  224. });
  225. UtilService.showMess("修改成功");
  226. HandleService.changeflg = true;
  227. $timeout(function () {
  228. $scope.goback();
  229. }, 1000);
  230. }, function () {
  231. });
  232. };
  233. //共享本地分类至云文件夹
  234. var shareLocalFolderToCloudFolder = function (folder) {
  235. if (ConfigService.isedit == 1) {
  236. UtilService.showMess("有数据未同步,请去对接宝页面同步后再操作此功能");
  237. return;
  238. }
  239. DockingService.updateFolder(folder, sharecloudidlist).then(function (res) {
  240. // console.log(res);
  241. UtilService.showMess("修改成功");
  242. $timeout(function () {
  243. $scope.goback();
  244. }, 1000);
  245. ModelService.sharecloudflg = false;
  246. }, function () {
  247. })
  248. };
  249. //打开/关闭共享开关
  250. $scope.cloudToggle = function () {
  251. if (conninfolist.length == 0) {
  252. UtilService.showMess("当前文件夹下无记录,无法共享");
  253. $scope.ttc.showcloud = false;
  254. return;
  255. }
  256. if (UtilService.checkNetWork() == "None") {
  257. UtilService.showMess("当前网络已关闭,请打开网络后操作此功能");
  258. $scope.ttc.showcloud = false;
  259. return;
  260. }
  261. if (ConfigService.isedit == 1) {
  262. UtilService.showMess("有数据未同步,请去对接宝页面同步后再操作此功能");
  263. $scope.ttc.showcloud = false;
  264. return;
  265. }
  266. // console.log($scope.ttc.showcloud);
  267. };
  268. //新建云文件夹
  269. $scope.createCloudFolder = function () {
  270. $scope.go("cloudFolderCreate")
  271. };
  272. //选择云文件夹
  273. $scope.checkCloudFolder = function (folder, index) {
  274. $scope.cloudFolderList[index].issyn = !$scope.cloudFolderList[index].issyn;
  275. if ($scope.cloudFolderList[index].issyn) {
  276. sharecloudidlist.push(folder.id);
  277. } else {
  278. angular.forEach(sharecloudidlist, function (value, ind) {
  279. if (value == folder.id) {
  280. sharecloudidlist.splice(ind, 1);
  281. }
  282. });
  283. }
  284. // console.log(sharecloudidlist);
  285. };
  286. $scope.editFolder = function () {
  287. //修改了分类则更新
  288. if ($scope.folder.name == "默认文件夹") {
  289. UtilService.showMess("默认文件夹已存在");
  290. return;
  291. }
  292. if ($scope.tempname != $scope.folder.name || $scope.ttc.showcloud) {
  293. updateFolder();
  294. }
  295. };
  296. });