Personfield.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. var dutys = JSON.decode(this.json.dutyValue);
  67. var par;
  68. if (dutys.length){
  69. dutys.each(function(duty){
  70. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  71. var code = "return this.org.getDepartmentDuty({\"name\": \""+duty.name+"\", \"departmentName\": \""+par+"\"})";
  72. var d = this.form.Macro.exec(code, this);
  73. if (typeOf(d)!="array") d = (d) ? [d.toString()] : [];
  74. d.each(function(dd){values.push(dd);});
  75. code = "return this.org.getCompanyDuty({\"name\": \""+duty.name+"\", \"compName\": \""+par+"\"})";
  76. d = this.form.Macro.exec(code, this);
  77. if (typeOf(d)!="array") d = (d) ? [d.toString()] : [];
  78. d.each(function(dd){values.push(dd);});
  79. }.bind(this));
  80. }
  81. }
  82. if (this.json.defaultValue && this.json.defaultValue.code){
  83. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  84. if (typeOf(fd)!="array") fd = (fd) ? [fd.toString()] : [];
  85. fd.each(function(fdd){values.push(fdd);});
  86. }
  87. if (this.json.count>0){
  88. return values.slice(0, this.json.count);
  89. }
  90. return values;
  91. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  92. },
  93. getDepartments: function(){
  94. if (this.json.range=="depart"){
  95. return this.getRange();
  96. }
  97. if (this.json.range=="currentdepart"){
  98. return [this.form.app.currentTask.department];
  99. }
  100. return [];
  101. },
  102. getCompanys: function(){
  103. if (this.json.range=="company"){
  104. var comp = "";
  105. //if (this.json.rangeKey){
  106. return this.getRange();
  107. //}
  108. }
  109. if (this.json.range=="currentcompany"){
  110. return [this.form.app.currentTask.company];
  111. }
  112. return [];
  113. },
  114. clickSelect: function(){
  115. var nameValue = this.getInputData();
  116. //var names = (nameValue) ? this.getInputData().split(MWF.splitStr) : [];
  117. var names = nameValue;
  118. var count = (this.json.count) ? this.json.count : 0;
  119. var companys = this.getCompanys();
  120. var departments = this.getDepartments();
  121. if (this.json.range=="depart"){
  122. if (!departments.length){
  123. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  124. return false;
  125. }
  126. }
  127. if (this.json.range=="company"){
  128. if (!companys.length){
  129. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  130. return false;
  131. }
  132. }
  133. var options = {
  134. "type": this.json.selectType,
  135. "names": names,
  136. "count": count,
  137. "departments": departments,
  138. "companys": companys,
  139. "onComplete": function(items){
  140. var values = [];
  141. items.each(function(item){
  142. values.push(item.data.name);
  143. }.bind(this));
  144. this.setData(values.join(", "));
  145. this._setBusinessData(this.getInputData());
  146. this.validationMode();
  147. this.validation()
  148. }.bind(this),
  149. "onCancel": function(){
  150. this.validation();
  151. }.bind(this),
  152. "onLoad": function(){
  153. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  154. }.bind(this),
  155. "onClose": function(){
  156. var v = this.node.getFirst().get("value");
  157. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  158. }.bind(this)
  159. };
  160. //if (layout.mobile) options.style = "mobile";
  161. //var selector = new MWF.OrgSelector(this.form.node.getParent(), options);
  162. var selector = new MWF.OrgSelector(this.form.app.content, options);
  163. //value = MWF.Macro.exec(this.json.defaultValue.code, this.form);
  164. },
  165. resetData: function(){
  166. var v = this.getValue();
  167. this.setData((v) ? v.join(", ") : "");
  168. },
  169. getInputData: function(){
  170. //if (this.json.count==1){
  171. // return this.node.get("value");
  172. //}
  173. var v = this.node.getElement("input").get("value");
  174. return (v) ? v.split(/,\s*/g) : "";
  175. }
  176. });