FormStyle.js 15 KB

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