FormStyle.js 13 KB

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