123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613 |
- MWF.xDesktop.requireApp("process.Xform", "Personfield", null, false);
- MWF.require("MWF.widget.O2Identity", null,false);
- MWF.xDesktop.requireApp("Selector", "package", null, false);
- MWF.xApplication.process.Xform.Orgfield = MWF.APPOrgfield = new Class({
- Extends: MWF.APPPersonfield,
- iconStyle: "orgfieldIcon",
- loadDescription: function(){
- if (this.isReadonly())return;
- var v = this._getBusinessData();
- if (!v || !v.length){
- if (this.json.description){
- var size = this.node.getFirst().getSize();
- var w = size.x-3;
- if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ) {
- if (COMMON.Browser.safari) w = w - 20;
- }
- this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
- this.descriptionNode.setStyles({
- "width": ""+w+"px",
- "height": ""+size.y+"px",
- "line-height": ""+size.y+"px"
- });
- this.setDescriptionEvent();
- }
- }
- },
- setDescriptionEvent: function(){
- if (this.descriptionNode){
- this.descriptionNode.addEvents({
- "mousedown": function( ev ){
- this.descriptionNode.setStyle("display", "none");
- this.clickSelect( ev );
- }.bind(this)
- });
- }
- },
- _loadUserInterface: function(){
- this.field = true;
- this._loadNode();
- if (this.json.compute == "show"){
- this._setValue(this._computeValue());
- }else{
- this._loadValue();
- }
- },
- _loadNode: function(){
- if (this.isReadonly()){
- this._loadNodeRead();
- }else{
- this._getOrgOptions();
- if (this.json.isInput){
- this._loadNodeInputEdit();
- }else{
- this._loadNodeEdit();
- }
- }
- },
- _getOrgOptions: function(){
- var selectType = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
- if( selectType.contains("unit") || selectType.contains("identity")){
- this.selectUnits = this.getSelectRange();
- if (this.json.range!=="all"){
- if (!this.selectUnits.length){
- this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
- return false;
- }
- }
- }else{
- this.selectUnits = [];
- }
- },
- _loadNodeRead: function(){
- this.node.empty();
- this.node.setStyle("overflow" , "hidden");
- this.node.set({
- "nodeId": this.json.id,
- "MWFType": this.json.type
- });
- var node = new Element("div").inject(this.node);
- },
- _searchConfirmPerson: function(item){
- var inforNode = item.inforNode || new Element("div");
- if (item.data){
- var text = "";
- var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- text = item.data.name+"("+item.data.unitName+")";
- break;
- case "@p":
- text = item.data.name+ (item.data.employee ? "("+item.data.employee+")" : "");
- break;
- case "@u":
- text = item.data.levelName;
- break;
- case "@g":
- text = item.data.name;
- break;
- default:
- text = item.data.name;
- }
- inforNode.set({
- "styles": {"font-size": "14px", "color": ""},
- "text": text
- });
- }else{
- inforNode.set({
- "styles": {"font-size": "14px", "color": "#bd0000"},
- "text": MWF.xApplication.process.Xform.LP.noOrgObject
- });
- }
- if (!item.inforNode){
- new mBox.Tooltip({
- content: inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: item.node,
- transition: 'flyin'
- });
- item.inforNode = inforNode;
- }
- },
- _searchOptions: function(value, callback){
- var selectType = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
- var options = {
- "type" : "",
- "types": selectType,
- "units": this.selectUnits, //范围
- "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
- };
- if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
- this.comboxFilter.filter(value, function(data){
- data.map(function(d){
- var value = Object.clone(d);
- d.value = value;
- var flag = d.distinguishedName.substr(d.distinguishedName.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- d.text = d.name+"("+d.unitName+")";
- break;
- case "@p":
- d.text = d.name+(d.employee ? "("+d.employee+")" : "");
- break;
- case "@u":
- d.text = d.name;
- break;
- case "@g":
- d.text = d.name;
- break;
- default:
- d.text = d.name;
- }
- });
- if (callback) callback(data);
- });
- },
- _resetNodeInputEdit: function(){
- var node = new Element("div", {
- "styles": {
- "overflow": "hidden",
- //"position": "relative",
- "margin-right": "20px"
- }
- }).inject(this.node, "after");
- this.node.destroy();
- this.node = node;
- },
- _loadNodeInputEdit: function(){
- var input=null;
- MWF.require("MWF.widget.Combox", function(){
- this.combox = input = new MWF.widget.Combox({
- "count": this.json.count || 0,
- "splitShow": this.json.splitShow || ", ",
- "onCommitInput": function(item){
- this._searchConfirmPerson(item);
- //this.fireEvent("change");
- }.bind(this),
- "onChange": function(){
- this._setBusinessData(this.getInputData());
- this.fireEvent("change");
- }.bind(this),
- "optionsMethod": this._searchOptions.bind(this)
- });
- }.bind(this), false);
- input.setStyles({
- "background": "transparent",
- "border": "0px"
- });
- input.set(this.json.properties);
- if (!this.json.preprocessing) this._resetNodeInputEdit();
- this.node.empty();
- input.inject(this.node);
- this.node.set({
- "id": this.json.id,
- "MWFType": this.json.type
- });
- if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
- this.iconNode = new Element("div", {
- "styles": this.form.css[this.iconStyle],
- "events": {
- "click": function (ev) {
- this.clickSelect( ev );
- }.bind(this)
- //this.clickSelect.bind(this)
- }
- }).inject(this.node, "before");
- }else if( this.form.json.nodeStyleWithhideModuleIcon ){
- this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
- }
- this.combox.addEvent("change", function(){
- this.validationMode();
- if (this.validation()) this._setBusinessData(this.getInputData("change"));
- }.bind(this));
- },
- _resetNodeEdit: function(){
- var input = new Element("div", {
- "styles": {
- "background": "transparent",
- "border": "0px",
- "min-height": "24px"
- }
- });
- var node = new Element("div", {"styles": {
- "overflow": "hidden",
- "position": "relative",
- "margin-right": "20px",
- "min-height": "24px"
- }}).inject(this.node, "after");
- input.inject(node);
- this.node.destroy();
- this.node = node;
- },
- _loadNodeEdit : function(){
- if (!this.json.preprocessing) this._resetNodeEdit();
- var input = this.node.getFirst();
- input.set(this.json.properties);
- this.node.set({
- "id": this.json.id,
- "MWFType": this.json.type,
- "readonly": true
- });
- if( !this.readonly ) {
- this.node.setStyle("cursor" , "pointer");
- this.node.addEvents({
- "click": function (ev) {
- this.clickSelect( ev );
- }.bind(this)
- //this.clickSelect.bind(this)
- });
- if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
- this.iconNode = new Element("div", { //this.form.css[this.iconStyle],
- "styles": {
- "background": "url(" + "../x_component_process_Xform/$Form/default/icon/selectorg.png) center center no-repeat",
- "width": "18px",
- "height": "18px",
- "float": "right"
- }
- }).inject(this.node, "before");
- }else if( this.form.json.nodeStyleWithhideModuleIcon ){
- this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
- }
- if (this.iconNode){
- this.iconNode.setStyle("cursor" , "pointer");
- this.iconNode.addEvents({
- "click": function (ev) {
- this.clickSelect( ev );
- }.bind(this)
- //this.clickSelect.bind(this)
- });
- }
- }
- },
- getValue: function(){
- var value = this._getBusinessData();
- if( typeOf( value ) === "array" ){
- if( value.length === 0 )value = this._computeValue();
- }else if (!value){
- value = this._computeValue();
- }
- return value || "";
- },
- isEmpty: function(){
- var data = this.getData();
- if( typeOf(data) !== "array" )return true;
- if( data.length === 0 )return true;
- return false;
- },
- getData: function(when){
- if (this.json.compute == "save") this._setValue(this._computeValue());
- return this._getBusinessData();
- },
- getInputData: function(){
- if (this.json.isInput){
- if (this.combox) return this.combox.getData();
- return this._getBusinessData();
- }else{
- return this._getBusinessData();
- }
- },
- addData: function(value){
- if (!value) return false;
- value.each(function(v){
- var vtype = typeOf(v);
- if (vtype==="string"){
- var data;
- this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true); }.bind(this), null, v, false);
- if (data) this.combox.addNewValue(this.getDataText(data), data);
- }
- if (vtype==="object"){
- this.combox.addNewValue(this.getDataText(v), v);
- }
- }.bind(this));
- },
- setData: function(data) {
- this._setValue(data);
- },
- _computeValue: function(){
- var values = [];
- if (this.json.identityValue) {
- this.json.identityValue.each(function(v){ if (v) values.push(v)});
- }
- if (this.json.unitValue) {
- this.json.unitValue.each(function(v){ if (v) values.push(v)});
- }
- if (this.json.defaultValue && this.json.defaultValue.code){
- var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
- if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
- fd.each(function(fdd){
- if (fdd){
- if (typeOf(fdd)==="string"){
- var data;
- this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true); }.bind(this), null, fdd, false);
- values.push(data);
- }else{
- values.push(fdd);
- }
- }
- }.bind(this));
- }
- if (this.json.count>0){
- return values.slice(0, this.json.count);
- }
- return values;
- },
- _getBusinessData: function(){
- if (this.json.section=="yes"){
- var data = this._getBusinessSectionData();
- }else {
- var data = this.form.businessData.data[this.json.id] || "";
- }
- if (typeOf( data ) != "array"){
- if (data) return [data];
- return [];
- }else{
- return data;
- }
- },
- creteShowNode: function(data, islast){
- var nodeText = (data.text) ? data.text : data;
- if (!islast) nodeText = nodeText + (this.json.splitStr || ", ");
- var node = new Element("div", {
- "styles": {
- "float": "left",
- "margin-right": "5px"
- },
- "text": nodeText
- });
- var text = "";
- if (data.value){
- var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- text = data.value.name+"("+data.value.unitName+")";
- break;
- case "@p":
- text = data.value.name+ (data.value.employee ? "("+data.value.employee+")" : "");
- break;
- case "@u":
- text = data.value.levelName;
- break;
- case "@g":
- text = data.value.name;
- break;
- default:
- text = data.value.name;
- }
- var inforNode = new Element("div").set({
- "styles": {"font-size": "14px", "color": ""},
- "text": text
- });
- new mBox.Tooltip({
- content: inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: node,
- transition: 'flyin'
- });
- }
- return node;
- },
- _setValue: function(value){
- if (value.length==1 && !(value[0])) value=[];
- var values = [];
- var comboxValues = [];
- var type = typeOf(value);
- if (type==="array"){
- value.each(function(v){
- var data=null;
- var vtype = typeOf(v);
- if (vtype==="string"){
- var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
- this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true); }.bind(this), error, v, false);
- }
- if (vtype==="object") data = v;
- if (data){
- values.push(data);
- comboxValues.push({"text": this.getDataText(data),"value": data});
- }
- }.bind(this));
- }
- if (type==="string"){
- var vData;
- var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
- this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true); }.bind(this), error, value, false);
- if (vData){
- values.push(vData);
- comboxValues.push({"text": this.getDataText(vData),"value": vData});
- }
- }
- if (type==="object"){
- values.push(value);
- comboxValues.push({"text": this.getDataText(value),"value": value});
- }
- this._setBusinessData(value);
- if (this.json.isInput){
- if (this.combox){
- this.combox.clear();
- this.combox.addNewValues(comboxValues);
- }else{
- var node = this.node.getFirst();
- if (node){
- node.empty();
- comboxValues.each(function(v, i){
- this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
- }.bind(this));
- }
- }
- }else {
- var input = this.node.getFirst();
- if (!input) {
- input = this.node;
- }
- input.empty();
- this.loadOrgWidget(values, input);
- }
- },
- loadOrgWidget: function(value, node){
- var disableInfor = layout.mobile ? true : false;
- if( this.json.showCard === "no" )disableInfor = true;
- var options = {"style": "xform", "canRemove":false , "onRemove" : this.removeItem,"disableInfor" : disableInfor};
- value.each(function(data){
- if( data.distinguishedName ){
- var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- var widget = new MWF.widget.O2Identity(data, node, options );
- break;
- case "@p":
- var widget = new MWF.widget.O2Person(data, node, options);
- break;
- case "@u":
- var widget = new MWF.widget.O2Unit(data, node, options);
- break;
- case "@g":
- var widget = new MWF.widget.O2Group(data, node, options);
- break;
- default:
- var widget = new MWF.widget.O2Other(data, node, options);
- }
- widget.field = this;
- if( layout.mobile ){
- widget.node.setStyles({
- "float" : "none"
- })
- }
- }
- }.bind(this));
- },
- removeItem : function( widget, ev ){
- //this 是 MWF.widget.O2Identity 之类的对象
- var _self = this.field; //这个才是Readerfield
- var dn = this.data.distinguishedName;
- var data = _self._getBusinessData();
- var index;
- data.each( function ( d , i){
- if( d.distinguishedName == dn ){
- index = i
- }
- });
- data.splice( index, 1 );
- _self._setBusinessData( data );
- this.node.destroy();
- ev.stopPropagation();
- },
- _loadValue: function(){
- this._setValue(this.getValue());
- },
- clickSelect: function( ev ){
- this.validationMode();
- var count = (this.json.count) ? this.json.count : 0;
- var selectType = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
- // if( selectType.contains("unit") || selectType.contains("identity")){
- // var selectUnits = this.getSelectRange();
- // if (this.json.range!=="all"){
- // if (!selectUnits.length){
- // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
- // return false;
- // }
- // }
- // }else{
- // var selectUnits = [];
- // }
- var selectUnits = this.selectUnits;
- if( !selectType[0] ){
- this.form.notice(MWF.xApplication.process.Xform.LP.noSelectType, "error", this.node);
- return false;
- }
- var exclude = [];
- if( this.json.exclude ){
- var v = this.form.Macro.exec(this.json.exclude.code, this);
- exclude = typeOf(v)==="array" ? v : [v];
- }
- var options = {
- "type" : "",
- "types": selectType,
- "values" : (this.json.isInput) ? [] : this._getBusinessData(),
- "count": count,
- "units": selectUnits, //范围
- "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
- "exclude" : exclude,
- "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
- //"expand" : false,
- "onComplete": function(items, itemsObject){
- var values = [];
- items.each( function(it){
- values.push(MWF.org.parseOrgData(it.data));
- });
- if (this.json.isInput){
- this.addData(values);
- }else{
- this.setData(values);
- }
- //this.setData( values );
- this.validation();
- this.fireEvent("select");
- }.bind(this),
- "onCancel": function(){
- this.validation();
- }.bind(this),
- "onLoad": function(){
- if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
- }.bind(this),
- "onClose": function(){
- //var v = this.node.getFirst().get("value");
- var v = this.getInputData();
- if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
- }.bind(this)
- };
- if( this.form.json.selectorStyle )options = Object.merge( options, this.form.json.selectorStyle );
- if( this.selector && this.selector.loading ) {
- }else if( this.selector && this.selector.selector && this.selector.selector.active ){
- }else{
- this.selector = new MWF.O2Selector(this.form.app.content, options);
- }
- },
- _loadStyles: function(){
- if (this.isReadonly()){
- if (this.json.styles) this.node.setStyles(this.json.styles);
- }else{
- if (this.json.styles) this.node.setStyles(this.json.styles);
- if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
- if (this.iconNode && this.iconNode.offsetParent !== null ){
- var size = this.node.getSize();
- this.iconNode.setStyle("height", ""+size.y+"px");
- }
- }
- }
- });
|