FormStyle.js 13 KB

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