FormStyle.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. debugger;
  20. var subItemList = [];
  21. Object.each(json, function(s, key){
  22. if( s.mode.contains( this.options.mode ) ){
  23. subItemList.push({
  24. name : s.name,
  25. id : key
  26. });
  27. }
  28. }.bind(this));
  29. var category = this._newItemCategory({
  30. name : "系统样式",
  31. id : "stystem",
  32. subItemList : subItemList
  33. }, this, this.itemAreaNode);
  34. var json = {};
  35. var appJs = {};
  36. var array = [];
  37. o2.Actions.load("x_processplatform_assemble_designer").ScriptAction.listNext("(0)", 500, function (scriptJson) {
  38. o2.Actions.load("x_processplatform_assemble_designer").ApplicationAction.list(function (appJson) {
  39. appJson.data.each( function (app) {
  40. appJs[ app.id ] = app;
  41. });
  42. scriptJson.data.each( function (script) {
  43. if( !json[script.application] ){
  44. json[script.application] = appJs[ script.application ];
  45. json[script.application].scriptList = [];
  46. }
  47. script.appName = appJs[ script.application ].name;
  48. script.appId = script.application;
  49. script.type = "script";
  50. json[script.application].scriptList.push( script )
  51. }.bind(this));
  52. for( var application in json ){
  53. if( json[application].scriptList && json[application].scriptList.length ){
  54. array.push( json[application] );
  55. }
  56. }
  57. var category = this._newItemCategory({
  58. name : "自定义样式(脚本)",
  59. id : "script",
  60. applicationList : array
  61. }, this, this.itemAreaNode);
  62. }.bind(this))
  63. }.bind(this));
  64. }.bind(this)
  65. }
  66. );
  67. // this.processAction.listApplications(function(json){
  68. // json.data.each(function(data){
  69. // if (!data.scriptList){
  70. // this.designerAction.listScript(data.id, function(scriptJson){
  71. // data.scriptList = scriptJson.data;
  72. // }.bind(this), null, false);
  73. // }
  74. // if (data.scriptList && data.scriptList.length){
  75. // var category = this._newItemCategory(data, this, this.itemAreaNode);
  76. // data.scriptList.each(function(d){
  77. // d.applicationName = data.name;
  78. // var item = this._newItem(d, this, category.children);
  79. // this.items.push(item);
  80. // }.bind(this));
  81. // }
  82. // }.bind(this));
  83. // }.bind(this));
  84. },
  85. _scrollEvent: function(y){
  86. return true;
  87. },
  88. _getChildrenItemIds: function(data){
  89. return data.scriptList || data.subItemList || data.applicationList;
  90. },
  91. _newItemCategory: function(data, selector, item, level){
  92. return new MWF.xApplication.Selector.FormStyle.ItemCategory(data, selector, item, level)
  93. },
  94. _listItemByKey: function(callback, failure, key){
  95. return false;
  96. },
  97. _getItem: function(callback, failure, id, async){
  98. this.queryAction.getTable(function(json){
  99. if (callback) callback.apply(this, [json]);
  100. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  101. },
  102. _newItemSelected: function(data, selector, item){
  103. return new MWF.xApplication.Selector.FormStyle.ItemSelected(data, selector, item)
  104. },
  105. _listItemByPinyin: function(callback, failure, key){
  106. return false;
  107. },
  108. _newItem: function(data, selector, container, level){
  109. return new MWF.xApplication.Selector.FormStyle.Item(data, selector, container, level);
  110. }
  111. });
  112. MWF.xApplication.Selector.FormStyle.Item = new Class({
  113. Extends: MWF.xApplication.Selector.Person.Item,
  114. _getShowName: function(){
  115. return this.data.name;
  116. },
  117. _setIcon: function(){
  118. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  119. },
  120. loadSubItem: function(){
  121. return false;
  122. },
  123. checkSelectedSingle: function(){
  124. var selectedItem = this.selector.options.values.filter(function(item, index){
  125. if (typeOf(item)==="object"){
  126. if( this.data.id && item.id ){
  127. return this.data.id === item.id;
  128. }
  129. //return (this.data.id === item.id) || (this.data.name === item.name) ;
  130. }
  131. //if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  132. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  133. return false;
  134. }.bind(this));
  135. if (selectedItem.length){
  136. this.selectedSingle();
  137. }
  138. },
  139. checkSelected: function(){
  140. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  141. if( item.data.id && this.data.id){
  142. return item.data.id === this.data.id;
  143. }
  144. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  145. }.bind(this));
  146. if (selectedItem.length){
  147. //selectedItem[0].item = this;
  148. selectedItem[0].addItem(this);
  149. this.selectedItem = selectedItem[0];
  150. this.setSelected();
  151. }
  152. }
  153. });
  154. MWF.xApplication.Selector.FormStyle.ItemSelected = new Class({
  155. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  156. _getShowName: function(){
  157. return this.data.name;
  158. },
  159. _setIcon: function(){
  160. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  161. },
  162. check: function(){
  163. if (this.selector.items.length){
  164. var items = this.selector.items.filter(function(item, index){
  165. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  166. if( item.data.id && this.data.id){
  167. return item.data.id === this.data.id;
  168. }
  169. }.bind(this));
  170. this.items = items;
  171. if (items.length){
  172. items.each(function(item){
  173. item.selectedItem = this;
  174. item.setSelected();
  175. }.bind(this));
  176. }
  177. }
  178. }
  179. });
  180. MWF.xApplication.Selector.FormStyle.ItemCategory = new Class({
  181. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  182. clickItem: function (callback) {
  183. if (this._hasChild() ) {
  184. var firstLoaded = !this.loaded;
  185. this.loadSub(function () {
  186. if (firstLoaded && this._hasChild() ) {
  187. if (!this.selector.isFlatCategory) {
  188. this.children.setStyles({"display": "block", "height": "auto"});
  189. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  190. this.isExpand = true;
  191. }
  192. // this.checkSelectAll();
  193. } else {
  194. var display = this.children.getStyle("display");
  195. if (display === "none") {
  196. // this.selector.fireEvent("expand", [this] );
  197. this.children.setStyles({"display": "block", "height": "auto"});
  198. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  199. this.isExpand = true;
  200. } else {
  201. // this.selector.fireEvent("collapse", [this] );
  202. this.children.setStyles({"display": "none", "height": "0px"});
  203. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  204. this.isExpand = false;
  205. }
  206. }
  207. if (callback) callback();
  208. }.bind(this));
  209. }
  210. },
  211. loadSub: function (callback) {
  212. if (!this.loaded) {
  213. if( this.data.subItemList ){
  214. this.data.subItemList.each(function (subItem, index) {
  215. var item = this.selector._newItem(subItem, this.selector, this.children, this.level + 1, this);
  216. this.selector.items.push(item);
  217. if(this.subItems)this.subItems.push( item );
  218. }.bind(this));
  219. }
  220. if( this.data.scriptList ){
  221. this.data.scriptList.each(function (subItem, index) {
  222. var item = this.selector._newItem(subItem, this.selector, this.children, this.level + 1, this);
  223. this.selector.items.push(item);
  224. if(this.subItems)this.subItems.push( item );
  225. }.bind(this));
  226. }
  227. if ( this.data.applicationList ) {
  228. this.data.applicationList.each(function (subCategory, index) {
  229. var category = this.selector._newItemCategory(subCategory, this.selector, this.children, this.level + 1, this);
  230. this.subCategorys.push( category );
  231. }.bind(this));
  232. }
  233. this.loaded = true;
  234. if (callback) callback();
  235. } else {
  236. if (callback) callback();
  237. }
  238. },
  239. _getShowName: function(){
  240. return this.data.name;
  241. },
  242. _getTtiteText: function () {
  243. return this.data.name;
  244. },
  245. createNode: function(){
  246. this.node = new Element("div", {
  247. "styles": this.selector.css.selectorItemCategory_department
  248. }).inject(this.container);
  249. },
  250. _setIcon: function(){
  251. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  252. },
  253. _hasChild: function(){
  254. return ( this.data.scriptList && this.data.scriptList.length ) ||
  255. ( this.data.subItemList && this.data.subItemList.length) ||
  256. ( this.data.applicationList && this.data.applicationList.length);
  257. },
  258. afterLoad: function(){
  259. if ( this._hasChild() ){
  260. this.clickItem();
  261. }
  262. },
  263. check: function(){}
  264. });