FormStyle.js 14 KB

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