123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- 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();
- }
- });
|