123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- angular.module('push')
- .controller('authorityLocalSetCtrl', function ($scope, $stateParams, AuthorityService, AuthorityModel, UtilService, $timeout, $ionicPopup, UserService,
- LocalOperateService, ConfigService, SqliteStorageService) {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- //0:记录,1:资源
- var tempmess = $stateParams.type == 1 ? "资源库" : "文件夹";
- //恢复临时数据
- if (AuthorityModel.isfirst == 0) {
- $scope.tempfolder = angular.fromJson(angular.copy($stateParams.authoritydata));
- $scope.memberlist = [{
- userId: UserService.id,
- userName: UserService.user.user.userName,
- photo: UserService.user.user.photo,
- iscreator: 1,
- comefrom: ConfigService.comefrom
- }];
- $scope.adminlist = [];
- $scope.ownername = UserService.user.user.userName;
- } else {
- $scope.tempfolder = AuthorityModel.getAuthorityObj();
- $scope.memberlist = AuthorityModel.getMemberList();
- $scope.adminlist = AuthorityModel.getAdminList();
- $scope.ownername = AuthorityModel.getOwnerName();
- }
- $scope.editLocalFolder = function () {
- if (!UtilService.isDefined($scope.tempfolder.name)) {
- var tempmessage = tempmess + "名称不能为空";
- UtilService.showMess(tempmessage);
- return;
- }
- if ($scope.memberlist.length > 1) {
- if (UserService.viplevel == 1) {
- AuthorityService.isHasEnoughCount(2).then(function (response) {
- if (response.isHasEnoughCount == 1) {
- showToast();
- } else {
- UtilService.showMess("本月新建云文件夹次数已用完");
- $scope.hideLoadingToast();
- }
- }, function () {
- UtilService.showMess("网络不给力,请重试");
- $scope.hideLoadingToast();
- });
- } else {
- showToast();
- }
- } else {
- setLocalFolder();
- }
- };
- var showToast = function () {
- $ionicPopup.show({
- title: "提示信息",
- template: "<p style='text-align: center;'>加入成员后将新建一个云" + tempmess + ",所有成员将共享" + tempmess + "</p>",
- scope: $scope,
- buttons: [
- {text: "取消"},
- {
- text: '<span class="ionicAction_span">确认</span>',
- type: "button-positive",
- onTap: function () {
- newCreateFolder();
- }
- }
- ]
- });
- };
- //新建权限(云文件夹)
- var crfoflg = 0;
- var newCreateFolder = function () {
- if (crfoflg != 0) {
- return;
- }
- crfoflg = 1;
- $scope.showLoadingToast();
- var list1 = [];
- var list2 = [];
- var ownerid = "";
- angular.forEach($scope.memberlist, function (value, index) {
- if (value.iscreator == 0) {
- list1.push(value.userId);
- } else if (value.iscreator == 1) {
- ownerid = value.userId;
- } else {
- list2.push(value.userId);
- }
- });
- if ($stateParams.type == 0) {
- $scope.tempfolder.content = angular.isDefined($scope.tempfolder.content) ? $scope.tempfolder.content : "";
- AuthorityService.newCreateFolder($scope.tempfolder, list1, list2, [], ownerid, 0, 0, 1).then(function (response) {
- // console.log(response);
- copyLocalClass(response.conn.id);
- UtilService.showMess("新建成功");
- if (UserService.viplevel == 1) {
- $scope.deductUserMemberCount(2);
- }
- $timeout(function () {
- AuthorityModel.resetAuthorityData();
- AuthorityModel.isfirst = 0;
- $scope.goback();
- crfoflg = 0;
- }, 1000);
- $scope.hideLoadingToast();
- }, function () {
- crfoflg = 0;
- UtilService.showMess("网络不给力,请重试");
- $scope.hideLoadingToast();
- });
- } else {
- AuthorityService.newCreateResLib($scope.tempfolder, list1, list2, ownerid).then(function (response) {
- // console.log(response);
- UtilService.showMess("新建成功");
- $timeout(function () {
- AuthorityModel.resetAuthorityData();
- AuthorityModel.isfirst = 0;
- $scope.goback();
- crfoflg = 0;
- }, 1000);
- $scope.hideLoadingToast();
- }, function () {
- crfoflg = 0;
- UtilService.showMess("网络不给力,请重试");
- $scope.hideLoadingToast();
- });
- }
- };
- var copyLocalClass = function (claid) {
- if (!UtilService.isDefined($scope.tempfolder.id) || $scope.tempfolder.id == 0) {
- return;
- }
- AuthorityService.copyLocalClass($scope.tempfolder.id, claid).then(function (response) {
- // console.log(response);
- }, function () {
- })
- };
- //编辑本地文件夹
- var setLocalFolder = function () {
- $scope.showLoadingToast();
- LocalOperateService.setLocalFolder($scope.tempfolder).then(function (response) {
- UtilService.showMess("设置成功");
- $timeout(function () {
- AuthorityModel.resetAuthorityData();
- AuthorityModel.isfirst = 0;
- ConfigService.isedit = 1;
- SqliteStorageService.updateEditFlg(1);
- if ($stateParams.goflg == 1) {
- $scope.backViews(-2)
- } else {
- $scope.goback();
- }
- crfoflg = 0;
- }, 1000);
- $scope.hideLoadingToast();
- }, function () {
- crfoflg = 0;
- $scope.hideLoadingToast();
- });
- };
- //保存临时数据
- var saveTempData = function () {
- AuthorityModel.setAuthorityObj($scope.tempfolder);
- AuthorityModel.setMemberList($scope.memberlist);
- AuthorityModel.setAdminList($scope.adminlist);
- AuthorityModel.setOwnerName($scope.ownername);
- AuthorityModel.isfirst = 1;
- };
- //返回
- $scope.gobackback = function () {
- AuthorityModel.resetAuthorityData();
- AuthorityModel.isfirst = 0;
- $scope.goback();
- };
- //跳转至添加成员页面
- $scope.addResourceMember = function () {
- saveTempData();
- $scope.go("addMember");
- };
- //跳转至设置管理员页面
- $scope.goSetManger = function () {
- if ($scope.memberlist.length > 1) {
- saveTempData();
- $scope.go("authoritySetManger");
- }
- };
- //跳转至设置所有者页面
- /*$scope.goSetOwner = function () {
- if ($scope.memberlist.length > 1) {
- saveTempData();
- $scope.go("authoritySetOwner");
- }
- };*/
- //跳转到成员页面
- $scope.goResourceMember = function () {
- saveTempData();
- $scope.go("authorityFolderMember");
- };
- //查看个人主页
- $scope.goPublisher = function (member) {
- saveTempData();
- $scope.go('publisher', {Id: member.userId})
- };
- //退出权限
- $scope.quitAuthority = function () {
- $ionicPopup.show({
- title: "确认退出此" + tempmess,
- template: "<p style='text-align: center;'>退出后" + tempmess + "将不再显示在列表中</p>",
- scope: $scope,
- buttons: [
- {text: "取消"},
- {
- text: '<span class="ionicAction_span">确认</span>',
- type: "button-positive",
- onTap: function () {
- deleteAllData();
- }
- }
- ]
- });
- };
- $scope.delflg = 0;
- var delnum = 1;
- //删除所有此文件夹数据
- var deleteAllData = function () {
- $scope.showLoadingToast();
- var tempdate = UtilService.formatDate();
- //--查询当前文件夹下所有子文件夹(将当前文件夹及所有子文件夹localid组成list返回)
- LocalOperateService.queryAllFolderByLocalid($scope.tempfolder.localid).then(function (response) {
- // console.log(response);
- if (response.length > 0) {
- delnum++;
- //删除文件夹
- var up_fol_sql = "update conninfofolder set synchrotype = 4,updatetime = '" + tempdate.formattime + "' where localid in (" + response.join(",") + ")";
- SqliteStorageService.queryData(up_fol_sql).then(function () {
- $scope.delflg++;// 2
- }, function (error) {
- $scope.delflg++;// 2
- });
- var sel_sql = "select * from conninfo where localclaid in (" + response.join(",") + ")";
- SqliteStorageService.queryData(sel_sql).then(function (res) {
- if (res.length > 0) {
- delnum++;
- //删除文件夹下记录
- var up_conn_sql = "update conninfo set synchrotype = 4,updatetime = '" + tempdate.formattime + "' where localclaid in (" + response.join(",") + ")";
- SqliteStorageService.queryData(up_conn_sql).then(function () {
- $scope.delflg++;// 4
- }, function () {
- $scope.delflg++;// 4
- });
- //删除记录下名片
- var localinfoidstr = "";
- angular.forEach(res, function (value, index) {
- var tempstr = "'" + value.localid + "'";
- localinfoidstr = localinfoidstr + tempstr + ",";
- });
- localinfoidstr = localinfoidstr.substring(0, localinfoidstr.length - 1);
- var up_unit_sql = "update conninfounit set synchrotype = 4,updatetime = '" + tempdate.formattime + "' where localinfoid in (" + localinfoidstr + ")";
- SqliteStorageService.queryData(up_unit_sql).then(function () {
- $scope.delflg++;// 5
- }, function () {
- $scope.delflg++;// 5
- });
- } else {
- $scope.delflg++;// 3
- }
- }, function () {
- $scope.delflg++;// 3
- });
- } else {
- $scope.delflg++;// 1
- }
- }, function () {
- $scope.delflg++;// 1
- });
- };
- //--监听本地与云文件夹查询是否结束
- var owacth = $scope.$watch("delflg", function (newValue) {
- if (newValue == delnum) {
- if (delnum == 1) {
- UtilService.showMess("退出失败,请重试");
- } else {
- UtilService.showMess("退出成功");
- ConfigService.isedit = 1;
- SqliteStorageService.updateEditFlg(1);
- $timeout(function () {
- AuthorityModel.resetAuthorityData();
- AuthorityModel.isfirst = 0;
- if ($stateParams.goflg == 1) {
- $scope.backViews(-2)
- } else {
- $scope.goback();
- }
- }, 1000);
- }
- owacth();
- $scope.hideLoadingToast();
- }
- });
- });
|