starter.factory('WorkFlow', function ($ionicPopup, $resource, formatFilter, cfg, Tool, showPopup) { var workflow = {}; workflow.templates = $resource(formatFilter('{0}workflow/template/:id', cfg.api)); workflow.templateitem = $resource(formatFilter('{0}workflow/templateitem/', cfg.api)); workflow.templatecc = $resource(formatFilter('{0}workflow/templatecc/', cfg.api)); workflow.templatestep = $resource(formatFilter('{0}workflow/templatestep/', cfg.api)); workflow.templatepermission = $resource(formatFilter('{0}workflow/templatepermission/', cfg.api)); workflow.templatefield = $resource(formatFilter('{0}daily/templatefield/', cfg.api)); workflow.templatedata = {template_id: -1, items: [], steps: [], cc: [], permission: {'depts': [], 'users': [], 'all': true}}; workflow.create_template = function (templatedata) { var template = _.pick(templatedata, "name", "description"); template.type = templatedata.template_id == -1 ? 1 : 0; workflow.templates.save(template, function (data) { var items = _.map(templatedata.items, function (item) { return _.pick(item, 'name', 'required') }) }) }; workflow.showDialog = function (scope, titlename, placeholder, itemlabel, righttext) { var customTemplate = formatFilter( '
' + '{1}

{2}

', placeholder, itemlabel, righttext); var popup = $ionicPopup.show({ scope: scope, template: customTemplate, title: '
' + titlename + '
', buttons: [{ text: '取消', onTap: function (e) { return false; } }, { text: '保存', type: 'button-positive', onTap: function (e) { if (Tool.trim(scope.auditstep.name).length < 2) { showPopup.PopupWindow(0, "不能少于2个字!", false); e.preventDefault(); } else return true; } }] }); return popup; }; return workflow; }) ;