mwf.xdesktop.requireapp("process.xform", "$input", null, false);
mwf.xdesktop.requireapp("selector", "package", null, false);
mwf.require("mwf.widget.o2identity", null, false);
/** @class org 人员组织组件。
* @o2cn 人员组织组件
* @example
* //可以在脚本中获取该组件
* //方法1:
* var field = this.form.get("fieldid"); //获取组件对象
* //方法2
* var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
*
* var data = field.getdata(); //获取值
* field.setdata(value); //设置值
* field.hide(); //隐藏字段
* var id = field.json.id; //获取字段标识
* var flag = field.isempty(); //字段是否为空
* @extends mwf.xapplication.process.xform.$input
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
*/
mwf.xapplication.process.xform.org = mwf.apporg = new class(
/** @lends mwf.xapplication.process.xform.org# */
{
implements: [events],
extends: mwf.app$input,
options: {
/**
* 组件加载前触发。当前组件的queryload事件还没有在form里注册,通过this.form.get("fieldid")不能获取到当前组件,需要用this.target获取当前组件。
* @event mwf.xapplication.process.xform.org#queryload
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 组件加载时触发.
* @event mwf.xapplication.process.xform.org#load
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 组件加载后触发.
* @event mwf.xapplication.process.xform.org#postload
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 当组件值改变时触发。
* @event mwf.xapplication.process.xform.org#change
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 当组件不允许输入(使用人员选择框)时,完成选择人员,并且给组件赋值后执行。
* @event mwf.xapplication.process.xform.org#select
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
"moduleevents": ["load", "queryload", "postload", "change", "select", "removeitem"],
/**
* 人员选择框事件:加载前执行。this.target指向人员选择框。
* @event mwf.xapplication.process.xform.org#queryloadselector
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:加载后执行,由于选择项为异步加载,此时选择项并未加载完成。this.target指向人员选择框。
* @event mwf.xapplication.process.xform.org#postloadselector
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:加载选择框容器节点前执行。this.target指向人员选择框。
* @event mwf.xapplication.process.xform.org#queryloadcategory
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:加载选择框容器节点后执行。this.target指向人员选择框。
* @event mwf.xapplication.process.xform.org#postloadcontent
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:加载分类前执行。this.target指向分类,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#queryloadcategory
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:加载分类后执行。this.target指向分类,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#postloadcategory
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:选择分类后执行。this.target指向分类,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#selectcategory
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:取消选择分类后执行。this.target指向分类,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#unselectcategory
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:展开分类后执行。this.target指向分类,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#expand
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:折叠分类后执行。this.target指向分类,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#collapse
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:加载选择项前执行。this.target指向选择项,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#queryloaditem
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:加载选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#postloaditem
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:选择选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#selectitem
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:取消选择选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
* @event mwf.xapplication.process.xform.org#unselectitem
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 人员选择框事件:在人员选择框点取消时执行。this.target指向人员选择框。
* @event mwf.xapplication.process.xform.org#close
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
"selectorevents" : ["queryloadselector","postloadselector","queryloadcontent","postloadcontent","queryloadcategory","postloadcategory",
"selectcategory", "unselectcategory","queryloaditem","postloaditem","selectitem", "unselectitem","change","expand","collapse","cancel"],
"readonly": true
},
iconstyle: "orgicon",
isreadonly : function(){
var readonly = !!(this.readonly || this.form.json.isreadonly);
if( readonly )return readonly;
if( this.json.isreadonly === "script" ){
if( this.json.readonlyscript && this.json.readonlyscript.code ){
readonly = this.form.macro.exec(this.json.readonlyscript.code, this);
}
}else{
readonly = !!this.json.isreadonly
}
return readonly || !!this.issectionmergeread();
},
gettextdata: function(){
//var value = this.node.get("value");
//var text = this.node.get("text");
var value = this.getvalue();
//var text = (this.node.getfirst()) ? this.node.getfirst().get("text") : this.node.get("text");
var text = [];
if( typeof( value ) === "object" )value = [value];
if( typeof( value ) === "array" ){
value.each(function(v){
if( typeof(v) === "string" ){
text.push(v);
}else{
text.push(v.name ((v.unitname) ? "(" v.unitname ")" : ""));
}
}.bind(this));
return {"value": value || "", "text": [text.join(",")]};
}else{
return {"value": [""], "text": [""]};
}
},
loaddescription: function(){
if (this.isreadonly())return;
if(this.descriptionnode)return;
var v = this._getbusinessdata();
if (!v || !v.length){
if (this.json.description){
var size, w;
if( this.node.offsetparent === null ){ //隐藏
size = { y: 26 }
}else{
size = this.node.getfirst().getsize();
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({
"height": "" size.y "px",
"line-height": "" size.y "px"
});
if( w )this.descriptionnode.setstyles({
"width": "" w "px"
});
this.setdescriptionevent();
}
}
},
setdescriptionevent: function(){
if (this.descriptionnode){
this.descriptionnode.addevents({
"mousedown": function( ev ){
this.descriptionnode.setstyle("display", "none");
if( this.json.isinput ){
if( this.combox ){
if (!this.combox.edititem) this.combox.intoedit(ev);
window.settimeout( function () {
this.combox.input.node.focus();
}.bind(this), 300)
}
}else{
this.clickselect( ev );
}
}.bind(this)
});
}
},
_loadnode: function(){
this.field = true;
if (this.isreadonly()){
this._loadnoderead();
}else{
this._getorgoptions();
if (this.json.isinput){
this._loadnodeinputedit();
}else{
this._loadnodeedit();
}
}
},
_loadmergereadcontentnode: function(contentnode, data){
this.loadorgwidget(data.data, contentnode);
},
_loadmergeeditnodebydefault: function(){
var data = this.getsortedsectiondata();
var businessdata = [];
data.each(function(d){
businessdata = businessdata.concat( d.data || [] );
});
this._setbusinessdata( businessdata );
this._loadnode();
},
_getorgoptions: function(){
this.selecttypelist = typeof( this.json.selecttype ) == "array" ? this.json.selecttype : [this.json.selecttype];
if( this.selecttypelist.contains( "identity" ) ) {
this.identityoptions = new mwf.apporg.identityoptions(this.form, this.json);
}
if( this.selecttypelist.contains( "unit" ) ) {
this.unitoptions = new mwf.apporg.unitoptions(this.form, this.json);
}
if( this.selecttypelist.contains( "group" ) ){
this.groupoptions = new mwf.apporg.groupoptions( this.form, this.json );
}
//this.selectunits = this.getselectrange();
//if (this.json.selecttype=="identity"){
// this.selectdutys = this.getselectrangeduty();
//}
},
_valuemerge: function(values, v){
if (o2.typeof(v)=="function"){
return v.then(function(re){
this._valuemerge(values, re)
}.bind(this), function(){});
}else{
return values.concat(v);
}
},
_computevalue: function(){
var simple = this.json.storerange === "simple";
var values = [];
if (this.json.identityvalue) {
this.json.identityvalue.each(function(v){
if (v) values.push(mwf.org.parseorgdata(v, true, simple))
});
}
if (this.json.unitvalue) {
this.json.unitvalue.each(function(v){ if (v) values.push(mwf.org.parseorgdata(v, true, simple))});
}
if (this.json.dutyvalue) {
var dutys = json.decode(this.json.dutyvalue);
var par;
if (dutys.length){
dutys.each(function(duty){
if (duty.code) par = this.form.macro.exec(duty.code, this);
if (par){
var pars = (o2.typeof(par)=="array") ? par : [par];
var promise = promise.all(pars).then(function(p){
var uname = p.distinguishedname || p;
if (o2.typeof(p)=="array") uname = p[0].distinguishedname || p[0];
var code = "return this.org.getduty(\"" duty.name "\", \"" uname "\", true)";
var r = (!!uname) ? this.form.macro.exec(code, this) : "";
var m = (o2.typeof(r)=="array") ? "all" : "resolve";
return promise[m](r).then(function(d){
if (typeof(d)!=="array") d = (d) ? [d.tostring()] : [];
var arr = [];
d.each(function(dd){
if (dd) arr.push(mwf.org.parseorgdata(dd, true, simple));
});
return arr;
}.bind(this)).catch(function(){
console.log("catch error : can not get duty : " duty.name, "-" uname);
});
}.bind(this), function(){});
values.push(promise);
}
}.bind(this));
}
}
if (this.json.defaultvalue && this.json.defaultvalue.code){
var fd = this.form.macro.exec(this.json.defaultvalue.code, this);
if (o2.typeof(fd)=="array"){
fd.each(function(v){values.push(v);});
}else{
values.push(fd);
}
// if (fd && fd.isag){
// values.push(fd);
// }else{
// 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, simple); }.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;
//return (this.json.defaultvalue.code) ? this.form.macro.exec(this.json.defaultvalue.code, this): (value || "");
},
__computevalue: function(){
var simple = this.json.storerange === "simple";
var values = [];
if (this.json.identityvalue) {
this.json.identityvalue.each(function(v){
if (v) values.push(mwf.org.parseorgdata(v, true, simple))
});
}
if (this.json.unitvalue) {
this.json.unitvalue.each(function(v){ if (v) values.push(mwf.org.parseorgdata(v, true, simple))});
}
if (this.json.dutyvalue) {
var dutys = json.decode(this.json.dutyvalue);
var par;
if (dutys.length){
dutys.each(function(duty){
if (duty.code) par = this.form.macro.exec(duty.code, this);
if (par && par.isag){
var ag = o2.ag.all(par).then(function(p){
var uname = "";
if (p && p.length) uname = p[0].distinguishedname || p[0];
var code = "return this.org.getduty(\"" duty.name "\", \"" uname "\", true)";
var r = this.form.macro.exec(code, this);
o2.ag.all(r).then(function(d) {
//var d = rd[0];
if (typeof(d)!=="array") d = (d) ? [d.tostring()] : [];
var arr = [];
d.each(function(dd){
if (dd) arr.push(mwf.org.parseorgdata(dd, true, simple));
});
return arr;
}.bind(this));
}.bind(this));
values.push(ag);
}else{
var code = "return this.org.getduty(\"" duty.name "\", \"" par "\", true)";
var r = this.form.macro.exec(code, this);
var ag = o2.ag.all(r).then(function(d) {
//var d = rd[0];
if (typeof(d)!=="array") d = (d) ? [d.tostring()] : [];
var arr = [];
d.each(function(dd){
if (dd) arr.push(mwf.org.parseorgdata(dd, true, simple));
});
return arr;
}.bind(this));
values.push(ag);
// if (typeof(d)!=="array") d = (d) ? [d.tostring()] : [];
// d.each(function(dd){if (dd) values.push(mwf.org.parseorgdata(dd, true, simple));});
}
}.bind(this));
}
}
if (this.json.defaultvalue && this.json.defaultvalue.code){
var fd = this.form.macro.exec(this.json.defaultvalue.code, this);
if (fd && fd.isag){
// value.addresolve(function(v){
// this._setbusinessdata(v);
// if (this.node.getfirst()) this.node.getfirst().set("value", v || "");
// if (this.readonly || this.json.isreadonly) this.node.set("text", v);
// }.bind(this));
values.push(fd);
// fd.then(function(v){
// return this._valuemerge(values, v);
// }.bind(this));
// return fd;
}else{
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, simple); }.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;
//return (this.json.defaultvalue.code) ? this.form.macro.exec(this.json.defaultvalue.code, this): (value || "");
},
getorgaction: function(){
if (!this.orgaction) this.orgaction = mwf.actions.get("x_organization_assemble_control");
//if (!this.orgaction) this.orgaction = new mwf.xapplication.selector.actions.restactions();
return this.orgaction;
},
getoptions: function(){
var _self = this;
if( this.selecttypelist.length === 0 )return false;
var values = this.getinputdata() || [];
var exclude = [];
if( this.json.exclude ){
var v = this.form.macro.exec(this.json.exclude.code, this);
exclude = typeof(v)==="array" ? v : [v];
}
//var count = (this.json.count) ? this.json.count : 0;
var identityopt;
if( this.identityoptions ){
identityopt = this.identityoptions.getoptions();
if (this.json.identityrange!=="all"){
if ( !identityopt.nounit && (!identityopt.units || !identityopt.units.length) ){
this.form.notice(mwf.xapplication.process.xform.lp.noidentityselectrange, "error", this.node);
identityopt.disabled = true;
// return false;
}
}
if ( !identityopt.nounit && this.json.dutyrange && this.json.dutyrange!=="all"){
if (!identityopt.dutys || !identityopt.dutys.length){
this.form.notice(mwf.xapplication.process.xform.lp.noidentitydutyselectrange, "error", this.node);
identityopt.disabled = true;
// return false;
}
}
identityopt.values = (this.json.isinput) ? [] : values;
identityopt.exclude = exclude;
if( this.form.json.selectorstyle )identityopt = object.merge( identityopt, this.form.json.selectorstyle );
}
var unitopt;
if( this.unitoptions ){
unitopt = this.unitoptions.getoptions();
if (this.json.unitrange!=="all"){
if ( !unitopt.units || !unitopt.units.length){
this.form.notice(mwf.xapplication.process.xform.lp.nounitselectrange, "error", this.node);
unitopt.disabled = true;
// return false;
}
}
unitopt.values = (this.json.isinput) ? [] : values;
unitopt.exclude = exclude;
if( this.form.json.selectorstyle )unitopt = object.merge( unitopt, this.form.json.selectorstyle );
}
var groupopt;
if( this.groupoptions ){
groupopt = this.groupoptions.getoptions();
groupopt.values = (this.json.isinput) ? [] : values;
groupopt.exclude = exclude;
if( this.form.json.selectorstyle )groupopt = object.merge( groupopt, this.form.json.selectorstyle );
}
//var selectunits = this.getselectrange();
//if (this.json.selecttype=="identity"){
// var selectdutys = this.getselectrangeduty();
//}
//if (this.json.range!=="all"){
// if (!selectunits.length){
// this.form.notice(mwf.xapplication.process.xform.lp.noselectrange, "error", this.node);
// return false;
// }
//}
//if (this.json.selecttype=="identity"){
// if ((this.json.dutyrange) && this.json.dutyrange!=="all"){
// if (!selectdutys || !selectdutys.length){
// this.form.notice(mwf.xapplication.process.xform.lp.noselectrange, "error", this.node);
// return false;
// }
// }
//}
var defaultopt = {};
if( this.json.events && typeof(this.json.events) === "object" ){
object.each(this.json.events, function(e, key){
if (e.code){
if (this.options.selectorevents.indexof(key)!==-1){
if( key === "postloadselector" ) {
this.addevent("loadselector", function (selector) {
return this.form.macro.fire(e.code, selector);
}.bind(this))
}else if( key === "queryloadselector"){
defaultopt["onqueryload"] = function(target){
return this.form.macro.fire(e.code, target);
}.bind(this)
}else{
defaultopt["on" key.capitalize()] = function(target){
return this.form.macro.fire(e.code, target);
}.bind(this)
}
}
}
}.bind(this));
}
if( this.selecttypelist.length === 1 ){
return object.merge( {
"type": this.selecttypelist[0],
"oncomplete": function(items){
this.selectoncomplete(items);
}.bind(this),
"oncancel": this.selectoncancel.bind(this),
// "onload": this.selectonload.bind(this),
"onload": function(){
//this 为 selector
_self.selectonload(this, this.selector );
},
"onclose": this.selectonclose.bind(this)
}, defaultopt, identityopt || unitopt || groupopt )
}else if( this.selecttypelist.length > 1 ){
var options = {
"type" : "",
"types" : this.selecttypelist,
"oncomplete": function(items){
this.selectoncomplete(items);
}.bind(this),
"oncancel": this.selectoncancel.bind(this),
// "onload": this.selectonload.bind(this),
"onload": function(){
//this 为 selector
_self.selectonload(this)
},
"onclose": this.selectonclose.bind(this)
};
if( this.form.json.selectorstyle ){
options = object.merge( options, this.form.json.selectorstyle );
}
if( identityopt )options.identityoptions = object.merge( {}, defaultopt, identityopt );
if( unitopt )options.unitoptions = object.merge( {}, defaultopt, unitopt );
if( groupopt )options.groupoptions = object.merge( {}, defaultopt, groupopt );
return options;
}
//return {
// "type": this.json.selecttype,
// "unittype": (this.json.selectunittype==="all") ? "" : this.json.selectunittype,
// "values": (this.json.isinput) ? [] : values,
// "count": count,
// "units": selectunits,
// "dutys": (this.json.selecttype=="identity") ? selectdutys : [],
// "exclude" : exclude,
// "expandsubenable" : (this.json.expandsubenable=="no") ? false : true,
// "categorytype": this.json.categorytype || "unit",
// "oncomplete": function(items){
// this.selectoncomplete(items);
// }.bind(this),
// "oncancel": this.selectoncancel.bind(this),
// "onload": this.selectonload.bind(this),
// "onclose": this.selectonclose.bind(this)
//};
},
selectoncomplete: function(items){
var array = [];
items.each(function(item){
array.push(item.data);
}.bind(this));
var simple = this.json.storerange === "simple";
this.checkempower( array, function( data ){
var values = [];
data.each(function(d){
values.push(mwf.org.parseorgdata(d, true, simple));
}.bind(this));
if (this.json.isinput){
this.adddata(values);
}else{
this.setdata(values, true);
}
//this._setbusinessdata(values);
this.validationmode();
this.validation();
var p = this.getvalue();
if (p.then){
p.then(function(){
this.fireevent("select");
}.bind(this), function(){});
}else{
this.fireevent("select");
}
}.bind(this))
},
selectoncancel: function(){
this.validation();
},
selectonload: function( selector ){
if (this.descriptionnode) this.descriptionnode.setstyle("display", "none");
this.fireevent("loadselector", [selector])
},
selectonclose: function(){
var v = this._getbusinessdata();
if (!v || !v.length) if (this.descriptionnode) this.descriptionnode.setstyle("display", "block");
},
checkdescription: function(){
if (!this.json.description)return;
var v = this._getbusinessdata();
if (!v || !v.length){
if( this.descriptionnode ){
if( this.node.getfirst() ){
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.setstyles({
"display": "block",
"width": "" w "px",
"height": "" ( size.y || 26) "px",
"line-height": "" ( size.y || 26) "px"
});
}else{
this.descriptionnode.setstyle("display", "block");
}
}else{
this.loaddescription();
}
}else{
if(this.descriptionnode)this.descriptionnode.setstyle("display", "none");
}
},
/**
* @summary 弹出选择界面.
* @example
* this.form.get('org').clickselect();
*/
clickselect: function( ev ){
if (this.isreadonly())return;
if( layout.mobile ){
settimeout( function(){ //如果有输入法界面,这个时候页面的计算不对,所以等100毫秒
var options = this.getoptions();
if(options){
if( this.selector && this.selector.loading ) {
}else if( this.selector && this.selector.selector && this.selector.selector.active ){
}else{
/**
* @summary 人员选择框package的对象
* @member {o2.o2selector}
* @example
* //可以在脚本中获取该组件
* var selector = this.form.get("fieldid").selector.selector; //获取人员选择框对象
* var options = selector.options; //获取人员选择框的选项
*/
this.selector = new mwf.o2selector(this.form.app.content, options);
}
}
}.bind(this), 100 )
}else{
var options = this.getoptions();
if(options){
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);
}
}
}
},
resetdata: function(){
var v = this.getvalue();
//this.setdata((v) ? v.join(", ") : "");
this.setdata(v);
},
isempty: function(){
var data = this.getdata();
if( typeof(data) !== "array" )return true;
if( data.length === 0 )return true;
return false;
},
getinputdata: function(){
if (this.json.isinput){
if (this.combox)return this.combox.getdata();
//return this._getbusinessdata();
return this.node.retrieve("data");
}else{
//return this._getbusinessdata();
return this.node.retrieve("data");
}
},
_loadnoderead: function(){
this.node.empty();
var node = new element("div").inject(this.node);
this.node.set({
"nodeid": this.json.id,
"mwftype": this.json.type
});
},
_searchconfirmperson: function(item){
var infornode = item.infornode || new element("div");
var simple = this.json.storerange === "simple";
if (item.data){
var data = item.data;
if( this.selecttypelist.contains("identity") && this.json.identityresulttype === "person"){
var dn = data.distinguishedname || data;
if( dn.substr( dn.length-1, 1).tolowercase() === "i" ){
mwf.actions.get("x_organization_assemble_express").listpersonwithidentity({
identitylist : [dn]
}, function(json){
if( json.data.length > 0 ){
if( data["person"] )json.data[0].id = data["person"];
item.data = mwf.org.parseorgdata( json.data[0], true, simple );
item.value = this.getdatatext( item.data );
if(item.node)item.node.set("text", item.value);
}
}.bind(this), null, false)
}
}
if( item.data && ( item.data.createtime || item.data.updatetime ) ){
item.data = mwf.org.parseorgdata( item.data, true, simple );
}
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;
}
},
getsearchoptions: function(){
if( this.selecttypelist.length === 0 )return false;
var identityopt;
if( this.identityoptions ){
identityopt = this.identityoptions.getsearchoptions();
//if (this.json.identityrange!=="all"){
// if ( !identityopt.units || !identityopt.units.length){
// this.form.notice(mwf.xapplication.process.xform.lp.noidentityselectrange, "error", this.node);
// return false;
// }
//}
//if ((this.json.dutyrange) && this.json.dutyrange!=="all"){
// if (!identityopt.dutys || !identityopt.dutys.length){
// this.form.notice(mwf.xapplication.process.xform.lp.noidentitydutyselectrange, "error", this.node);
// return false;
// }
//}
}
var unitopt;
if( this.unitoptions ){
unitopt = this.unitoptions.getsearchoptions();
//if (this.json.unitrange!=="all"){
// if ( !unitopt.units || !unitopt.units.length){
// this.form.notice(mwf.xapplication.process.xform.lp.nounitselectrange, "error", this.node);
// return false;
// }
//}
}
var groupopt;
if( this.groupoptions ){
groupopt = this.groupoptions.getoptions();
}
if( this.selecttypelist.length === 1 ){
return object.merge( {
"type": this.selecttypelist[0]
}, identityopt || unitopt || groupopt )
}else if( this.selecttypelist.length > 1 ){
var options = {
"type" : "",
"types" : this.selecttypelist
};
if( identityopt )options.identityoptions = identityopt;
if( unitopt )options.unitoptions = unitopt;
if( groupopt )options.groupoptions = groupopt;
return options;
}
//return {
// "type": this.json.selecttype,
// "unittype": (this.json.selectunittype==="all") ? "" : this.json.selectunittype,
// "values": (this.json.isinput) ? [] : values,
// "count": count,
// "units": selectunits,
// "dutys": (this.json.selecttype=="identity") ? selectdutys : [],
// "exclude" : exclude,
// "expandsubenable" : (this.json.expandsubenable=="no") ? false : true,
// "categorytype": this.json.categorytype || "unit",
// "oncomplete": function(items){
// this.selectoncomplete(items);
// }.bind(this),
// "oncancel": this.selectoncancel.bind(this),
// "onload": this.selectonload.bind(this),
// "onclose": this.selectonclose.bind(this)
//};
},
_searchoptions: function(value, callback){
//var options = {
// "type": this.json.selecttype,
// "unittype": (this.json.selectunittype==="all") ? "" : this.json.selectunittype,
// "units": this.selectunits,
// "dutys": (this.json.selecttype=="identity") ? this.selectdutys : []
//};
var options = this.getsearchoptions();
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": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
//"position": "relative",
"margin-right": this.hasicon() ? "20px" : "0px"
}
}).inject(this.node, "after");
this.node.destroy();
this.node = node;
},
_loadnodeinputedit: function(){
this.node.setstyle("overflow","visible");
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.node.store("data", this.getinputdata());
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.node.store("data", this.getinputdata());
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": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
"position": "relative",
"margin-right": this.hasicon() ? "20px" : "0px",
"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();
if( !input && this.nodehtml ){
this.node.set("html", this.nodehtml);
input = this.node.getfirst();
}
input.set(this.json.properties);
this.node.set({
"id": this.json.id,
"mwftype": this.json.type,
"events": {
"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", {
"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.node.getfirst().setstyle("height", "auto");
this.node.getfirst().addevent("change", function(){
this.validationmode();
if (this.validation()){
this.node.store("data", this.getinputdata());
this._setbusinessdata(this.getinputdata("change"));
}
}.bind(this));
},
getdatatext: function(data){
if (typeof(data)=="string") return data;
if( !data || !data.distinguishedname )return "";
var text = "";
var flag = data.distinguishedname.substr(data.distinguishedname.length-2, 2);
switch (flag.tolowercase()){
case "@i":
text = data.name "(" data.unitname ")";
break;
case "@p":
text = data.name (data.employee ? ("(" data.employee ")") : "");
break;
case "@u":
text = data.name;
break;
case "@g":
text = data.name;
break;
default:
text = data.name;
}
return text;
},
adddata: function(value){
if (!value) return false;
var simple = this.json.storerange === "simple";
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, simple); }.bind(this), null, v, false);
if (data) this.combox.addnewvalue(this.getdatatext(data), data);
}
if (vtype==="object"){
var d = mwf.org.parseorgdata(v, true, simple);
this.combox.addnewvalue(this.getdatatext(d), d);
}
}.bind(this));
},
checkchange: function(oldvalues, values){
var change = false;
if (!values) values = [];
if (oldvalues.length && (values && values.length)){
if (oldvalues.length === values.length){
for (var i=0; i0){
value = value.slice(0, this.json.count);
}
var values = [];
var comboxvalues = [];
var type = typeof(value);
var simple = this.json.storerange === "simple";
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, simple); }.bind(this), error, v, false);
}
if (vtype==="object") data = v;
if (data){
var d = mwf.org.parseorgdata(data, true, simple)
values.push(d);
comboxvalues.push({"text": this.getdatatext(d),"value": d});
}
}.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,simple); }.bind(this), error, value, false);
if (vdata){
values.push(vdata);
comboxvalues.push({"text": this.getdatatext(vdata),"value": vdata});
}
}
if (type==="object"){
var v = mwf.org.parseorgdata(value, true, simple)
values.push(v);
comboxvalues.push({"text": this.getdatatext(v),"value": v});
}
this.node.store("data", values);
this._setbusinessdata(values);
if (this.json.isinput){
if (this.combox){
this.combox.clear();
this.combox.addnewvalues(comboxvalues);
// values.each(function(v){
// if (typeof(v)=="string"){
// this.combox.addnewvalue(v);
// }else{
// this.combox.addnewvalue(this.getdatatext(v), v);
// }
// }.bind(this));
}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{
if (this.node.getfirst()){
var node = this.node.getfirst();
node.empty();
this.loadorgwidget(values, node)
}else{
this.node.empty();
this.loadorgwidget(values, this.node);
}
}
this.checkdescription();
this.fieldmoduleloaded = true;
//if (this.readonly) this.loadorgwidget(values, this.node)
//this.node.set("text", value);
},
getvaluemethod: function(value){
if (value){
var flag = value.substr(value.length-2, 2);
switch (flag.tolowercase()){
case "@i":
return "getidentity";
case "@p":
return "getperson";
case "@u":
return "getunit";
case "@g":
return "getgroup";
default:
return (this.json.selecttype==="unit") ? "getunit" : "getidentity";
}
}
return (this.json.selecttype==="unit") ? "getunit" : "getidentity";
},
loadorgwidget: function(value, node){
var _self = this;
var disableinfor = layout.mobile ? true : false;
if( this.json.showcard === "no" )disableinfor = true;
var canremove = this.json.canremove ? true : false;
var height = node.getstyle("height").toint();
if (node.getstyle("overflow")==="visible" && !height) node.setstyle("overflow", "hidden");
if (value && value.length){
value.each(function(data){
if( !data || !data.distinguishedname )return;
var flag = data.distinguishedname.substr(data.distinguishedname.length-2, 2);
var copydata = object.clone(data);
if( this.json.displaytextscript && this.json.displaytextscript.code ){
this.currentdata = copydata;
var displayname = this.form.macro.exec(this.json.displaytextscript.code, this);
if( displayname ){
copydata.displayname = displayname;
}
this.currentdata = null;
}
var opt = {"style": "xform","lazy":true,"disableinfor" : disableinfor, "canremove":canremove, "onremove": function () {
_self.fireevent("removeitem", [{
data: data,
item: this
}])
}, "styles": this.json.itemstyles || "" };
var widget;
switch (flag.tolowercase()){
case "@i":
widget = new mwf.widget.o2identity(copydata, node, opt);
break;
case "@p":
widget = new mwf.widget.o2person(copydata, node, opt);
break;
case "@u":
widget = new mwf.widget.o2unit(copydata, node, opt);
break;
case "@g":
widget = new mwf.widget.o2group(copydata, node, opt);
break;
default:
widget = new mwf.widget.o2other(copydata, node, opt);
}
widget.field = this;
if( layout.mobile ){
widget.node.setstyles({
"float" : "none"
})
}
}.bind(this));
}
},
_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");
}
}
},
checkempower : function( data, callback ){
if( typeof(data)==="array" && this.identityoptions && this.json.ischeckempower && this.json.identityresulttype === "identity" ) {
var empowerchecker = new mwf.apporg.empowerchecker(this.form, this.json);
empowerchecker.load(data, callback);
}else{
if( callback )callback( data );
}
},
_beforereloaded: function(){
this.selector = null;
if (this.combox) {
this.combox.clear();
this.combox = null;
}
},
getexceldata: function(){
var text, value = this.getdata();
if (o2.typeof(value) === "array") {
var textarray = [];
value.each(function (item) {
if (o2.typeof(item) === "object") {
textarray.push(item.distinguishedname);
} else {
textarray.push(item);
}
}.bind(this));
text = textarray.join(", \n");
} else if (o2.typeof(value) === "object") {
text = value.distinguishedname;
} else {
text = value;
}
return text;
},
setexceldata: function(data){
this.exceldata = data;
this.setdata(data, true);
}
});
mwf.apporg.empowerchecker = new class({
implements: [events],
initialize: function (form, json) {
this.form = form;
this.json = json;
this.css = this.form.css;
this.checkedallitems = true;
},
load : function( data, callback, container ){
if( typeof(data)==="array" && this.json.ischeckempower && this.json.identityresulttype === "identity" ){
var array = [];
data.each( function( d ){
if( d.distinguishedname ){
var flag = d.distinguishedname.substr(d.distinguishedname.length-1, 1).tolowercase();
if( flag === "i" ){
array.push( d.distinguishedname )
}
}
}.bind(this));
if( array.length > 0 ){
o2.actions.get("x_organization_assemble_express").listempowerwithidentity({
"application" : (this.form.businessdata.work || this.form.businessdata.workcompleted).application,
"process" : (this.form.businessdata.work || this.form.businessdata.workcompleted).process,
"work" : (this.form.businessdata.work || this.form.businessdata.workcompleted).id,
"identitylist" : array
}, function( json ){
var arr = [];
json.data.each( function(d){
if(d.fromidentity !== d.toidentity )arr.push(d);
});
if( arr.length > 0 ){
this.openselectempowerdlg( arr, data, callback, container );
}else{
if( callback )callback( data );
}
}.bind(this), function(){
if( callback )callback( data );
}.bind(this))
}else{
if( callback )callback( data );
}
}else{
if( callback )callback( data );
}
},
getignoreempowerarray : function( callback ){
var array = [];
if( this.empowerselectnodes && this.empowerselectnodes.length ){
this.empowerselectnodes.each(function(node){
if( !node.retrieve("isselected") ){
var d = node.retrieve("data");
array.push( d.fromidentity );
}
}.bind(this));
}
if( callback )callback( array );
return array;
},
setignoreempowerflag : function(data, callback){
var ignorelist = this.getignoreempowerarray();
for( var i=0; i -1 ){
d.ignoreempower = true;
}else if( d.ignoreempower ){
delete d.ignoreempower;
}
}
if( callback )callback( data );
},
replaceempoweridentity : function(data, callback){
var empowerdata = {};
this.empowerselectnodes.each(function(node){
if( node.retrieve("isselected") ){
var d = node.retrieve("data");
empowerdata[ d.fromidentity ] = d;
}
}.bind(this));
if( object.keys(empowerdata).length === 0 ){
callback( data );
}else{
var identitylist = [];
for( var key in empowerdata ){
identitylist.push( empowerdata[key].toidentity );
}
o2.actions.get("x_organization_assemble_express").listidentity({ "identitylist" : identitylist }, function(json){
var newdata = data.clone();
var d = {};
json.data.each( function(j){
d[j.distinguishedname] = j;
});
for( var i=0; i -1 ){
d.ignoreempower = true;
}else if( d.ignoreempower ){
delete d.ignoreempower;
}
}
if( callback )callback( orgindata );
// empowerlist.each( function(obj){
// var list = obj.subitemlist.filter(function(item, index){
// return !arr.contains( item.id );
// }.bind(this));
// ignorelist = ignorelist.map(function(item,index){
// return item.id.split("#")[1];
// })
// });
// empowerlist.each( function(obj){
// var org = that.orgitemsobject[obj.orgid];
// // if( obj.ignorelist.length > 0 ){
// var data = org.getdata();
// for( var i=0; i -1 ){
// d.ignoreempower = true;
// }else if( d.ignoreempower ){
// delete d.ignoreempower;
// }
// }
// org.setdata( data );
// }
// if( obj.empowermap ){
// var data = org.getvalue();
// for( var i=0; i" mwf.xapplication.process.xform.lp.empowerdlgtext "
source
";
html = "";
node.set("html", html);
var itemnode = node.getlast();
this.getempoweritems(itemnode, data);
node.inject( container || this.form.app.content);
var dlg = o2.dl.open({
"title": mwf.xapplication.process.xform.lp.selectempower,
"style": this.form.json.dialogstyle || "user",
"isresize": true,
"content": node,
"width": 630,
//"height" : 500,
"buttonlist": [
{
"type" : "ok",
"text": mwf.lp.process.button.ok,
"action": function(d, e){
//this.replaceempoweridentity( orgindata, callback ); //直接替换已授权的人,已废弃
this.setignoreempowerflag( orgindata, callback ); //然后设置忽略的人的标志
dlg.close();
}.bind(this)
},
{
"type" : "cancel",
"text": mwf.lp.process.button.cancel,
"action": function(){dlg.close();}
}
],
"onpostshow": function(){
var selectnode = this.createselectallempowernode();
selectnode.inject( dlg.button );
if( layout.mobile ){
dlg.node.inject( $(document.body) );
dlg.node.setstyles({
"width":"100%",
"height": "100%",
"top" : "0px",
"left" : "0px"
});
var y = dlg.node.getsize().y - 190;
itemnode.setstyle("height",y "px");
dlg.options.contentheight = dlg.node.getsize().y - 100 ; // 100;
dlg.setcontentsize();
}else{
dlg.content.setstyle("overflow","hidden");
var y = math.min(300, itemnode.getsize().y);
var margintop = itemnode.getstyle("margin-top");
var marginbottom = itemnode.getstyle("margin-bottom");
itemnode.setstyle("height",y "px");
dlg.options.contentheight = y 30 20 ; // 100;
dlg.setcontentsize();
dlg.node.setstyles({
"height": "" (dlg.options.height) "px"
});
dlg.recenter();
}
}.bind(this)
});
},
getempoweritems: function(itemnode, data){
var _self = this;
this.empowerselectnodes = [];
var count = 1;
var node;
data.each(function( d ){
if(d.fromidentity == d.toidentity )return;
if( count % 2 === 1 ){
node = new element("div", {"styles": this.css.empoweritemoddnode}).inject(itemnode);
node.store("nodetype","odd");
//node.setstyle("margin-right","10px");
}else{
node = new element("div", {"styles": this.css.empoweritemevennode}).inject(itemnode);
node.store("nodetype","even");
}
count ;
this.empowerselectnodes.push( node );
node.store("data", d);
var iconnode = new element("div.empoweritemiconnode", {"styles": this.css.empoweritemiconnode}).inject(node);
node.store("iconnode",iconnode);
var contentnode = new element("div.empoweritemcontentnode", {"styles": this.css.empoweritemcontentnode}).inject(node);
var formidentitynode = new element("div.empoweritempersonnode", {"styles": this.css.empoweritempersonnode, text : d.fromidentity.split("@")[0] }).inject(contentnode);
var titlenode = new element("div.empoweritemtitlenode", {"styles": this.css.empoweritemtitlenode, text : mwf.xapplication.process.xform.lp.empowerto }).inject(contentnode);
var toidentitynode = new element("div.empoweritempersonnode", {"styles": this.css.empoweritempersonnode, text : d.toidentity.split("@")[0] }).inject(contentnode);
node.addevents({
"mouseover": function(){
var isselected = this.retrieve("isselected");
if (!isselected){
this.setstyles(_self.css[ "empoweritem" this.retrieve("nodetype") "node_over" ]);
if( _self.css.empoweritemiconnode_over ){
var iconnode = this.retrieve("iconnode");
if(iconnode)iconnode.setstyles(_self.css.empoweritemiconnode_over);
}
}
},
"mouseout": function(){
var isselected = this.retrieve("isselected");
if (!isselected){
this.setstyles(_self.css[ "empoweritem" this.retrieve("nodetype") "node" ])
if( _self.css.empoweritemiconnode_over ){
var iconnode = this.retrieve("iconnode");
if(iconnode)iconnode.setstyles(_self.css.empoweritemiconnode);
}
}
},
"click": function(){
var isselected = this.retrieve("isselected");
if (isselected){
_self.unselectempoweritem( this)
}else{
_self.selectempoweritem(this)
}
}
});
if( this.checkedallitems )node.click();
}.bind(this));
},
unselectempoweritem : function( itemnode ){
itemnode.store("isselected", false);
itemnode.setstyles( this.css[ "empoweritem" itemnode.retrieve("nodetype") "node" ] );
itemnode.getelements("div").each( function( div ){
var classname = div.get("class");
if( classname && this.css[classname] )div.setstyles( this.css[classname] )
}.bind(this))
},
selectempoweritem : function( itemnode ){
itemnode.store("isselected", true);
itemnode.setstyles( this.css[ "empoweritem" itemnode.retrieve("nodetype") "node_selected" ] );
itemnode.getelements("div").each( function( div ){
var classname = div.get("class");
if( classname && this.css[classname "_selected"] )div.setstyles( this.css[classname "_selected"] )
}.bind(this))
},
createselectallempowernode : function(){
var _self = this;
var node = new element("div", {
styles : this.css.empowerselectallitemnode,
text : mwf.xapplication.process.xform.lp.selectall
});
node.addevents({
"mouseover": function(){
var isselected = this.retrieve("isselected");
if (!isselected) this.setstyles(_self.css.empowerselectallitemnode_over);
},
"mouseout": function(){
var isselected = this.retrieve("isselected");
if (!isselected) this.setstyles(_self.css.empowerselectallitemnode)
},
"click": function(){
var isselected = this.retrieve("isselected");
if (isselected){
this.store("isselected", false);
this.setstyles( _self.css.empowerselectallitemnode );
_self.empowerselectnodes.each( function(itemnode){
_self.unselectempoweritem(itemnode)
}.bind(this))
}else{
this.store("isselected", true);
this.setstyles( _self.css.empowerselectallitemnode_selected );
_self.empowerselectnodes.each( function(itemnode){
_self.selectempoweritem(itemnode)
}.bind(this))
}
}
});
if( this.checkedallitems ){
node.store("isselected", true);
node.setstyles( _self.css.empowerselectallitemnode_selected );
}
return node;
}
});
mwf.apporg.groupoptions = new class({
implements: [events],
initialize: function (form, json) {
this.form = form;
this.json = json;
this.orgaction = mwf.actions.get("x_organization_assemble_control");
},
getoptions: function(){
var count = (this.json.groupcount) ? this.json.groupcount : 0;
if( this.json.grouprange==="group" ){
return {
"count": count,
"storerange" : this.json.storerange,
"include": this.getselectrange( true )
}
}else{
return {
"count": count,
"storerange" : this.json.storerange
}
}
},
getsearchoptions : function(){
return {};
},
getselectrange : function( refresh ){
if( !this.selectrange || refresh){
this.selectrange = this._getselectrange();
}
return this.selectrange;
},
_getselectrange : function(){
var rangevalues = [];
if (this.json.grouprangekey && this.json.grouprangekey.code){
var v = this.form.macro.exec(this.json.grouprangekey.code, this);
if (typeof(v)!=="array") v = (v) ? [v.tostring()] : [];
rangevalues = v;
//v.each(function(d){
// if (d){
// if (typeof(d)==="string"){
// var data;
// this.orgaction.getgroup(function(json){ data = json.data }.bind(this), null, d, false);
// rangevalues.push(data);
// }else{
// rangevalues.push(d);
// }
// }
//}.bind(this));
}
return rangevalues;
}
});
mwf.apporg.unitoptions = new class({
implements: [events],
initialize : function( form, json ){
this.form = form;
this.json = json;
this.orgaction = mwf.actions.get("x_organization_assemble_control");
},
getoptions: function(){
var count = (this.json.unitcount) ? this.json.unitcount : 0;
var selectunits = this.getselectrange( true );
return {
"count": count,
"units": selectunits,
"unittype": (this.json.selectunittype==="all") ? "" : this.json.selectunittype,
"storerange" : this.json.storerange,
"expandsubenable" : (this.json.unitexpandsubenable==="no") ? false : true,
"firstlevelselectable":this.json.firstlevelselectable==="yes"
};
},
getsearchoptions : function(){
var selectunits = this.getselectrange( true );
return {
"units": selectunits,
"unittype": (this.json.selectunittype==="all") ? "" : this.json.selectunittype
};
},
getselectrange : function( refresh ){
if( !this.selectrange || refresh){
this.selectrange = this._getselectrange();
}
return this.selectrange;
},
_getselectrange : function(){
if (this.json.unitrange==="unit"){
return this.getscriptselectunit();
}
if (this.json.unitrange==="draftunit"){
var dn = (this.form.businessdata.work || this.form.businessdata.workcompleted).creatoridentitydn;
if (!dn){
if ( layout.session.user.identitylist && layout.session.user.identitylist.length){
var ids = [];
layout.session.user.identitylist.each(function(id){ ids.push(id.id); });
return this.getnextselectunit(ids);
}else{
return [];
}
}else{
return this.getnextselectunit((this.form.businessdata.work || this.form.businessdata.workcompleted).creatoridentitydn);
}
}
if (this.json.unitrange==="currentunit"){
if (this.form.app.currenttask){
return this.getnextselectunit(this.form.app.currenttask.identitydn);
}else{
if (this.form.app.tasklist && this.form.app.tasklist.length){
var ids = [];
this.form.app.tasklist.each(function(task){ ids.push(task.identity); });
return this.getnextselectunit(ids);
}else{
if ( layout.session.user.identitylist && layout.session.user.identitylist.length){
var ids = [];
layout.session.user.identitylist.each(function(id){ ids.push(id.id); });
return this.getnextselectunit(ids);
}else{
return [];
}
}
}
}
return [];
},
getscriptselectunit: function(){
var rangevalues = [];
if (this.json.unitrangeunit && this.json.unitrangeunit.length){
this.json.unitrangeunit.each(function(unit){
//var unitflag = unit.distinguishedname || unit.id || unit.unique || unit.levelname;
//if (unitflag) rangevalues.push(unitflag);
rangevalues.push(unit);
}.bind(this));
}
if (this.json.unitrangefield && this.json.unitrangefield.length){
this.json.unitrangefield.each(function(field){
var n = (typeof(field)=="object") ? field.name : field;
var v = this.form.businessdata.data[n];
if (typeof(v)!=="array") v = (v) ? [v.tostring()] : [];
v.each(function(d){
if (d){
// if (typeof(d)==="string"){
// var data;
// this.orgaction.getunit(function(json){ data = json.data }.bind(this), null, d, false);
// rangevalues.push(data);
// }else{
rangevalues.push(d);
// }
}
}.bind(this));
}.bind(this));
}
if (this.json.unitrangekey && this.json.unitrangekey.code){
var v = this.form.macro.exec(this.json.unitrangekey.code, this);
if (typeof(v)!=="array") v = (v) ? [v.tostring()] : [];
v.each(function(d){
if (d){
// if (typeof(d)==="string"){
// var data;
// this.orgaction.getunit(function(json){ data = json.data }.bind(this), null, d, false);
// rangevalues.push(data);
// }else{
rangevalues.push(d);
// }
}
}.bind(this));
}
return rangevalues;
},
getnextselectunit: function(id){
var ids = typeof(id)==="array" ? id : [id];
var data;
var units = [];
ids.each( function(i){
if (this.json.unitrangenext === "direct"){
this.orgaction.getidentity(function(json){ data = json.data }.bind(this), function(){data={"wounit": null}}, i, false);
if (data && data.wounit) units.push(data.wounit);
}else if(this.json.unitrangenext==="level"){
this.orgaction.getunitwithidentitywithlevel(i, this.json.unitrangenextlevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
if (data) units.push(data);
}else if (this.json.unitrangenext==="type"){
if (this.json.unitrangenextunittype==="all"){
this.orgaction.getunitwithidentitywithlevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
}else{
this.orgaction.getunitwithidentitywithtype(i, this.json.unitrangenextunittype, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
}
if (data) units.push(data);
}
data = null;
}.bind(this));
return units;
//if (this.json.unitrangenext === "direct"){
// if (typeof(id)==="array"){
// var units = [];
// id.each(function(i){
// this.orgaction.getidentity(function(json){ data = json.data }.bind(this), function(){data={"wounit": null}}, i, false);
// if (data && data.wounit) units.push(data.wounit);
// data = null;
// }.bind(this));
// return units;
// }else{
// this.orgaction.getidentity(function(json){ data = json.data }.bind(this), function(){data={"wounit": null}}, id, false);
// return (data.wounit) ? [data.wounit] : [];
// }
//}
//if (this.json.unitrangenext==="level"){
// this.orgaction.getunitwithidentitywithlevel(id, this.json.unitrangenextlevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
// //this.json.rangenextlevel
// return (data) ? [data] : [];
//}
//if (this.json.unitrangenext==="type"){
// if (this.json.unitrangenextunittype==="all"){
// this.orgaction.getunitwithidentitywithlevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
// }else{
// this.orgaction.getunitwithidentitywithtype(id, this.json.unitrangenextunittype, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
// }
//
// return (data) ? [data] : [];
//}
}
});
mwf.apporg.identityoptions = new class({
implements: [events],
initialize : function( form, json ){
this.form = form;
this.json = json;
this.orgaction = mwf.actions.get("x_organization_assemble_control");
},
getoptions: function(){
var count = (this.json.identitycount) ? this.json.identitycount : 0;
if( this.json.identityonlyuseinclude ){
return {
"nounit" : true,
"count": count,
"resulttype" : this.json.identityresulttype,
"storerange" : this.json.storerange,
"include" : this._getinclude()
};
}else{
var selectunits = this.getselectrange( true );
var selectdutys = this.getselectrangeduty( true );
return {
"count": count,
"units": selectunits,
"unittype": this.json.unittype || "",
"dutys": selectdutys,
"expandsubenable" : (this.json.identityexpandsubenable=="no") ? false : true,
"resulttype" : this.json.identityresulttype,
"categorytype": this.json.categorytype || "unit",
"dutyunitlevelby" : this.json.dutyunitlevelby || "duty",
"storerange" : this.json.storerange,
"include" : this._getinclude()
};
}
},
getsearchoptions : function(){
var selectunits = this.getselectrange( true );
var selectdutys = this.getselectrangeduty( true );
return {
"units": selectunits,
"dutys": selectdutys,
"resulttype" : this.json.identityresulttype
};
},
getselectrange : function( refresh ){
if( !this.selectrange || refresh ){
this.selectrange = this._getselectrange();
}
return this.selectrange;
},
_getinclude : function(){
var include = [];
if( this.json.identityincludekey ){
var v = this.form.macro.exec(this.json.identityincludekey.code, this);
if( v )include = typeof(v)==="array" ? v : [v];
}
return include;
},
_getselectrange : function(){
if (this.json.identityrange==="unit"){
return this.getscriptselectunit();
}
if (this.json.identityrange==="draftunit"){
var dn = (this.form.businessdata.work || this.form.businessdata.workcompleted).creatoridentitydn;
if (!dn){
if ( layout.session.user.identitylist && layout.session.user.identitylist.length){
var ids = [];
layout.session.user.identitylist.each(function(id){ ids.push(id.id); });
return this.getnextselectunit(ids);
}else{
return [];
}
}else{
return this.getnextselectunit((this.form.businessdata.work || this.form.businessdata.workcompleted).creatoridentitydn);
}
}
if (this.json.identityrange==="currentunit"){
if (this.form.app.currenttask){
return this.getnextselectunit(this.form.app.currenttask.identitydn);
}else{
if (this.form.app.tasklist && this.form.app.tasklist.length){
var ids = [];
this.form.app.tasklist.each(function(task){ ids.push(task.identity); });
return this.getnextselectunit(ids);
}else{
if ( layout.session.user.identitylist && layout.session.user.identitylist.length){
var ids = [];
layout.session.user.identitylist.each(function(id){ ids.push(id.id); });
return this.getnextselectunit(ids);
}else{
return [];
}
}
}
}
return [];
},
getscriptselectunit: function(){
var rangevalues = [];
if (this.json.identityrangeunit && this.json.identityrangeunit.length){
this.json.identityrangeunit.each(function(unit){
//var unitflag = unit.distinguishedname || unit.id || unit.unique || unit.levelname ;
//if (unitflag) rangevalues.push(unitflag);
rangevalues.push(unit);
}.bind(this));
}
if (this.json.identityrangefield && this.json.identityrangefield.length){
this.json.identityrangefield.each(function(field){
var n = (typeof(field)=="object") ? field.name : field;
var v = this.form.businessdata.data[n];
if (typeof(v)!=="array") v = (v) ? [v.tostring()] : [];
v.each(function(d){
if (d){
// if (typeof(d)==="string"){
// var data;
// this.orgaction.getunit(function(json){ data = json.data }.bind(this), null, d, false);
// rangevalues.push(data);
// }else{
rangevalues.push(d);
// }
}
}.bind(this));
}.bind(this));
}
if (this.json.identityrangekey && this.json.identityrangekey.code){
var v = this.form.macro.exec(this.json.identityrangekey.code, this);
if (typeof(v)!=="array") v = (v) ? [v.tostring()] : [];
v.each(function(d){
if (d){
// if (typeof(d)==="string"){
// var data;
// this.orgaction.getunit(function(json){ data = json.data }.bind(this), null, d, false);
// rangevalues.push(data);
// }else{
rangevalues.push(d);
// }
}
}.bind(this));
}
return rangevalues;
},
getnextselectunit: function(id){
var ids = typeof(id)==="array" ? id : [id];
var data;
var units = [];
ids.each(function(i){
if (this.json.identityrangenext === "direct"){
this.orgaction.getidentity(function(json){ data = json.data }.bind(this), function(){data={"wounit": null}}, i, false);
if (data && data.wounit) units.push(data.wounit);
}else if (this.json.identityrangenext==="level"){
this.orgaction.getunitwithidentitywithlevel(i, this.json.identityrangenextlevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
if (data) units.push(data);
}else if (this.json.identityrangenext==="type"){
if (this.json.identityrangenextunittype==="all"){
this.orgaction.getunitwithidentitywithlevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
}else{
this.orgaction.getunitwithidentitywithtype(i, this.json.identityrangenextunittype, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
}
if (data) units.push(data);
}
data = null;
}.bind(this));
return units;
//if (this.json.identityrangenext === "direct"){
//if (typeof(id)==="array"){
// var units = [];
// id.each(function(i){
// this.orgaction.getidentity(function(json){ data = json.data }.bind(this), function(){data={"wounit": null}}, i, false);
// if (data && data.wounit) units.push(data.wounit);
// data = null;
// }.bind(this));
// return units;
//}else{
// this.orgaction.getidentity(function(json){ data = json.data }.bind(this), function(){data={"wounit": null}}, id, false);
// return (data.wounit) ? [data.wounit] : [];
//}
//}
//if (this.json.identityrangenext==="level"){
// this.orgaction.getunitwithidentitywithlevel(id, this.json.identityrangenextlevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
// return (data) ? [data] : [];
// //this.json.rangenextlevel
//}
//if (this.json.identityrangenext==="type"){
// if (this.json.identityrangenextunittype==="all"){
// this.orgaction.getunitwithidentitywithlevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
// }else{
// this.orgaction.getunitwithidentitywithtype(id, this.json.identityrangenextunittype, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
// }
// return (data) ? [data] : [];
//}
},
getselectrangeduty: function( refresh ){
if( !this.selectrangeduty || refresh ){
this.selectrangeduty = this._getselectrangeduty();
}
return this.selectrangeduty;
},
_getselectrangeduty: function(){
if (this.json.dutyrange==="duty"){
return this.getscriptselectduty();
}
return [];
},
getscriptselectduty: function(){
var rangevalues = [];
if( this.json.rangeduty && this.json.rangeduty.length ){
var rangeduty = this.json.rangeduty;
if( typeof(rangeduty) === "string" ){
rangeduty = json.parse( rangeduty );
}
if( typeof(rangeduty) === "array" ){
rangeduty.each(function(unit){
var unitflag = typeof(unit) === "string" ? unit : (unit.id || unit.name);
if (unitflag) rangevalues.push(unitflag);
}.bind(this));
}
}
//if (this.json.rangeduty && this.json.rangeduty.length){
// this.json.rangeduty.each(function(unit){
// var unitflag = unit.id || unit.name;
// if (unitflag) rangevalues.push(unitflag);
// }.bind(this));
//}
if (this.json.rangedutyfield && this.json.rangedutyfield.length){
this.json.rangedutyfield.each(function(field){
var n = (typeof(field)=="object") ? field.name : field;
var v = this.form.businessdata.data[n];
if (typeof(v)!=="array") v = (v) ? [v.tostring()] : [];
v.each(function(d){
if (d) rangevalues.push(d);
}.bind(this));
}.bind(this));
}
if (this.json.rangedutykey && this.json.rangedutykey.code){
var v = this.form.macro.exec(this.json.rangedutykey.code, this);
if (typeof(v)!=="array") v = (v) ? [v.tostring()] : [];
v.each(function(d){
if (d) rangevalues.push(d);
}.bind(this));
}
return rangevalues;
}
});