FormStyle.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.FormStyle = new Class({
  4. Extends: MWF.xApplication.Selector.Person,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectFormStyle,
  9. "values": [],
  10. "names": [],
  11. "expand": false,
  12. "mode" : "pc",
  13. "forceSearchInItem" : true
  14. },
  15. loadSelectItems: function(addToNext){
  16. var stylesUrl = "../x_component_process_FormDesigner/Module/Form/skin/config.json";
  17. MWF.getJSON(stylesUrl,{
  18. "onSuccess": function(json){
  19. var category = this._newItemCategory({
  20. name : "系统样式",
  21. id : "stystem"
  22. }, this, this.itemAreaNode);
  23. Object.each(json, function(s, key){
  24. if( s.mode.contains( this.options.mode ) ){
  25. var d = {
  26. name : s.name,
  27. id : key
  28. };
  29. var item = this._newItem(d, this, category.children);
  30. this.items.push(item);
  31. }
  32. }.bind(this));
  33. var category = this._newItemCategory({
  34. name : "脚本",
  35. id : "script"
  36. }, this, this.itemAreaNode);
  37. var json = {};
  38. var appJs = {};
  39. o2.Actions.load("x_processplatform_assemble_designer").ScriptAction.listNext("(0)", 500, function (scriptJson) {
  40. o2.Actions.load("x_processplatform_assemble_designer").ApplicationAction.list(function (appJson) {
  41. appJson.data.each( function (app) {
  42. appJs[ app.id ] = app;
  43. });
  44. scriptJson.data.each( function (script) {
  45. if( !json[script.application] ){
  46. json[script.application] = appJs[ script.application ];
  47. json[script.application].scriptList = [];
  48. }
  49. script.appName = appJs[ script.application ].name;
  50. script.appId = script.application;
  51. script.type = "script";
  52. json[script.application].scriptList.push( script )
  53. }.bind(this));
  54. for( var application in json ){
  55. var category = this._newItemCategory(json[application], this, category.children);
  56. json[application].scriptList.each(function(d){
  57. var item = this._newItem(d, this, category.children);
  58. this.items.push(item);
  59. }.bind(this));
  60. }
  61. }.bind(this))
  62. }.bind(this));
  63. }.bind(this)
  64. }
  65. );
  66. // this.processAction.listApplications(function(json){
  67. // json.data.each(function(data){
  68. // if (!data.scriptList){
  69. // this.designerAction.listScript(data.id, function(scriptJson){
  70. // data.scriptList = scriptJson.data;
  71. // }.bind(this), null, false);
  72. // }
  73. // if (data.scriptList && data.scriptList.length){
  74. // var category = this._newItemCategory(data, this, this.itemAreaNode);
  75. // data.scriptList.each(function(d){
  76. // d.applicationName = data.name;
  77. // var item = this._newItem(d, this, category.children);
  78. // this.items.push(item);
  79. // }.bind(this));
  80. // }
  81. // }.bind(this));
  82. // }.bind(this));
  83. },
  84. _scrollEvent: function(y){
  85. return true;
  86. },
  87. _getChildrenItemIds: function(data){
  88. return data.scriptList || [];
  89. },
  90. _newItemCategory: function(data, selector, item, level){
  91. return new MWF.xApplication.Selector.FormStyle.ItemCategory(data, selector, item, level)
  92. },
  93. _listItemByKey: function(callback, failure, key){
  94. return false;
  95. },
  96. _getItem: function(callback, failure, id, async){
  97. this.queryAction.getTable(function(json){
  98. if (callback) callback.apply(this, [json]);
  99. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  100. },
  101. _newItemSelected: function(data, selector, item){
  102. return new MWF.xApplication.Selector.FormStyle.ItemSelected(data, selector, item)
  103. },
  104. _listItemByPinyin: function(callback, failure, key){
  105. return false;
  106. },
  107. _newItem: function(data, selector, container, level){
  108. return new MWF.xApplication.Selector.FormStyle.Item(data, selector, container, level);
  109. }
  110. });
  111. MWF.xApplication.Selector.FormStyle.Item = new Class({
  112. Extends: MWF.xApplication.Selector.Person.Item,
  113. _getShowName: function(){
  114. return this.data.name;
  115. },
  116. _setIcon: function(){
  117. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  118. },
  119. loadSubItem: function(){
  120. return false;
  121. },
  122. checkSelectedSingle: function(){
  123. var selectedItem = this.selector.options.values.filter(function(item, index){
  124. if (typeOf(item)==="object"){
  125. if( this.data.id && item.id ){
  126. return this.data.id === item.id;
  127. }
  128. //return (this.data.id === item.id) || (this.data.name === item.name) ;
  129. }
  130. //if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  131. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  132. return false;
  133. }.bind(this));
  134. if (selectedItem.length){
  135. this.selectedSingle();
  136. }
  137. },
  138. checkSelected: function(){
  139. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  140. if( item.data.id && this.data.id){
  141. return item.data.id === this.data.id;
  142. }else{
  143. return item.data.name === this.data.name;
  144. }
  145. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  146. }.bind(this));
  147. if (selectedItem.length){
  148. //selectedItem[0].item = this;
  149. selectedItem[0].addItem(this);
  150. this.selectedItem = selectedItem[0];
  151. this.setSelected();
  152. }
  153. }
  154. });
  155. MWF.xApplication.Selector.FormStyle.ItemSelected = new Class({
  156. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  157. _getShowName: function(){
  158. return this.data.name;
  159. },
  160. _setIcon: function(){
  161. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  162. },
  163. check: function(){
  164. if (this.selector.items.length){
  165. var items = this.selector.items.filter(function(item, index){
  166. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  167. if( item.data.id && this.data.id){
  168. return item.data.id === this.data.id;
  169. }else{
  170. return item.data.name === this.data.name;
  171. }
  172. }.bind(this));
  173. this.items = items;
  174. if (items.length){
  175. items.each(function(item){
  176. item.selectedItem = this;
  177. item.setSelected();
  178. }.bind(this));
  179. }
  180. }
  181. }
  182. });
  183. MWF.xApplication.Selector.FormStyle.ItemCategory = new Class({
  184. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  185. _getShowName: function(){
  186. return this.data.name;
  187. },
  188. createNode: function(){
  189. this.node = new Element("div", {
  190. "styles": this.selector.css.selectorItemCategory_department
  191. }).inject(this.container);
  192. },
  193. _setIcon: function(){
  194. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  195. },
  196. _hasChild: function(){
  197. return (this.data.scriptList && this.data.scriptList.length);
  198. },
  199. check: function(){}
  200. });