Readerfield.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. MWF.xDesktop.requireApp("cms.Xform", "Personfield", null, false);
  2. MWF.require("MWF.widget.Identity", null,false);
  3. MWF.xDesktop.requireApp("Organization", "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. _loadNodeRead: function(){
  17. this.node.empty();
  18. this.node.setStyle("overflow" , "hidden");
  19. },
  20. _loadNodeEdit : function(){
  21. var input = this.input = new Element("div", {
  22. "styles": {
  23. "background": "transparent",
  24. "width": "100%",
  25. "border": "0px"
  26. }
  27. });
  28. input.set(this.json.properties);
  29. var node = new Element("div", {"styles": {
  30. "overflow": "hidden",
  31. "position": "relative",
  32. "min-height" : "20px",
  33. "margin-right": "20px"
  34. }}).inject(this.node, "after");
  35. input.inject(node);
  36. this.node.destroy();
  37. this.node = node;
  38. this.node.set({
  39. "id": this.json.id,
  40. "MWFType": this.json.type,
  41. "readonly": true
  42. });
  43. if( !this.readonly ) {
  44. this.node.setStyle("cursor" , "pointer");
  45. this.node.addEvents({
  46. "click": this.clickSelect.bind(this)
  47. });
  48. this.iconNode = new Element("div", { //this.form.css[this.iconStyle],
  49. "styles": {
  50. "background": "url("+"/x_component_cms_Xform/$Form/default/icon/selectreader.png) center center no-repeat",
  51. "width": "18px",
  52. "height": "18px",
  53. "float": "right"
  54. }
  55. }).inject(this.node, "before");
  56. this.iconNode.setStyle("cursor" , "pointer");
  57. this.iconNode.addEvents({
  58. "click": this.clickSelect.bind(this)
  59. });
  60. }
  61. //this.node.getFirst().addEvent("change", function(){
  62. // this.validationMode();
  63. // if (this.validation()) this._setBusinessData(this.getInputData("change"));
  64. //}.bind(this));
  65. },
  66. getData: function(when){
  67. if (this.json.compute == "save") this._setValue(this._computeValue());
  68. return this._getBusinessData();
  69. },
  70. getInputData: function(){
  71. //debugger;
  72. //var v = this.node.getElement("input").get("value");
  73. //return (v) ? v.split(/,\s*/g) : "";
  74. var data = this._getBusinessData();
  75. var values = [];
  76. for( var key in data ){
  77. data[key].each( function(d){
  78. values.push( d.name );
  79. });
  80. }
  81. return values.join(",");
  82. },
  83. setData: function(data) {
  84. this._setValue(data);
  85. //this._setBusinessData(data);
  86. //if (this.node.getFirst()){
  87. // this.node.getFirst().set("value", data);
  88. //}else{
  89. // this.node.set("text", data);
  90. //}
  91. },
  92. _computeValue: function(value){
  93. var values = {};
  94. if (this.json.identityValue) {
  95. values.identityValue = [];
  96. this.json.identityValue.each( function( d ){
  97. values.identityValue.push( { name : d } )
  98. }.bind(this) )
  99. //this.json.identityValue.each(function(v){ if (v) values.push(v)});
  100. }
  101. if (this.json.personValue) {
  102. values.personValue = [];
  103. this.json.personValue.each( function( d ){
  104. values.personValue.push( { name : d } )
  105. }.bind(this) );
  106. //this.json.identityValue.each(function(v){ if (v) values.push(v)});
  107. }
  108. if (this.json.departmentValue) {
  109. values.departmentValue = [];
  110. this.json.departmentValue.each( function( d ){
  111. values.departmentValue.push( { name : d } )
  112. }.bind(this) );
  113. //this.json.departmentValue.each(function(v){ if (v) values.push(v)});
  114. }
  115. if (this.json.companyValue) {
  116. values.companyValue = [];
  117. this.json.companyValue.each( function( d ){
  118. values.companyValue.push( { name : d } )
  119. }.bind(this) );
  120. //this.json.companyValue.each(function(v){ if (v) values.push(v)});
  121. }
  122. if (this.json.groupValue) {
  123. values.groupValue = [];
  124. this.json.groupValue.each( function( d ){
  125. values.groupValue.push( { name : d } )
  126. }.bind(this) );
  127. //this.json.groupValue.each(function(v){ if (v) values.push(v)});
  128. }
  129. //if (this.json.defaultValue && this.json.defaultValue.code){
  130. // var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  131. // if (typeOf(fd)!="array") fd = (fd) ? [fd.toString()] : [];
  132. // fd.each(function(fdd){values.push(fdd);});
  133. //}
  134. //if (this.json.count>0){
  135. // return values.slice(0, this.json.count);
  136. //}
  137. return values;
  138. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  139. },
  140. _setValue: function(value){
  141. this._setBusinessData(value);
  142. var input = this.node.getFirst();
  143. if (!input){
  144. input = this.node;
  145. }
  146. //if (this.readonly)var input = this.node;
  147. //this.input.empty();
  148. //if (this.node.getFirst()) this.node.getFirst().set("value", value);
  149. var explorer = {
  150. actions : this.form.documentAction,
  151. app : this.form.app,
  152. field : this
  153. };
  154. for (var key in value) {
  155. v = value[key];
  156. if( key == "identityValue" ){
  157. v.each(function( d ){
  158. if (d.name) new MWF.widget.Identity( Object.merge( d, {"type" : "identity" }), input, explorer, !this.readonly, this.removeItem, {"style": "cmsdoc"});
  159. }.bind(this));
  160. }else if( key == "personValue" ){
  161. v.each(function( d ){
  162. if (d.name) new MWF.widget.Department(Object.merge( d, {"type" : "person" }), input, explorer, !this.readonly, this.removeItem, {"style": "cmsdoc"});
  163. }.bind(this));
  164. }else if( key == "departmentValue" ){
  165. v.each(function(d){
  166. if (d.name) new MWF.widget.Department(Object.merge( d, {"type" : "department" }), input, explorer, !this.readonly, this.removeItem, {"style": "cmsdoc"});
  167. }.bind(this));
  168. }else if( key == "companyValue" ){
  169. v.each(function(d){
  170. if (d.name) new MWF.widget.Company(Object.merge( d, {"type" : "company" }), input, explorer, !this.readonly, this.removeItem, {"style": "cmsdoc"});
  171. }.bind(this));
  172. }else if( key == "groupValue" ){
  173. v.each(function(d){
  174. if (d.name) new MWF.widget.Department(Object.merge( d, {"type" : "group" }), input, explorer, !this.readonly, this.removeItem, {"style": "cmsdoc"});
  175. }.bind(this));
  176. }
  177. }
  178. },
  179. removeItem : function( ev ){
  180. //this 是 MWF.widget.Identity 之类的对象
  181. var _self = this.explorer.field; //这个才是Readerfield
  182. var type = this.data.type;
  183. var name = this.data.name;
  184. var data = _self._getBusinessData();
  185. var arr = data[ type+"Value"];
  186. var index;
  187. arr.each( function ( d , i){
  188. if( d.name == name ){
  189. index = i
  190. }
  191. });
  192. arr.splice( index, 1 );
  193. _self._setBusinessData( data );
  194. this.node.destroy();
  195. ev.stopPropagation();
  196. },
  197. _loadValue: function(){
  198. this._setValue(this.getValue());
  199. },
  200. //_loadStyles: function(){
  201. // if (this.json.styles) this.node.setStyles(this.json.styles);
  202. // if( this.readonly ){
  203. // var parent = this.node.parentNode;
  204. // if( parent.tagName.toLowerCase() == "td" ){
  205. // var border = parent.getStyle("borderBottomWidth");
  206. // if( border.toInt() > 0 ){
  207. // this.node.setStyle("border","0px");
  208. // }
  209. // }
  210. // }
  211. // if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  212. // if (this.iconNode){
  213. // var size = this.node.getSize();
  214. // this.iconNode.setStyle("height", ""+size.y+"px");
  215. // }
  216. //},
  217. clickSelect: function(){
  218. this.validationMode();
  219. //var names = (nameValue) ? this.getInputData().split(MWF.splitStr) : [];
  220. //var names = nameValue;
  221. var count = (this.json.count) ? this.json.count : 0;
  222. var companys = this.getCompanys(); //范围
  223. var departments = this.getDepartments(); //范围
  224. if (this.json.range=="depart"){
  225. if (!departments.length){
  226. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  227. return false;
  228. }
  229. }
  230. if (this.json.range=="company"){
  231. if (!companys.length){
  232. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  233. return false;
  234. }
  235. }
  236. var nameValue = this._getBusinessData();
  237. var names = {};
  238. var namesArr = [];
  239. if( typeOf( this.json.selectType ) == "array" && this.json.selectType.length > 1 ){
  240. for( var key in nameValue ){
  241. var name = [];
  242. nameValue[key].each( function(value){
  243. name.push( value.name );
  244. }.bind(this));
  245. names[ key.replace("Value","") ] = name;
  246. }
  247. }else{
  248. for( var key in nameValue ){
  249. nameValue[key].each( function(value){
  250. namesArr.push( value.name );
  251. }.bind(this));
  252. }
  253. }
  254. var options = {
  255. "types": typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType],
  256. "names" : namesArr,
  257. "multipleNames": names, //已选值
  258. "count": count,
  259. "departments": departments, //范围
  260. "companys": companys, //范围
  261. "onComplete": function(items, itemsObject){
  262. var values = {};
  263. if( itemsObject ){
  264. for( var key in itemsObject ){
  265. var item = itemsObject[key];
  266. var value = [];
  267. item.each( function(it){
  268. value.push({
  269. id : it.data.id,
  270. name: it.data.name
  271. })
  272. });
  273. values[ key + "Value" ] = value;
  274. }
  275. }else{
  276. var key = typeOf( this.json.selectType ) == "array" ? this.json.selectType[0] : this.json.selectType;
  277. key = key + "Value";
  278. var values = {};
  279. values[key] = [];
  280. items.each( function(it){
  281. values[key].push({
  282. id : it.data.id,
  283. name: it.data.name
  284. })
  285. });
  286. }
  287. this.setData( values );
  288. //items.each(function(item){
  289. // values.push(item.data.name);
  290. //}.bind(this));
  291. //this.setData(values.join(", "));
  292. //this._setBusinessData(this.getInputData());
  293. this.validation()
  294. }.bind(this),
  295. "onCancel": function(){
  296. this.validation();
  297. }.bind(this),
  298. "onLoad": function(){
  299. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  300. }.bind(this),
  301. "onClose": function(){
  302. //var v = this.node.getFirst().get("value");
  303. var v = this.getInputData();
  304. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  305. }.bind(this)
  306. };
  307. //if (layout.mobile) options.style = "mobile";
  308. //var selector = new MWF.OrgSelector(this.form.node.getParent(), options);
  309. var selector = new MWF.OrgSelector(this.form.app.content, options);
  310. //value = MWF.Macro.exec(this.json.defaultValue.code, this.form);
  311. }
  312. });