123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687 |
- 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) {
- //console.log($parse('Restangular')($scope));
- //console.log($injector.get('Restangular'));
- var vm = this;
- vm.options = {
- formState: {
- horizontalLabelClass: 'col-sm-5',
- horizontalFieldClass: 'col-sm-5',
- readOnly: true
- }
- };
- vm.exampleTitle = ['expressionProperties','model property'];
- vm.fields=[];
- vm.model={};
- $scope.langs=i18nService.getAllLangs();
- $scope.lang = 'zh-cn';
- i18nService.setCurrentLang($scope.lang);
- $scope.backFunction = function(data){
- $state.go('app.incident',{});
- };
- var that=$injector;
- var parse=$parse;
- var formKey = "";
- var pdKey = "";
- if(angular.isDefined($state.current.pdKey)&&$state.current.pdKey!=""){
- pdKey = $state.current.pdKey;
- // console.log("pdKey::"+$state.current.pdKey);
- }
- if(angular.isDefined($stateParams.formKey)&&$stateParams.formKey!=""){
- formKey = $stateParams.formKey;
- // console.log("formKey::"+$stateParams.formKey);
- }
- //用户测试数据,后续从header的auth中获取
- var userId = 2;
- //==============处理表单设计数据 开始====================
- //处理组件加载后台数据选项的方法
- function refreshSelectOptions(searchVal, field) {
- if(field.templateOptions.optionsUrl){
- var process = BpmRestangular.all("");
- process.customPOST({"assignee":2,"idx":0,"sum":1000},field.templateOptions.optionsUrl).then(function(result){
- if(!field.templateOptions.options){
- field.templateOptions.options=[];
- }
- if(field.templateOptions.optionsDataKey){
- field.templateOptions.options =result[field.templateOptions.optionsDataKey];
- }else{
- field.templateOptions.options =result;
- }
- });
- }
- }
- //解析自定义表单设计数据
- function decodeVMForm(vmForm, mdata){
- var result = {model:{},fields:[]};
- //设置模型实体数据 begin
- // var mdata = vmForm.model;
- //解析数据实体
- //console.log("mdata="+JSON.stringify(mdata));
- var mdata = angular.fromJson(vmForm.model);
- angular.extend(result.model,mdata);
- //设置模型实体数据 end
- //解析设计数据生成表单项 begin
- var fields = [];
- //处理修改设计数据中展示设置
- angular.forEach(vmForm.fields, function(field){
- if(field.key==""){
- delete field.key;
- }
- if(angular.isDefined(field.extjson)){
- var extObj = angular.fromJson(field.extjson);//JSON.parse(field.extjson);
- angular.extend(field.templateOptions, extObj.templateOptions);
- delete extObj.templateOptions;
- for(var prop in extObj){
- if(new RegExp("Expression").test(prop)){
- //var obj = $scope.$eval(extObj[prop]);
- //extObj[prop] = $scope.$eval(extObj[prop]);
- if(extObj[prop]!=null){
- if(new RegExp("function").test(extObj[prop])){
- var propValue = eval(extObj[prop]);
- extObj[prop] = propValue;
- }else{
- // console.log(extObj[prop]);
- var obj = $scope.$eval(extObj[prop]);
- extObj[prop] = obj;
- // console.log(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){
- // console.log(property);
- if(angular.isString(templateOs[property])&& (!(new RegExp("[\u4e00-\u9fa5]").test(templateOs[property]))||new RegExp("function").test(templateOs[property]))){
- if(new RegExp("function").test(templateOs[property])){
- var propValue = eval(templateOs[property]);
- field.templateOptions[property] = propValue;
- }else{
- if(that.has(templateOs[property])){
- field.templateOptions[property] = that.get(templateOs[property]);
- }else{
- field.templateOptions[property] = templateOs[property];
- }
- }
- }else if(templateOs[property]==null){
- //delete field.templateOptions[property];
- }else{
- }
- }
- }
- // console.log(field);
- if(angular.isDefined(field.templateOptions) && angular.isDefined(field.templateOptions.extjson)){
- var extObj = angular.fromJson(field.templateOptions.extjson);//JSON.parse(field.extjson);
- angular.extend(field.templateOptions,extObj);
- delete field.templateOptions.extjson;
- }
- //...
- if(field.templateOptions){
- //处理远程获取数据控件方法调用
- if(field.templateOptions.optionsUrl){
- field.templateOptions.refresh = refreshSelectOptions;
- }
- //处理嵌套属性数据绑定/
- if(field.templateOptions.pkey){
- var pmodel,i= 0;
- angular.forEach(field.templateOptions.pkey.split("."),function(p){
- if(i==0){
- if(result.model[p]==null){
- result.model[p] = {};
- }
- pmodel = result.model[p];
- i++;
- }else{
- if(pmodel[p]==null){
- pmodel[p] = {};
- }
- pmodel = pmodel[p];
- }
- });
- if(pmodel!=null){
- field.model = pmodel;
- if(pmodel[field.key]==null){
- pmodel[field.key] = null;
- }
- }
- }else{
- if(result.model[field.key]==null){
- result.model[field.key] = null;
- }
- }
- //处理弹出框组件初始化
- if(field.type=="ui-input-selectmodal"){
- field.templateOptions.modal = $modal;
- //field.templateOptions.Restangular = Restangular;
- }else if(field.type=="ui-userselect"){
- field.templateOptions.modal = $modal;
- //field.templateOptions.Restangular = Restangular;
- }else if(field.type=="ui-multiuserselect"){
- field.templateOptions.modal = $modal;
- }else if(field.type=="ui-modelselect"){
- field.templateOptions.modal = $modal;
- //field.templateOptions.Restangular = Restangular;
- }else if(field.type=="ui-dropfile"){
- field.templateOptions.fileUploader = new FileUploader({
- url:'/uploader'
- });
- field.templateOptions.taskId = $stateParams.taskId;
- field.templateOptions.processInstanceId = $stateParams.processInstanceId;
- field.templateOptions.userId = $rootScope.user.id;
- //field.ApiService=api_bpm_domain;
- }else if(field.type=="ui-dropfiletable"){
- field.templateOptions.processInstanceId = $stateParams.processInstanceId;
- }
- }
- // console.log(field);
- result.fields.push(field);
- });
- angular.extend($scope.vm.fields,result.fields);
- angular.extend($scope.vm.model,result.model);
- $scope.formData = vmForm;
- //console.log($scope.vm);
- //解析设计数据生成表单项 end
- return result;
- }
- //======================处理表单设计数据 结束========================
- $scope.closeModel = function(){
- console.log("pdKey="+pdKey);
- if(pdKey=="incident") {
- $state.go('app.incident.list',{ });
- }else if(pdKey=="change"){
- $state.go('app.change.list',{ });
- }else if(pdKey=="problem"){
- $state.go('app.problem.list',{ });
- }else if(pdKey=="release"){
- $state.go('app.release.list',{ });
- }else if(pdKey=="schedule"){
- $state.go('app.scheduling.list',{ });
- }else if(pdKey=="configure"){
- $state.go('app.cmdb.plist',{ });
- }else if(pdKey=="serviceCatalogueProcessActual"){
- $state.go('app.reService.manager',{ });
- };
- event.preventDefault();
- } ;
- vm.submit = function(data, style){
-
- };
- $scope.vm = vm;
- var dataId = $stateParams.dataId;
- var pdKey = $stateParams.pdKey;
- var detailFormKey = $stateParams.formKey;
- if(angular.isDefined(detailFormKey)&&detailFormKey!=""){
- //console.log("formKey>>"+detailFormKey);
- // editor process task form
- var dataId = parseInt(dataId);
- if(angular.isDefined(dataId)&&dataId!=""){
- api_bpm_data.fetchData(pdKey, dataId).then(function(response){
- if(response){
- var myData = Restangular.stripRestangular(response);
- var processInstanceId = myData.data.processInstanceId;
- //$scope.vm.model[pdKey]=myData.data;
- api_configure_form.renderForm(detailFormKey,'00000',processInstanceId).then(function(responseData){
- if(responseData){
- // console.log("responseData>>>");console.log(responseData);
- var vmForm = Restangular.stripRestangular(responseData);
- if(vmForm){
- //console.log("vmForm>>>");console.log(vmForm);
- var modelData = {};
- modelData[pdKey]=vmForm.model;
- decodeVMForm(vmForm, modelData);
- }
- }
- });
- }
- })
- }
-
-
-
-
- }else{
- // create process instance
- if(pdKey!=""){//for process
- api_bpm_domain.startformkey(pdKey).then(function(response){
- if(response){
- var myData = Restangular.stripRestangular(response);
- api_configure_form.renderForm(myData.data).then(function(responseData){
- if(responseData){
- var vmForm = Restangular.stripRestangular(responseData);
- if(vmForm){
- decodeVMForm(vmForm);
- console.log($scope);
- }
- }
- });
- }
- });
- }else{//for form
- //TODO
- //测试数据 开始
- var testJson = {
- fields : [
- {
- key: 'formtitle',
- type: 'ui-title',
- noFormControl: true,
- 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(val,opt,el,ev,model){alert(val);}
- },
- 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(val,opt,el,ev,model){alert(val);}
- },
- 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:true,
- maxLength:10
- }
- },
- {
- key: 'password',
- type: 'ui-input',
- className:'col-xs-6',
- templateOptions: {
- type: 'password',
- label: 'Password',
- placeholder: 'Password',
- required:true
- },
- 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:false,
- selLeafs:false,//只选叶子节点
- refreshData: function(APIService){
- return APIService.fetchDataList('changeclassify',{'idx':0,'sum':100});
- },
- APIService:api_bpm_data,
- optionsDataKey:'list',
- refreshDelay:1000,
- onDataCallback:function(item, selectItems, options, field, model){
- model[options.key]={id:item.id};
- }
- }
- },
- {
- key:'selectItem',
- type:'ui-select',
- className:'col-xs-4',
- templateOptions:{
- label:'ui-select',
- valueProp: 'code',//对应value
- labelProp: 'source',//对应key
- optionsUrl:'data/fetchDataList/incidentsource',//对应后台地址,api/之前的部分省略
- optionsDataKey:'list',//对应返回数组数据的键值,
- required:true,
- onChange:function(val, options, field, event ,model){
- model.start_code = val;
- }
- }
- },
- {
- key:'multiselectItem',
- type:'ui-multiselect',
- className:'col-xs-4',
- templateOptions:{
- label:'multi-select',
- valueProp: 'code',//对应value
- labelProp: 'source',//对应key
- optionsUrl:'data/fetchDataList/incidentsource',//对应后台地址,api/之前的部分省略
- optionsDataKey:'list',//对应返回数组数据的键值,
- required:true,
- onChange:function(val, options, field, event ,model){
- console.log(val);
- console.log(model);
- //model.start_code = val;
- }
- }
- },
- {
- 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(filterData, APIService){
- return APIService.fetchDataList('user',filterData);
- },
- Restangular:Restangular,
- ApiService:api_user_data,
- onClick:function(val, options, field, event , model){
- //model.start_code++;
- console.log(options);
- }
- }
- },
- {
- key:'cabUser',
- type:'ui-multiuserselect',
- className:'col-xs-12',
- templateOptions:{
- label:'CAB评审成员',
- modalTitle:'CAB成员列表',
- fetchItems:function(filterData, APIService){
- return APIService.fetchDataList('user',filterData);
- },
- Restangular:Restangular,
- ApiService:api_user_data,
- onClick:function(val, options, field, event , model){
- console.log(model);
- }
- }
- },
- {
- key:'incident',
- type:'ui-modelselect',
- className:'col-xs-3',
- templateOptions:{
- label:'关联事件工单',
- modalTitle:'事件列表',
- fetchItems:function(filterData,APIService){
- return APIService.fetchDataList('incident',filterData);
- },
- Restangular:"Restangular",
- ApiService:"api_bpm_data",
- columnDefs:[
- { name:'id', width:80, enableFiltering:false},
- { 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(val, options, field, event , model){
- //model.start_code++;
- console.log(options);
- }
- }
- },
- {
- key: 'worknumber',
- type: 'ui-workernumber',
- className:'col-xs-3',
- templateOptions: {
- label: 'work number',
- Restangular:Restangular,
- ApiService:api_bpm_domain,
- getWorkernumber: function(APIService){
- return APIService.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(val, options, field, event ,model){
- if(angular.isUndefined(field.form.dropState)){
- field.form.dropState=false;
- }
- field.form.dropState=!field.form.dropState;
- console.log(field);
- }
- }
- },
- {
- 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(val, options, field, event ,model){
- model.start_code++;
- console.log(options);
- }
- }
- }
- ],
- model : {
- username:"robin lau",
- password:"123456",
- chkme:false,start_code:0,
- formtitle:"Hey!I am title value!",
- name:{
- first:"robin",last:"lau"
- },
- multiselectItem:[]
- //date:"2015-09-15 00:00:00"
- }
- };
- setTimeout(function(){
- decodeVMForm(testJson);
- $scope.$apply();
- },500);
- //测试数据结束
- }
- }
- }]);
|