starter.controller('WorkFlowCtrl', function ($scope, $state, global) { $scope.goBack = function () { global.goBack(); }; $scope.toman = function () { $state.go('workflow-manage'); }; $scope.toapply = function () { $state.go('workflow-apply'); }; }) .controller('WorkFlowManageCtrl', function ($scope, global, WorkFlow, Tool) { $scope.ordering = false; global.fetch_user().then(function () { if (!$scope.templates) $scope.loading = true; WorkFlow.templates.get({'type': 1}, function (res) { $scope.templates = res; }, function (err) { alert(JSON.stringify(err)); } ).$promise.finally(function (f) { $scope.loading = false; }) }); $scope.ordering = function () { $scope.ordering = !$scope.ordering; }; $scope.loadMore = function () { Tool.get_nextpage($scope.templates.nexturl).then(function (res) { var old_data = angular.copy($scope.templates.results); $scope.templates = res; $scope.templates.results = old_data.concat(res.results); }).finally(function (f) { $scope.$broadcast('scroll.infiniteScrollComplete'); }) } }) .controller('WorkFlowTemplateCreateCtrl', function ($scope, $stateParams, $state, $ionicSlideBoxDelegate, $ionicHistory, $rootScope, global, Member, WorkFlow, showPopup, Tool) { $scope.datatext = { leftbtn: [{ text: '取消', click: "cancel", params: "c" }, { text: '上一步', click: 'back' }], rightbtn: [{ text: '下一步', click: 'down' }, { text: '完成', click: 'ok' }] }; $scope.titleName = ['填写流程名称', '选择流程模板', '创建审批人步骤', '添加流程介绍']; $scope.leftIndex = 0; $scope.rightIndex = 0; $scope.activeIndex = 0; $scope.template = WorkFlow.templatedata; var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () { if (Member.customerop == "cc" && Member.selectedemplst.length > 0) $scope.template.cc = $scope.template.cc.concat(Member.selectedemplst); else if (Member.customerop == "permission" && Member.selectedemplst.length > 0) { $scope.template.permission.users = $scope.template.permission.users.concat(Member.selectedemplst); $scope.template.permission.all = false; } Member.customerop = null; }); global.fetch_user().then(function () { WorkFlow.templates.query({'type': 0}, function (data) { var temp_templates = _.map(data, function (item) { return _.extend(item, {'show': false}); }); var temps = []; $scope.templates_already = []; _.each(temp_templates, function (item, index) { if (index % 2 == 0 && index != 0) { $scope.templates_already.push(angular.copy(temps)); temps = []; } temps.push(item); }); if (temps.length <= 2) $scope.templates_already.push(temps); }); }); $scope.down = function () { if ($scope.activeIndex == 0 && Tool.trim($scope.template.name).length < 2) { showPopup.PopupWindow(0, "名称长度不能少于2!", false); return; } if ($scope.activeIndex == 2 && $scope.template.steps.length == 0) { showPopup.PopupWindow(0, "请添加审批步骤!", false); return; } $ionicSlideBoxDelegate.next(); $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex(); if ($scope.activeIndex >= 1) { $scope.leftIndex = 1; $scope.rightIndex = 0; if ($scope.activeIndex == 3) { $scope.rightIndex = 1; } } else { $scope.leftIndex = 0; $scope.rightIndex = 1; } }; $scope.cancel = function (op) { $ionicHistory.goBack(); }; $scope.back = function () { if ($scope.activeIndex != 0) { $ionicSlideBoxDelegate.previous(); $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex(); $scope.rightIndex = 0; if ($scope.activeIndex == 0) { $scope.leftIndex = 0; } } else { $ionicHistory.goBack(); } }; $scope.lockSlide = function () { $ionicSlideBoxDelegate.enableSlide(false); }; $scope.customer_template = {id: -1, show: true}; $scope.checktemplate = function (item) { _.each(_.flatten($scope.templates_already).concat($scope.customer_template), function (item) { item.show = false; }); item.show = true; }; $scope.toSetItem = function (id) { if (WorkFlow.templatedata.template_id != id) WorkFlow.templatedata.items = []; WorkFlow.templatedata.template_id = id; $state.go('workflow-templateitemset', { id: id }); }; $scope.auditstep = {name: "", verifier: null, ordering: WorkFlow.templatedata.steps.length + 1}; $scope.toaddstep = function (value) { $scope.auditsteps = WorkFlow.templatedata.steps; $scope.popup = WorkFlow.showDialog($scope, "第" + (WorkFlow.templatedata.steps.length + 1) + "步", '步骤名称', '审批人', value == undefined ? "选填" : value); $scope.popup.then(function (popup) { if (popup) { $scope.auditstep.verifier = Member.selectedemplst[0]; $scope.auditsteps.push(angular.copy($scope.auditstep)); $scope.auditstep.name = ""; $scope.auditstep.verifier = null; Member.selectedemplst = []; } }); }; //选择审批人 $scope.toselect = function () { $scope.popup.close(); Member.routename = ""; Member.selectedemplst = []; Member.emit.is_have = true; Member.emit.name = "show_popup_open"; $state.go('selectsinglemember'); }; $scope.select_cc_or_permission = function (op) { Member.customerop = op; Member.routename = ""; Member.selectedemplst = []; $state.go('selectmember'); }; $scope.ok_template=function () { }; var p = $rootScope.$on('show_popup_open', function () { if ($scope.popup != undefined) $scope.toaddstep(Member.selectedemplst.length > 0 ? Member.selectedemplst[0].username : "选填"); Member.emit = {"is_have": false, "name": ""}; }); $scope.$on('$destroy', function (e) { p = null; }); }) .controller('WorkFlowTemplateDetailCtrl', function ($scope, global, WorkFlow) { global.fetch_user().then(function () { if (!$scope.templates) $scope.loding = true; WorkFlow.templates.query(function (res) { $scope.templates = res; }) }) }) .controller('WorkFlowApplyCtrl', function ($scope, global, WorkFlow) { }) .controller('WorkFlowTemplateItemSetCtrl', function ($scope, $state, $ionicHistory, $ionicPopup, $rootScope, WorkFlow, global) { $scope.is_customer = $state.params['id'] < 0; beforeEnter = $scope.$on("$ionicView.beforeEnter", function (event, data) { $scope.template_items = WorkFlow.templatedata.items; }); global.fetch_user().then(function () { if (!$scope.is_customer) WorkFlow.templateitem.query({"template_id": $state.params['id']}, function (data) { $scope.template_items = data; WorkFlow.templatedata.items = data; }, function (err) { alert(JSON.stringify(err)) }).$promise.finally(function (f) { }); }); $scope.ok = function () { $ionicHistory.goBack(); }; $scope.cancel = function () { $ionicHistory.goBack(); }; $scope.toSetItem = function (id) { $state.go('workflow-templateitemfield', {id: id}); }; $scope.$on("$destroy", function () { beforeEnter = null; }); }) .controller('FormFieldTypeCtrl', function ($scope, $state, $ionicHistory, global, WorkFlow, showPopup) { $scope.isNew = $state.params['id'] < 0; $scope.template_item = $scope.isNew ? {name: "", required: true, t__type: 1, extra: "", select_texts: []} : angular.copy(_.find(WorkFlow.templatedata.items, {'id': id})); global.fetch_user().then(function () { WorkFlow.templatefield.get(function (res) { $scope.template_fields = _.map(res.results, function (item) { return _.extend(item, {'checked': false}); }); if ($scope.isNew) { $scope.template_field_active = $scope.template_fields[0]; $scope.template_field_active.checked = true; } }, function (err) { alert(JSON.stringify(err)); }) }); $scope.change = function (item_field) { $scope.template_field_active = item_field; if (item_field.showlist) $scope.template_item.select_texts.push({"text": ""}); }; $scope.remove = function (index) { $scope.template_item.select_texts.splice(index, 1); }; $scope.add = function () { $scope.template_item.select_texts.push({'text': ""}); }; $scope.ok = function () { if ($scope.isNew) WorkFlow.templatedata.items.push($scope.template_item); else { var item = _.find(WorkFlow.templatedata.items, {'id': $state.params['id']}); item = $scope.template_item; } $ionicHistory.goBack(); } });