1 |
- var appFormly=angular.module("formlyDetail",["formlyExample"]);app.requires.push("formlyDetail"),appFormly.controller("CustomformDetailCtrl",["$scope","i18nService","$rootScope","$parse","$injector","$http","$q","$state","$stateParams","$modal","$timeout","$interval","SweetAlert","FileUploader","Restangular","BpmRestangular","api_configure_form","api_bpm_domain","api_bpm_data","api_user_data",function($scope,i18nService,$rootScope,$parse,$injector,$http,$q,$state,$stateParams,$modal,$timeout,$interval,SweetAlert,FileUploader,Restangular,BpmRestangular,api_configure_form,api_bpm_domain,api_bpm_data,api_user_data){function refreshSelectOptions(e,t){if(t.templateOptions.optionsUrl){var a=BpmRestangular.all("");a.customPOST({assignee:2,idx:0,sum:1e3},t.templateOptions.optionsUrl).then(function(e){t.templateOptions.options||(t.templateOptions.options=[]),t.templateOptions.optionsDataKey?t.templateOptions.options=e[t.templateOptions.optionsDataKey]:t.templateOptions.options=e})}}function decodeVMForm(vmForm,mdata){var result={model:{},fields:[]},mdata=angular.fromJson(vmForm.model);angular.extend(result.model,mdata);var fields=[];return angular.forEach(vmForm.fields,function(field){if(""==field.key&&delete field.key,angular.isDefined(field.extjson)){var extObj=angular.fromJson(field.extjson);angular.extend(field.templateOptions,extObj.templateOptions),delete extObj.templateOptions;for(var prop in extObj)if(new RegExp("Expression").test(prop)){if(null!=extObj[prop])if(new RegExp("function").test(extObj[prop])){var propValue=eval(extObj[prop]);extObj[prop]=propValue}else{var obj=$scope.$eval(extObj[prop]);extObj[prop]=obj}}else if(new RegExp("expressionProperties").test(prop)){for(var p in extObj[prop])if(new RegExp("function").test(extObj[prop][p])){var propValue=eval(extObj[prop][p]);extObj[prop][p]=propValue}else if(p.indexOf("'")>=0){var obj=$scope.$eval(extObj[prop][p]);extObj[prop][$scope.$eval(p)]=obj}}else if("watcher"==prop)if(angular.isArray(extObj[prop]))angular.forEach(extObj[prop],function(item,index){for(var p in item)if(new RegExp("function").test(item[p])){var propValue=eval(item[p]);extObj[prop][index][p]=propValue}});else if(angular.isObject(extObj[prop]))for(var p in extObj[prop])if(new RegExp("function").test(extObj[prop][p])){var propValue=eval(extObj[prop][p]);extObj[prop][p]=propValue}angular.extend(field,extObj),delete field.extjson}if(angular.isDefined(field.templateOptions)){var templateOs=field.templateOptions;for(var property in templateOs)if(!angular.isString(templateOs[property])||new RegExp("[一-龥]").test(templateOs[property])&&!new RegExp("function").test(templateOs[property]))null==templateOs[property];else if(new RegExp("function").test(templateOs[property])){var propValue=eval(templateOs[property]);field.templateOptions[property]=propValue}else that.has(templateOs[property])?field.templateOptions[property]=that.get(templateOs[property]):field.templateOptions[property]=templateOs[property]}if(angular.isDefined(field.templateOptions)&&angular.isDefined(field.templateOptions.extjson)){var extObj=angular.fromJson(field.templateOptions.extjson);angular.extend(field.templateOptions,extObj),delete field.templateOptions.extjson}if(field.templateOptions){if(field.templateOptions.optionsUrl&&(field.templateOptions.refresh=refreshSelectOptions),field.templateOptions.pkey){var pmodel,i=0;angular.forEach(field.templateOptions.pkey.split("."),function(e){0==i?(null==result.model[e]&&(result.model[e]={}),pmodel=result.model[e],i++):(null==pmodel[e]&&(pmodel[e]={}),pmodel=pmodel[e])}),null!=pmodel&&(field.model=pmodel,null==pmodel[field.key]&&(pmodel[field.key]=null))}else null==result.model[field.key]&&(result.model[field.key]=null);"ui-input-selectmodal"==field.type?field.templateOptions.modal=$modal:"ui-userselect"==field.type?field.templateOptions.modal=$modal:"ui-multiuserselect"==field.type?field.templateOptions.modal=$modal:"ui-modelselect"==field.type?field.templateOptions.modal=$modal:"ui-dropfile"==field.type?(field.templateOptions.fileUploader=new FileUploader({url:"/uploader"}),field.templateOptions.taskId=$stateParams.taskId,field.templateOptions.processInstanceId=$stateParams.processInstanceId,field.templateOptions.userId=$rootScope.user.id):"ui-dropfiletable"==field.type&&(field.templateOptions.processInstanceId=$stateParams.processInstanceId)}result.fields.push(field)}),angular.extend($scope.vm.fields,result.fields),angular.extend($scope.vm.model,result.model),$scope.formData=vmForm,result}var vm=this;vm.options={formState:{horizontalLabelClass:"col-sm-5",horizontalFieldClass:"col-sm-5",readOnly:!0}},vm.exampleTitle=["expressionProperties","model property"],vm.fields=[],vm.model={},$scope.langs=i18nService.getAllLangs(),$scope.lang="zh-cn",i18nService.setCurrentLang($scope.lang),$scope.backFunction=function(e){$state.go("app.incident",{})};var that=$injector,parse=$parse,formKey="",pdKey="";angular.isDefined($state.current.pdKey)&&""!=$state.current.pdKey?pdKey=$state.current.pdKey:$stateParams.pdKey&&(pdKey=$stateParams.pdKey),angular.isDefined($stateParams.formKey)&&""!=$stateParams.formKey&&(formKey=$stateParams.formKey);var userId=2;$scope.closeModel=function(){"incident"==pdKey?$state.go("app.incident.list",{}):"change"==pdKey?$state.go("app.change.list",{}):"problem"==pdKey?$state.go("app.problem.list",{}):"release"==pdKey?$state.go("app.release.list",{}):"schedule"==pdKey?$state.go("app.scheduling.list",{}):"configure"==pdKey?$state.go("app.cmdb.plist",{}):"serviceCatalogueProcessActual"==pdKey?$state.go("app.reService.manager",{}):"inspectionListForm"==pdKey?$state.go("app.inspection.inspectList",{}):"bpm_inspection"==pdKey?$state.go("app.inspection.inspectList",{}):"bpm_service_request"==pdKey&&$state.go("app.reService.manager",{}),event.preventDefault()},vm.submit=function(e,t){},$scope.vm=vm;var dataId=$stateParams.dataId,pdKey=$stateParams.pdKey,detailFormKey=$stateParams.formKey,processInstanceId=$stateParams.processInstanceId;if(angular.isDefined(detailFormKey)&&""!=detailFormKey){var dataId=parseInt(dataId);angular.isDefined(processInstanceId)&&""!=processInstanceId?api_configure_form.renderForm(detailFormKey,"00000",processInstanceId).then(function(e){if(e){var t=Restangular.stripRestangular(e);if(t){var a={};a[pdKey]=t.model,decodeVMForm(t,a)}}}):angular.isDefined(dataId)&&""!=dataId&&api_bpm_data.fetchData(pdKey,dataId).then(function(e){if(e){var t=Restangular.stripRestangular(e),a=t.data.processInstanceId;api_configure_form.renderForm(detailFormKey,"00000",a).then(function(e){if(e){var t=Restangular.stripRestangular(e);if(t){var a={};a[pdKey]=t.model,decodeVMForm(t,a)}}})}})}else if(""!=pdKey)api_bpm_domain.startformkey(pdKey).then(function(e){if(e){var t=Restangular.stripRestangular(e);api_configure_form.renderForm(t.data).then(function(e){if(e){var t=Restangular.stripRestangular(e);t&&decodeVMForm(t)}})}});else{var testJson={fields:[{key:"formtitle",type:"ui-title",noFormControl:!0,templateOptions:{label:"title is ",placeholder:"Formly is terrific!"}},{key:"a",type:"ui-input",className:"col-xs-4",templateOptions:{type:"input",label:"input a",placeholder:"search a...",lBtn:{label:"input",onClick:function(e,t,a,l,p){}},rAddon:"@111.cc"}},{key:"b",type:"ui-input",className:"col-xs-4",templateOptions:{type:"input",label:"input a",placeholder:"search a...",rBtn:{icon:"glyphicon-search",onClick:function(e,t,a,l,p){}},lAddon:"@"}},{key:"first",type:"ui-input",className:"col-xs-2",templateOptions:{type:"input",label:"first name",pkey:"name"}},{key:"last",type:"ui-input",className:"col-xs-2",templateOptions:{type:"input",label:"last name",pkey:"name"}},{key:"username",type:"ui-input",className:"col-xs-6",templateOptions:{type:"input",label:"User Name",placeholder:"Enter name",required:!0,maxLength:10}},{key:"password",type:"ui-input",className:"col-xs-6",templateOptions:{type:"password",label:"Password",placeholder:"Password",required:!0},expressionProperties:{"templateOptions.disabled":"!model.username"}},{key:"selectmodal",type:"ui-input-selectmodal",className:"col-xs-6",templateOptions:{label:"selectmodal",btnLabel:"search",btnClassName:"btn-o",modalParam:{items:function(){return["a","b","c","d"]},title:function(){return"测试标题"}}}},{key:"email",type:"ui-input",className:"col-xs-6",templateOptions:{type:"email",maxlength:10,minlength:6,label:"EMail"}},{key:"date",type:"ui-datepicker",className:"col-xs-6",templateOptions:{label:"Date",type:"text",datepickerPopup:"yyyy-MM-dd hh:mm:ss",initDate:function(){return new Date}}},{key:"multiselectItem",type:"ui-multi-select-tree",className:"col-xs-6",templateOptions:{label:"multiSelect",placeholder:"请选择...",isMultiSelect:!1,selLeafs:!1,refreshData:function(e){return e.fetchDataList("changeclassify",{idx:0,sum:100})},APIService:api_bpm_data,optionsDataKey:"list",refreshDelay:1e3,onDataCallback:function(e,t,a,l,p){p[a.key]={id:e.id}}}},{key:"selectItem",type:"ui-select",className:"col-xs-4",templateOptions:{label:"ui-select",valueProp:"code",labelProp:"source",optionsUrl:"data/fetchDataList/incidentsource",optionsDataKey:"list",required:!0,onChange:function(e,t,a,l,p){p.start_code=e}}},{key:"multiselectItem",type:"ui-multiselect",className:"col-xs-4",templateOptions:{label:"multi-select",valueProp:"code",labelProp:"source",optionsUrl:"data/fetchDataList/incidentsource",optionsDataKey:"list",required:!0,onChange:function(e,t,a,l,p){}}},{key:"checklistItem",type:"ui-checklist",className:"col-xs-4",templateOptions:{label:"checklistItem",options:[{name:"Iron Man",value:"iron_man"},{name:"Captain America",value:"captain_america"},{name:"Black Widow",value:"black_widow"},{name:"Hulk",value:"hulk"},{name:"Captain Marvel",value:"captain_marvel"}]}},{key:"radioItem",type:"ui-radio",className:"col-xs-4",templateOptions:{label:"radioItem",options:[{name:"Iron Man",value:"iron_man"},{name:"Captain America",value:"captain_america"},{name:"Black Widow",value:"black_widow"},{name:"Hulk",value:"hulk"},{name:"Captain Marvel",value:"captain_marvel"}],type:"number"}},{key:"selectUser",type:"ui-userselect",className:"col-xs-12",templateOptions:{label:"请求人信息",modalTitle:"请求人列表",fetchItems:function(e,t){return t.fetchDataList("user",e)},Restangular:Restangular,ApiService:api_user_data,onClick:function(e,t,a,l,p){}}},{key:"cabUser",type:"ui-multiuserselect",className:"col-xs-12",templateOptions:{label:"CAB评审成员",modalTitle:"CAB成员列表",fetchItems:function(e,t){return t.fetchDataList("user",e)},Restangular:Restangular,ApiService:api_user_data,onClick:function(e,t,a,l,p){}}},{key:"incident",type:"ui-modelselect",className:"col-xs-3",templateOptions:{label:"关联事件工单",modalTitle:"事件列表",fetchItems:function(e,t){return t.fetchDataList("incident",e)},Restangular:"Restangular",ApiService:"api_bpm_data",columnDefs:[{name:"id",width:80,enableFiltering:!1},{name:"title",displayName:"事件主题",width:140},{name:"type.name",displayName:"事件类型",width:140},{name:"emergency.name",displayName:"紧急度",width:80},{name:"state.name",displayName:"状态",width:100},{name:"emergency.name",displayName:"紧急度",width:80},{name:"influence.name",displayName:"影响度",width:80},{name:"priority.name",displayName:"优先级",width:80},{name:"handlerUser.name",displayName:"当前处理人",width:100},{name:"acceptDate",displayName:"创建时间",width:100}],displayName:"title",onClick:function(e,t,a,l,p){}}},{key:"worknumber",type:"ui-workernumber",className:"col-xs-3",templateOptions:{label:"work number",Restangular:Restangular,ApiService:api_bpm_domain,getWorkernumber:function(e){return e.workernumber("bg")}}},{key:"chkme",type:"ui-checkbox",className:"col-xs-3",templateOptions:{label:"Check me out"}},{key:"droplink",type:"ui-link",className:"col-xs-3",templateOptions:{label:"添加附件",onClick:function(e,t,a,l,p){angular.isUndefined(a.form.dropState)&&(a.form.dropState=!1),a.form.dropState=!a.form.dropState}}},{key:"dropfile",type:"ui-dropfile",className:"col-xs-12",templateOptions:{label:"附件",uploadUrl:"http://127.0.0.1:9008/saveAttachments"}},{key:"droplist",type:"ui-dropfiletable",className:"col-xs-12",templateOptions:{label:"附件下载列表",Restangular:Restangular,ApiService:api_bpm_domain}},{key:"start_code",className:"col-xs-6",type:"ui-hidden"},{key:"remark",type:"ui-textarea",className:"col-xs-12",templateOptions:{label:"remark is ",rows:3}},{key:"setStartCode",type:"ui-button",className:"col-xs-4",templateOptions:{label:"customButton",onClick:function(e,t,a,l,p){p.start_code++}}}],model:{username:"robin lau",password:"123456",chkme:!1,start_code:0,formtitle:"Hey!I am title value!",name:{first:"robin",last:"lau"},multiselectItem:[]}};setTimeout(function(){decodeVMForm(testJson),$scope.$apply()},500)}}]);
|