123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- angular.module('push')
- .controller('removeFoldersCtrl', function ($scope, $ionicPopup, UtilService, $stateParams, $timeout, SqliteStorageService, ModelService, HandleService, UserService, ConfigService, DockingService, CloudFolderService) {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- $scope.folder = $stateParams.folder;
- $scope.tempname = angular.copy($scope.folder.name);
- var sharecloudidlist = [];
- $scope.ttc = {showcloud: false};
- var conninfolist = [];
- var tempconninfolist = [];
- var getConninfoList = function () {
- var sql = "select * from conninfo where status = 2 and localclaid = " + $scope.folder.localid;
- SqliteStorageService.queryData(sql).then(function (response) {
- tempconninfolist = response;
- angular.forEach(response, function (value, index) {
- if (value.status == 2) {
- conninfolist.push(value);
- }
- })
- }, function () {
- });
- };
- getConninfoList();
- //获取云文件夹list
- var getCloudFolderList = function () {
- CloudFolderService.getCloudFolderList("").then(function (response) {
- $scope.cloudFolderList = response.folderlist;
- }, function () {
- })
- };
- getCloudFolderList();
- //批量更新
- var updateBatchData = function (tablename, datalist) {
- SqliteStorageService.updateBatchData(tablename, datalist).then(function () {
- // console.log("回写成功");
- }, function () {
- });
- };
- //批量删除
- var deleteBatchData = function (tablename, datalist) {
- SqliteStorageService.deleteBatchData(tablename, datalist).then(function () {
- // console.log("批量delete成功");
- }, function () {
- })
- };
- //删除当前分类
- $scope.deleteFolders = function () {
- if ($scope.tempname == "默认文件夹") {
- UtilService.showMess("无法删除默认文件夹");
- return;
- }
- $ionicPopup.show({
- template: "<p style='text-align: center;'>文件夹中记录将被移入废纸篓</p>",
- title: "删除此文件夹",
- scope: $scope,
- buttons: [
- {
- text: "取消"
- },
- {
- text: "<span class='ionicAction_span'>删除</span>",
- type: "button-positive",
- onTap: function () {
- deleteFolder();
- }
- }
- ]
- })
- };
- var createFolder = function (tempdate) {
- var folder = {
- localid: tempdate.timestamp,//本地id
- userid: UserService.id,
- id: 0,
- usercomefrom: ConfigService.comefrom,
- name: "默认文件夹",
- createtime: tempdate.formattime,
- status: 0,
- isCloud: 0,
- synchrotype: 1,// 0:已同步,1:新增,2:修改,3:逻辑删除,4:物理删除
- updatetime: tempdate.formattime,//修改时间
- counts: 0
- };
- SqliteStorageService.insertSingleData("conninfofolder", folder).then(function (response) {
- folder.cloudfolder = "";
- DockingService.singleSync(1, folder).then(function (res) {
- // console.log("新建文件夹--单个同步成功");
- // console.log(res);
- var tfolder = {};
- tfolder.localid = res.conn.localid;
- tfolder.id = res.conn.id;
- tfolder.synchrotype = 0;
- updateBatchData("conninfofolder", [tfolder]);
- matchConninfo(tfolder.localid, tfolder.id);
- }, function () {
- SqliteStorageService.updateEditFlg(1);
- });
- }, function () {
- SqliteStorageService.updateEditFlg(1);
- });
- };
- var matchConninfo = function (templocalid, claid) {
- //提取分类下对接信息,依次移至废纸篓
- var templist = [];
- angular.forEach(tempconninfolist, function (value, index) {
- var tempdate2 = UtilService.formatDate();
- var tempobj2 = angular.copy(value);
- tempobj2.claid = claid;
- tempobj2.status = 1;
- tempobj2.updatetime = tempdate2.formattime;
- tempobj2.cloudfolder = "";
- tempobj2.localclaid = templocalid;
- if (UtilService.isDefined(value.id)) {
- tempobj2.synchrotype = 2;
- } else {
- tempobj2.synchrotype = 1;
- }
- templist.push(tempobj2);
- });
- SqliteStorageService.updateBatchData("conninfo", templist).then(function () {
- DockingService.singleSync(2, templist).then(function (res) {
- // console.log("修改记录--批量同步成功");
- // console.log(res);
- if (angular.isDefined(res.recordReturnList) && res.recordReturnList.length > 0) {
- var tempconnlist_up = [];
- var tempconnlist_del = [];
- angular.forEach(res.recordReturnList, function (value, index) {
- var tconn = {};
- tconn.localid = value.localid;
- tconn.id = value.id;
- if (value.synchrotype == 4) {
- tempconnlist_del.push(tconn);
- } else {
- tconn.synchrotype = 0;
- tempconnlist_up.push(tconn);
- }
- });
- updateBatchData("conninfo", tempconnlist_up);
- deleteBatchData("conninfo", tempconnlist_del);
- }
- SqliteStorageService.updateEditFlg(1);
- }, function () {
- SqliteStorageService.updateEditFlg(1);
- });
- HandleService.changeflg = true;
- SqliteStorageService.updateEditFlg(1);
- }, function () {
- });
- };
- var deleteFolder = function () {
- //删除分类
- var tempdate = UtilService.formatDate();
- var tempobj = angular.copy($scope.folder);
- tempobj.synchrotype = 4;
- tempobj.updatetime = tempdate.formattime;
- SqliteStorageService.updateSingleData("conninfofolder", tempobj).then(function () {
- tempobj.cloudfolder = "";
- DockingService.singleSync(1, tempobj).then(function (res) {
- // console.log("删除文件夹--单个同步成功");
- // console.log(res);
- var tfolder = {};
- tfolder.localid = res.conn.localid;
- tfolder.id = res.conn.id;
- tfolder.synchrotype = 0;
- deleteBatchData("conninfofolder", [tfolder]);
- }, function () {
- SqliteStorageService.updateEditFlg(1);
- });
- UtilService.showMess("删除文件夹成功");
- $timeout(function () {
- $scope.goback();
- }, 1500);
- HandleService.changeflg = true;
- }, function () {
- });
- if (tempconninfolist.length > 0) {
- //提取默认分类的localid
- var templocalid = "";
- var claid = 0;
- //删除的分类更新
- angular.forEach(ModelService.getLocalFolderList(), function (value, index) {
- if (value.name == "默认文件夹") {
- templocalid = value.localid;
- claid = value.id;
- }
- });
- if (!UtilService.isDefined(templocalid)) {
- templocalid = tempdate.timestamp + "";
- createFolder(tempdate);
- } else {
- matchConninfo(templocalid, claid);
- }
- }
- };
- var updateFolder = function () {
- var tempdate = UtilService.formatDate();
- var folder = {
- localid: $scope.folder.localid,//本地id
- name: $scope.folder.name,
- id: $scope.folder.id,
- updatetime: tempdate.formattime//修改时间
- };
- if (UtilService.isDefined($scope.folder.id)) {
- folder.synchrotype = 2;
- } else {
- folder.synchrotype = 1;
- }
- SqliteStorageService.updateSingleData("conninfofolder", folder).then(function () {
- var ttempfolder = angular.copy($scope.folder);
- ttempfolder.cloudfolder = sharecloudidlist.join(",");
- ttempfolder.synchrotype = folder.synchrotype;
- ttempfolder.updatetime = folder.updatetime;
- DockingService.singleSync(1, ttempfolder).then(function (res) {
- // console.log("修改文件夹--单个同步成功");
- // console.log(res);
- var tfolder = {};
- tfolder.localid = res.conn.localid;
- tfolder.id = res.conn.id;
- tfolder.synchrotype = 0;
- updateBatchData("conninfofolder", [tfolder]);
- }, function () {
- SqliteStorageService.updateEditFlg(1);
- });
- UtilService.showMess("修改成功");
- HandleService.changeflg = true;
- $timeout(function () {
- $scope.goback();
- }, 1000);
- }, function () {
- });
- };
- //共享本地分类至云文件夹
- var shareLocalFolderToCloudFolder = function (folder) {
- if (ConfigService.isedit == 1) {
- UtilService.showMess("有数据未同步,请去对接宝页面同步后再操作此功能");
- return;
- }
- DockingService.updateFolder(folder, sharecloudidlist).then(function (res) {
- // console.log(res);
- UtilService.showMess("修改成功");
- $timeout(function () {
- $scope.goback();
- }, 1000);
- ModelService.sharecloudflg = false;
- }, function () {
- })
- };
- //打开/关闭共享开关
- $scope.cloudToggle = function () {
- if (conninfolist.length == 0) {
- UtilService.showMess("当前文件夹下无记录,无法共享");
- $scope.ttc.showcloud = false;
- return;
- }
- if (UtilService.checkNetWork() == "None") {
- UtilService.showMess("当前网络已关闭,请打开网络后操作此功能");
- $scope.ttc.showcloud = false;
- return;
- }
- if (ConfigService.isedit == 1) {
- UtilService.showMess("有数据未同步,请去对接宝页面同步后再操作此功能");
- $scope.ttc.showcloud = false;
- return;
- }
- // console.log($scope.ttc.showcloud);
- };
- //新建云文件夹
- $scope.createCloudFolder = function () {
- $scope.go("cloudFolderCreate")
- };
- //选择云文件夹
- $scope.checkCloudFolder = function (folder, index) {
- $scope.cloudFolderList[index].issyn = !$scope.cloudFolderList[index].issyn;
- if ($scope.cloudFolderList[index].issyn) {
- sharecloudidlist.push(folder.id);
- } else {
- angular.forEach(sharecloudidlist, function (value, ind) {
- if (value == folder.id) {
- sharecloudidlist.splice(ind, 1);
- }
- });
- }
- // console.log(sharecloudidlist);
- };
- $scope.editFolder = function () {
- //修改了分类则更新
- if ($scope.folder.name == "默认文件夹") {
- UtilService.showMess("默认文件夹已存在");
- return;
- }
- if ($scope.tempname != $scope.folder.name || $scope.ttc.showcloud) {
- updateFolder();
- }
- };
- });
|