Personfield.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. MWF.xDesktop.requireApp("process.Xform", "$Input", null, false);
  2. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  3. MWF.xApplication.process.Xform.Personfield = MWF.APPPersonfield = new Class({
  4. Implements: [Events],
  5. Extends: MWF.APP$Input,
  6. iconStyle: "personfieldIcon",
  7. loadDescription: function(){
  8. var v = this._getBusinessData();
  9. if (!v || !v.length){
  10. if (this.json.description){
  11. var size = this.node.getFirst().getSize();
  12. var w = size.x-3;
  13. if (COMMON.Browser.safari) w = w-20;
  14. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  15. this.descriptionNode.setStyles({
  16. "width": ""+w+"px",
  17. "height": ""+size.y+"px",
  18. "line-height": ""+size.y+"px"
  19. });
  20. this.setDescriptionEvent();
  21. }
  22. }
  23. },
  24. setDescriptionEvent: function(){
  25. if (this.descriptionNode){
  26. this.descriptionNode.addEvents({
  27. "mousedown": function(){
  28. this.descriptionNode.setStyle("display", "none");
  29. this.clickSelect();
  30. }.bind(this)
  31. });
  32. }
  33. },
  34. getRange: function(){
  35. var rangeValues = [];
  36. if (this.json.rangeField && this.json.rangeField.length){
  37. this.json.rangeField.each(function(field){
  38. var v = this.form.businessData.data[field];
  39. if (typeOf(v)!="array") v = (v) ? [v.toString()] : [];
  40. v.each(function(d){
  41. if (d) rangeValues.push(d);
  42. });
  43. }.bind(this));
  44. }
  45. if (this.json.rangeKey && this.json.rangeKey.code){
  46. var v = this.form.Macro.exec(this.json.rangeKey.code, this);
  47. if (typeOf(v)!="array") v = (v) ? [v.toString()] : [];
  48. v.each(function(d){
  49. if (d) rangeValues.push(d);
  50. });
  51. }
  52. return rangeValues;
  53. },
  54. _computeValue: function(value){
  55. var values = [];
  56. if (this.json.identityValue) {
  57. this.json.identityValue.each(function(v){ if (v) values.push(v)});
  58. }
  59. if (this.json.departmentValue) {
  60. this.json.departmentValue.each(function(v){ if (v) values.push(v)});
  61. }
  62. if (this.json.companyValue) {
  63. this.json.companyValue.each(function(v){ if (v) values.push(v)});
  64. }
  65. if (this.json.dutyValue) {
  66. debugger;
  67. var dutys = JSON.decode(this.json.dutyValue);
  68. var par;
  69. if (dutys.length){
  70. dutys.each(function(duty){
  71. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  72. var code = "return this.org.getDepartmentDuty({\"name\": \""+duty.name+"\", \"departmentName\": \""+par+"\"})";
  73. var d = this.form.Macro.exec(code, this);
  74. if (typeOf(d)!="array") d = (d) ? [d.toString()] : [];
  75. d.each(function(dd){values.push(dd);});
  76. code = "return this.org.getCompanyDuty({\"name\": \""+duty.name+"\", \"compName\": \""+par+"\"})";
  77. d = this.form.Macro.exec(code, this);
  78. if (typeOf(d)!="array") d = (d) ? [d.toString()] : [];
  79. d.each(function(dd){values.push(dd);});
  80. }.bind(this));
  81. }
  82. }
  83. if (this.json.defaultValue && this.json.defaultValue.code){
  84. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  85. if (typeOf(fd)!="array") fd = (fd) ? [fd.toString()] : [];
  86. fd.each(function(fdd){values.push(fdd);});
  87. }
  88. if (this.json.count>0){
  89. return values.slice(0, this.json.count);
  90. }
  91. return values;
  92. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  93. },
  94. getDepartments: function(){
  95. if (this.json.range=="depart"){
  96. return this.getRange();
  97. }
  98. if (this.json.range=="currentdepart"){
  99. return [this.form.app.currentTask.department];
  100. }
  101. return [];
  102. },
  103. getCompanys: function(){
  104. if (this.json.range=="company"){
  105. var comp = "";
  106. //if (this.json.rangeKey){
  107. return this.getRange();
  108. //}
  109. }
  110. if (this.json.range=="currentcompany"){
  111. return [this.form.app.currentTask.company];
  112. }
  113. return [];
  114. },
  115. clickSelect: function(){
  116. var nameValue = this.getInputData();
  117. //var names = (nameValue) ? this.getInputData().split(MWF.splitStr) : [];
  118. var names = nameValue;
  119. var count = (this.json.count) ? this.json.count : 0;
  120. var companys = this.getCompanys();
  121. var departments = this.getDepartments();
  122. if (this.json.range=="depart"){
  123. if (!departments.length){
  124. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  125. return false;
  126. }
  127. }
  128. if (this.json.range=="company"){
  129. if (!companys.length){
  130. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  131. return false;
  132. }
  133. }
  134. var options = {
  135. "type": this.json.selectType,
  136. "names": names,
  137. "count": count,
  138. "departments": departments,
  139. "companys": companys,
  140. "onComplete": function(items){
  141. var values = [];
  142. items.each(function(item){
  143. values.push(item.data.name);
  144. }.bind(this));
  145. this.setData(values.join(", "));
  146. this._setBusinessData(this.getInputData());
  147. this.validationMode();
  148. this.validation()
  149. }.bind(this),
  150. "onCancel": function(){
  151. this.validation();
  152. }.bind(this),
  153. "onLoad": function(){
  154. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  155. }.bind(this),
  156. "onClose": function(){
  157. var v = this.node.getFirst().get("value");
  158. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  159. }.bind(this)
  160. };
  161. //if (layout.mobile) options.style = "mobile";
  162. //var selector = new MWF.OrgSelector(this.form.node.getParent(), options);
  163. var selector = new MWF.OrgSelector(this.form.app.content, options);
  164. //value = MWF.Macro.exec(this.json.defaultValue.code, this.form);
  165. },
  166. resetData: function(){
  167. var v = this.getValue();
  168. this.setData((v) ? v.join(", ") : "");
  169. },
  170. getInputData: function(){
  171. //if (this.json.count==1){
  172. // return this.node.get("value");
  173. //}
  174. debugger;
  175. var v = this.node.getElement("input").get("value");
  176. return (v) ? v.split(/,\s*/g) : "";
  177. }
  178. });