FormStyle.js 14 KB

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