FieldProperty.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.FieldProperty = new Class({
  4. Extends: MWF.xApplication.Selector.Person,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "values": [],
  9. "names": [],
  10. "appType" : ["currentForm","process","portal","cms"],
  11. "moduleTypes": [],
  12. "excludeModuleTypes": [], //"Div","Table$Td","Datatable$Data","Datatable$Title","Label"
  13. "currentFormFields": [],
  14. "applications": [],
  15. "expand": false,
  16. "forceSearchInItem" : true
  17. },
  18. setInitTitle: function(){
  19. this.setOptions({"title": MWF.xApplication.Selector.LP.selectFieldProperty});
  20. },
  21. _init : function(){
  22. this.selectType = "fieldProperty";
  23. this.className = "FieldProperty";
  24. },
  25. loadSelectItems: function(addToNext){
  26. var json = {};
  27. this.options.appType.each( function (type) {
  28. if( type === 'currentForm' && !this.options.currentFormFields.length )return;
  29. var container = new Element("div").inject(this.itemAreaNode);
  30. this._newItemCategory({
  31. name: MWF.xApplication.Selector.LP.appType[type],
  32. id: type,
  33. _appType: type
  34. }, this, container);
  35. }.bind(this));
  36. },
  37. _scrollEvent: function(y){
  38. return true;
  39. },
  40. _newItemCategory: function(data, selector, item, level){
  41. return new MWF.xApplication.Selector.FieldProperty.ItemCategory(data, selector, item, level)
  42. },
  43. _listItemByKey: function(callback, failure, key){
  44. return false;
  45. },
  46. _getItem: function(callback, failure, id, async){
  47. // this.queryAction.getTable(function(json){
  48. // if (callback) callback.apply(this, [json]);
  49. // }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  50. },
  51. _newItemSelected: function(data, selector, item){
  52. return new MWF.xApplication.Selector.FieldProperty.ItemSelected(data, selector, item)
  53. },
  54. _listItemByPinyin: function(callback, failure, key){
  55. return false;
  56. },
  57. _newItem: function(data, selector, container, level){
  58. return new MWF.xApplication.Selector.FieldProperty.Item(data, selector, container, level);
  59. }
  60. });
  61. MWF.xApplication.Selector.FieldProperty.Item = new Class({
  62. Extends: MWF.xApplication.Selector.Person.Item,
  63. _getShowName: function(){
  64. return this.data.name+"<"+this.data.type+">";
  65. },
  66. _setIcon: function(){
  67. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  68. },
  69. loadSubItem: function(){
  70. return false;
  71. },
  72. checkSelectedSingle: function(){
  73. var selectedItem = this.selector.options.values.filter(function(item, index){
  74. if (typeOf(item)==="object"){
  75. if( this.data.id && item.id ){
  76. return this.data.id === item.id;
  77. }
  78. }
  79. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  80. return false;
  81. }.bind(this));
  82. if (selectedItem.length){
  83. this.selectedSingle();
  84. }
  85. },
  86. checkSelected: function(){
  87. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  88. if( item.data.id && this.data.id){
  89. return item.data.id === this.data.id;
  90. }
  91. }.bind(this));
  92. if (selectedItem.length){
  93. selectedItem[0].addItem(this);
  94. this.selectedItem = selectedItem[0];
  95. this.setSelected();
  96. }
  97. }
  98. });
  99. MWF.xApplication.Selector.FieldProperty.ItemSelected = new Class({
  100. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  101. _getShowName: function(){
  102. return this.data.name+"<"+this.data.type+">";
  103. },
  104. _setIcon: function(){
  105. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  106. },
  107. check: function(){
  108. if (this.selector.items.length){
  109. var items = this.selector.items.filter(function(item, index){
  110. if( item.data.id && this.data.id){
  111. return item.data.id === this.data.id;
  112. }
  113. }.bind(this));
  114. this.items = items;
  115. if (items.length){
  116. items.each(function(item){
  117. item.selectedItem = this;
  118. item.setSelected();
  119. }.bind(this));
  120. }
  121. }
  122. }
  123. });
  124. MWF.xApplication.Selector.FieldProperty.ItemCategory = new Class({
  125. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  126. _setIcon: function(){
  127. switch (this.level){
  128. case 1:
  129. this.iconNode.setStyle("background-image", "url(/x_component_Selector/$Selector/default/icon/processicon.png)");
  130. break;
  131. case 2:
  132. this.iconNode.setStyle("background-image", "url(/x_component_Selector/$Selector/default/icon/applicationicon.png)");
  133. break;
  134. case 3:
  135. this.iconNode.setStyle("background-image", "url(/x_component_Selector/$Selector/default/icon/table.png)");
  136. break;
  137. }
  138. },
  139. clickItem: function (callback) {
  140. if (this._hasChild() ) {
  141. var firstLoaded = !this.loaded;
  142. this.loadSub(function () {
  143. if (firstLoaded && this._hasChild() ) {
  144. if (!this.selector.isFlatCategory) {
  145. this.children.setStyles({"display": "block", "height": "auto"});
  146. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  147. this.isExpand = true;
  148. }
  149. // this.checkSelectAll();
  150. } else {
  151. var display = this.children.getStyle("display");
  152. if (display === "none") {
  153. // this.selector.fireEvent("expand", [this] );
  154. this.children.setStyles({"display": "block", "height": "auto"});
  155. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  156. this.isExpand = true;
  157. } else {
  158. // this.selector.fireEvent("collapse", [this] );
  159. this.children.setStyles({"display": "none", "height": "0px"});
  160. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  161. this.isExpand = false;
  162. }
  163. }
  164. if (callback) callback();
  165. }.bind(this));
  166. }
  167. },
  168. loadSub: function (callback) {
  169. var action;
  170. if (!this.loaded) {
  171. if( this.level === 1 ){
  172. if( this.data._appType === "currentForm" ){
  173. var options = this.selector.options;
  174. options.currentFormFields.filter(function (d){
  175. var flag = options.moduleTypes.length ? options.moduleTypes.contains(d.type) : true;
  176. return !options.excludeModuleTypes.contains(d.type) && flag;
  177. }.bind(this)).sort(function (a, b){
  178. return a.id.localeCompare(b.id);
  179. }).each(function (d) {
  180. d._appType = this.data._appType;
  181. d.name = d.id;
  182. var item = this.selector._newItem(d, this.selector, this.children, this.level + 1, this);
  183. this.selector.items.push(item);
  184. if(this.subItems)this.subItems.push( item );
  185. }.bind(this));
  186. this.loaded = true;
  187. if (callback) callback();
  188. }else{
  189. switch (this.data._appType) {
  190. case "process":
  191. action = o2.Actions.load("x_processplatform_assemble_designer").ApplicationAction.list;
  192. break;
  193. case "portal":
  194. action = o2.Actions.load("x_portal_assemble_designer").PortalAction.list;
  195. break;
  196. case "cms":
  197. action = o2.Actions.load("x_cms_assemble_control").AppInfoAction.listAllAppInfo;
  198. break;
  199. }
  200. action(function (json){
  201. json.data.sort(function (a, b){
  202. a.name = a.name || a.appName;
  203. b.name = b.name || b.appName;
  204. return a.name.localeCompare(b.name);
  205. }).each(function (d){
  206. d._appType = this.data._appType;
  207. var category = this.selector._newItemCategory(d, this.selector, this.children, this.level + 1, this);
  208. this.subCategorys.push( category );
  209. }.bind(this));
  210. this.loaded = true;
  211. if (callback) callback();
  212. }.bind(this));
  213. }
  214. }else if(this.level === 2){
  215. switch (this.data._appType) {
  216. case "process":
  217. action = o2.Actions.load("x_processplatform_assemble_designer").FormAction.listWithApplication(this.data.id);
  218. break;
  219. case "portal":
  220. action = o2.Actions.load("x_portal_assemble_designer").PageAction.listWithPortal(this.data.id);
  221. break;
  222. case "cms":
  223. action = o2.Actions.load("x_cms_assemble_control").FormAction.listFormByAppId(this.data.id);
  224. break;
  225. }
  226. action.then(function (json){
  227. json.data.sort(function (a, b){{
  228. return a.name.localeCompare(b.name);
  229. }}).each(function (d){
  230. d._appType = this.data._appType;
  231. var category = this.selector._newItemCategory(d, this.selector, this.children, this.level + 1, this);
  232. this.subCategorys.push( category );
  233. }.bind(this));
  234. this.loaded = true;
  235. if (callback) callback();
  236. }.bind(this));
  237. }else if(this.level === 3){
  238. switch (this.data._appType) {
  239. case "process":
  240. action = o2.Actions.load("x_processplatform_assemble_designer").FormAction.get(this.data.id);
  241. break;
  242. case "portal":
  243. action = o2.Actions.load("x_portal_assemble_designer").PageAction.get(this.data.id);
  244. break;
  245. case "cms":
  246. action = o2.Actions.load("x_cms_assemble_control").FormAction.get(this.data.id);
  247. break;
  248. }
  249. action.then(function (json){
  250. var formData = JSON.decode(MWF.decodeJsonString(json.data.data));
  251. var options = this.selector.options;
  252. Object.values(formData.json.moduleList).filter(function (d){
  253. var flag = options.moduleTypes.length ? options.moduleTypes.contains(d.type) : true;
  254. return !options.excludeModuleTypes.contains(d.type) && flag;
  255. }.bind(this)).sort(function (a, b){
  256. return a.id.localeCompare(b.id);
  257. }).each(function (d) {
  258. d._appType = this.data._appType;
  259. d.name = d.id;
  260. var item = this.selector._newItem(d, this.selector, this.children, this.level + 1, this);
  261. this.selector.items.push(item);
  262. if(this.subItems)this.subItems.push( item );
  263. }.bind(this));
  264. this.loaded = true;
  265. if (callback) callback();
  266. }.bind(this));
  267. }
  268. } else {
  269. if (callback) callback();
  270. }
  271. },
  272. _getShowName: function(){
  273. return this.data.name;
  274. },
  275. _getTtiteText: function () {
  276. return this.data.name;
  277. },
  278. createNode: function(){
  279. this.node = new Element("div", {
  280. "styles": this.selector.css.selectorItemCategory_department
  281. }).inject(this.container);
  282. },
  283. _hasChild: function(){
  284. return true;
  285. // return ( this.data.scriptList && this.data.scriptList.length ) ||
  286. // ( this.data.applicationList && this.data.applicationList.length);
  287. },
  288. afterLoad: function(){
  289. if ( this._hasChild() ){
  290. if( this.level === 1 && this.data._appType === 'currentForm' ){
  291. this.clickItem();
  292. }
  293. }
  294. },
  295. check: function(){}
  296. });