Readerfield.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. MWF.xDesktop.requireApp("cms.Xform", "Personfield", null, false);
  2. MWF.require("MWF.widget.O2Identity", null,false);
  3. MWF.xDesktop.requireApp("Selector", "package", null, false);
  4. MWF.xApplication.cms.Xform.Readerfield = MWF.CMSReaderfield = new Class({
  5. Extends: MWF.CMSPersonfield,
  6. iconStyle: "readerfieldIcon",
  7. _loadUserInterface: function(){
  8. this.field = true;
  9. this._loadNode();
  10. if (this.json.compute == "show"){
  11. this._setValue(this._computeValue());
  12. }else{
  13. this._loadValue();
  14. }
  15. },
  16. _loadNode: function(){
  17. if (this.readonly || this.json.isReadonly){
  18. this._loadNodeRead();
  19. }else{
  20. this._loadNodeEdit();
  21. }
  22. },
  23. _loadNodeRead: function(){
  24. this.node.empty();
  25. this.node.setStyle("overflow" , "hidden");
  26. },
  27. _loadNodeEdit : function(){
  28. var input = this.input = new Element("div", {
  29. "styles": {
  30. "background": "transparent",
  31. "width": "100%",
  32. "border": "0px"
  33. }
  34. });
  35. input.set(this.json.properties);
  36. var node = new Element("div", {"styles": {
  37. "overflow": "hidden",
  38. "position": "relative",
  39. "min-height" : "20px",
  40. "margin-right": "20px"
  41. }}).inject(this.node, "after");
  42. input.inject(node);
  43. this.node.destroy();
  44. this.node = node;
  45. this.node.set({
  46. "id": this.json.id,
  47. "MWFType": this.json.type,
  48. "readonly": true,
  49. "title" : MWF.xApplication.cms.Xform.LP.readerFieldNotice
  50. });
  51. if( !this.readonly ) {
  52. this.node.setStyle("cursor" , "pointer");
  53. this.node.addEvents({
  54. "click": this.clickSelect.bind(this)
  55. });
  56. this.iconNode = new Element("div", { //this.form.css[this.iconStyle],
  57. "styles": {
  58. "background": "url("+"/x_component_cms_Xform/$Form/default/icon/selectreader.png) center center no-repeat",
  59. "width": "18px",
  60. "height": "18px",
  61. "float": "right"
  62. }
  63. }).inject(this.node, "before");
  64. this.iconNode.setStyle("cursor" , "pointer");
  65. this.iconNode.addEvents({
  66. "click": this.clickSelect.bind(this)
  67. });
  68. }
  69. //this.node.getFirst().addEvent("change", function(){
  70. // this.validationMode();
  71. // if (this.validation()) this._setBusinessData(this.getInputData("change"));
  72. //}.bind(this));
  73. },
  74. getData: function(when){
  75. if (this.json.compute == "save") this._setValue(this._computeValue());
  76. return this._getBusinessData();
  77. },
  78. getInputData: function(){
  79. return this._getBusinessData();
  80. //var data = this._getBusinessData();
  81. //var values = [];
  82. //for( var key in data ){
  83. // data[key].each( function(d){
  84. // values.push( d.name );
  85. // });
  86. //}
  87. //return values.join(",");
  88. },
  89. setData: function(data) {
  90. this._setValue(data);
  91. //this._setBusinessData(data);
  92. //if (this.node.getFirst()){
  93. // this.node.getFirst().set("value", data);
  94. //}else{
  95. // this.node.set("text", data);
  96. //}
  97. },
  98. _computeValue: function(){
  99. var values = [];
  100. if (this.json.identityValue) {
  101. this.json.identityValue.each(function(v){ if (v) values.push(v)});
  102. }
  103. if (this.json.unitValue) {
  104. this.json.unitValue.each(function(v){ if (v) values.push(v)});
  105. }
  106. if (this.json.defaultValue && this.json.defaultValue.code){
  107. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  108. if (typeOf(fd)!=="array") fd = (fd) ? [fd.toString()] : [];
  109. fd.each(function(fdd){values.push(fdd);});
  110. }
  111. if (this.json.count>0){
  112. return values.slice(0, this.json.count);
  113. }
  114. return values;
  115. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  116. },
  117. //_computeValue: function(value){
  118. //var values = {};
  119. //if (this.json.identityValue) {
  120. // values.identityValue = [];
  121. // this.json.identityValue.each( function( d ){
  122. // values.identityValue.push( { name : d } )
  123. // }.bind(this) );
  124. //}
  125. //if (this.json.personValue) {
  126. // values.personValue = [];
  127. // this.json.personValue.each( function( d ){
  128. // values.personValue.push( { name : d } )
  129. // }.bind(this) );
  130. //}
  131. //if (this.json.unitValue) {
  132. // values.unitValue = [];
  133. // this.json.unitValue.each( function( d ){
  134. // values.unitValue.push( { name : d } )
  135. // }.bind(this) );
  136. //}
  137. //if (this.json.groupValue) {
  138. // values.groupValue = [];
  139. // this.json.groupValue.each( function( d ){
  140. // values.groupValue.push( { name : d } )
  141. // }.bind(this) );
  142. //}
  143. //return values;
  144. //},
  145. _getBusinessData: function(){
  146. if (this.json.section=="yes"){
  147. var data = this._getBusinessSectionData();
  148. }else {
  149. var data = this.form.businessData.data[this.json.id] || [];
  150. }
  151. return typeOf( data ) != "array" ? [data] : data;
  152. },
  153. _setValue: function(value){
  154. this._setBusinessData(value);
  155. var input = this.node.getFirst();
  156. if (!input){
  157. input = this.node;
  158. }
  159. input.empty();
  160. this.loadOrgWidget(value, input);
  161. //for (var key in value) {
  162. // v = value[key];
  163. // if( key == "identityValue" ){
  164. // v.each(function( d ){
  165. // if (d.name) new MWF.widget.O2Identity( Object.merge( d, {"type" : "identity" }), input, {
  166. // "style": "cmsdoc", "canRemove":!this.readonly , "onRemove" : this.removeItem
  167. // });
  168. // }.bind(this));
  169. // }else if( key == "personValue" ){
  170. // v.each(function( d ){
  171. // if (d.name) new MWF.widget.O2Person(Object.merge( d, {"type" : "person" }), input, {
  172. // "style": "cmsdoc", "canRemove":!this.readonly , "onRemove" : this.removeItem
  173. // });
  174. // }.bind(this));
  175. // }else if( key == "unitValue" ){
  176. // v.each(function(d){
  177. // if (d.name) new MWF.widget.O2Unit(Object.merge( d, {"type" : "department" }), input, {
  178. // "style": "cmsdoc", "canRemove":!this.readonly , "onRemove" : this.removeItem
  179. // });
  180. // }.bind(this));
  181. // }else if( key == "groupValue" ){
  182. // v.each(function(d){
  183. // if (d.name) new MWF.widget.O2Group(Object.merge( d, {"type" : "group" }), input,{
  184. // "style": "cmsdoc", "canRemove":!this.readonly , "onRemove" : this.removeItem
  185. // });
  186. // }.bind(this));
  187. // }else{
  188. // v.each(function(d){
  189. // if (d.name) new MWF.widget.O2Other(Object.merge( d, {"type" : "group" }), input,{
  190. // "style": "cmsdoc", "canRemove":!this.readonly , "onRemove" : this.removeItem
  191. // });
  192. // }.bind(this));
  193. // }
  194. //}
  195. },
  196. loadOrgWidget: function(value, node){
  197. var options = {"style": "xform", "canRemove":!this.readonly , "onRemove" : this.removeItem};
  198. value.each(function(data){
  199. if( data.distinguishedName ){
  200. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  201. switch (flag.toLowerCase()){
  202. case "i":
  203. var widget = new MWF.widget.O2Identity(data, node, options );
  204. break;
  205. case "p":
  206. var widget = new MWF.widget.O2Person(data, node, options);
  207. break;
  208. case "u":
  209. var widget = new MWF.widget.O2Unit(data, node, options);
  210. break;
  211. case "g":
  212. var widget = new MWF.widget.O2Group(data, node, options);
  213. break;
  214. default:
  215. var widget = new MWF.widget.O2Other(data, node, options);
  216. }
  217. widget.field = this;
  218. }
  219. }.bind(this));
  220. },
  221. removeItem : function( widget, ev ){
  222. //this 是 MWF.widget.O2Identity 之类的对象
  223. var _self = this.field; //这个才是Readerfield
  224. var dn = this.data.distinguishedName;
  225. var data = _self._getBusinessData();
  226. var index;
  227. data.each( function ( d , i){
  228. if( d.distinguishedName == dn ){
  229. index = i
  230. }
  231. });
  232. data.splice( index, 1 );
  233. _self._setBusinessData( data );
  234. this.node.destroy();
  235. ev.stopPropagation();
  236. },
  237. //removeItem : function( ev ){
  238. // //this 是 MWF.widget.O2Identity 之类的对象
  239. // var _self = this.explorer.field; //这个才是Readerfield
  240. // var type = this.data.type;
  241. // var name = this.data.name;
  242. // var data = _self._getBusinessData();
  243. // var arr = data[ type+"Value"];
  244. // var index;
  245. // arr.each( function ( d , i){
  246. // if( d.name == name ){
  247. // index = i
  248. // }
  249. // });
  250. // arr.splice( index, 1 );
  251. // _self._setBusinessData( data );
  252. // this.node.destroy();
  253. // ev.stopPropagation();
  254. //},
  255. _loadValue: function(){
  256. this._setValue(this.getValue());
  257. },
  258. //_loadStyles: function(){
  259. // if (this.json.styles) this.node.setStyles(this.json.styles);
  260. // if( this.readonly ){
  261. // var parent = this.node.parentNode;
  262. // if( parent.tagName.toLowerCase() == "td" ){
  263. // var border = parent.getStyle("borderBottomWidth");
  264. // if( border.toInt() > 0 ){
  265. // this.node.setStyle("border","0px");
  266. // }
  267. // }
  268. // }
  269. // if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  270. // if (this.iconNode){
  271. // var size = this.node.getSize();
  272. // this.iconNode.setStyle("height", ""+size.y+"px");
  273. // }
  274. //},
  275. clickSelect: function(){
  276. this.validationMode();
  277. //var names = (nameValue) ? this.getInputData().split(MWF.splitStr) : [];
  278. //var names = nameValue;
  279. var count = (this.json.count) ? this.json.count : 0;
  280. //var companys = this.getCompanys(); //范围
  281. //var departments = this.getDepartments(); //范围
  282. //if (this.json.range=="depart"){
  283. // if (!departments.length){
  284. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  285. // return false;
  286. // }
  287. //}
  288. //if (this.json.range=="company"){
  289. // if (!companys.length){
  290. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  291. // return false;
  292. // }
  293. //}
  294. var selectType = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
  295. if( selectType.contains("unit") || selectType.contains("identity")){
  296. var selectUnits = this.getSelectRange();
  297. if (this.json.range!=="all"){
  298. if (!selectUnits.length){
  299. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  300. return false;
  301. }
  302. }
  303. }else{
  304. var selectUnits = [];
  305. }
  306. if( !selectType[0] ){
  307. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectType, "error", this.node);
  308. return false;
  309. }
  310. //var nameValue = this._getBusinessData();
  311. //var names = {};
  312. //var namesArr = [];
  313. //if( selectType.length > 1 ){
  314. // for( var key in nameValue ){
  315. // var name = [];
  316. // nameValue[key].each( function(value){
  317. // name.push( value.name );
  318. // }.bind(this));
  319. // names[ key.replace("Value","") ] = name;
  320. // }
  321. //}else{
  322. // for( var key in nameValue ){
  323. // nameValue[key].each( function(value){
  324. // namesArr.push( value.name );
  325. // }.bind(this));
  326. // }
  327. //}
  328. var options = {
  329. "type" : "",
  330. "types": selectType,
  331. "values" : this._getBusinessData(),
  332. "count": count,
  333. "units": selectUnits, //范围
  334. "expand" : false,
  335. "onComplete": function(items, itemsObject){
  336. var values = [];
  337. items.each( function(it){
  338. values.push(MWF.org.parseOrgData(it.data));
  339. });
  340. //if( itemsObject ){
  341. // for( var key in itemsObject ){
  342. // var item = itemsObject[key];
  343. // var value = [];
  344. // item.each( function(it){
  345. // value.push(MWF.org.parseOrgData(it.data));
  346. // });
  347. // values[ key + "Value" ] = value;
  348. // }
  349. //}else{
  350. // var key = selectType[0];
  351. // key = key + "Value";
  352. // var values = {};
  353. // values[key] = [];
  354. // items.each( function(it){
  355. // values[key].push(MWF.org.parseOrgData(it.data));
  356. // });
  357. //}
  358. this.setData( values );
  359. //items.each(function(item){
  360. // values.push(item.data.name);
  361. //}.bind(this));
  362. //this.setData(values.join(", "));
  363. //this._setBusinessData(this.getInputData());
  364. this.validation()
  365. }.bind(this),
  366. "onCancel": function(){
  367. this.validation();
  368. }.bind(this),
  369. "onLoad": function(){
  370. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  371. }.bind(this),
  372. "onClose": function(){
  373. //var v = this.node.getFirst().get("value");
  374. var v = this.getInputData();
  375. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  376. }.bind(this)
  377. };
  378. //if (layout.mobile) options.style = "mobile";
  379. //var selector = new MWF.O2Selector(this.form.node.getParent(), options);
  380. var selector = new MWF.O2Selector(this.form.app.content, options);
  381. //value = MWF.Macro.exec(this.json.defaultValue.code, this.form);
  382. }
  383. });