06da66f54eb7afafcc28dbbe1c549fc3a2115d6b.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*********************************************打桩 成功************************************/
  2. /*
  3. *创建jquery插件:quickgridAndSingleRecode
  4. */
  5. (function ($) {
  6. $.fn.quickgridAndSingleRecode = function (opt) {
  7. var gridAndSingleRecode=new GridAndSingleRecode(opt);
  8. gridAndSingleRecode.createGridAndSingleRecode(this.attr("id"));
  9. return gridAndSingleRecode;
  10. };
  11. })(jQuery);
  12. /*********************************************打桩 成功 *********************************************/
  13. /*
  14. *创建jquery插件:quickSingleRecode
  15. */
  16. (function($) {
  17. $.fn.quickSingleRecode = function(opt,grid) {
  18. var singleRecode=new SingleRecode(opt);
  19. singleRecode.createSingleRecode(this.attr("id"),grid);
  20. return gridAndSingleRecode;
  21. };
  22. })(jQuery);
  23. /*
  24. *创建jquery插件:quickPaper
  25. */
  26. (function($) {
  27. $.fn.quickPaper = function(opt,grid) {
  28. var paperObject=new PaperObject(opt,grid);
  29. /////////
  30. paperObject.createPaper(this.attr("id"));
  31. return paperObject;
  32. };
  33. })(jQuery);
  34. /*
  35. *创建jquery插件:quickPaper
  36. */
  37. (function($) {
  38. $.fn.quickToolBar = function(opt,grid) {
  39. var toolBar=new ToolBar(opt);
  40. toolBar.createToolBar(this.attr("id"),grid);
  41. return toolBar;
  42. };
  43. })(jQuery);
  44. /*********************************************打桩 成功 *********************************************/
  45. /*
  46. *创建SingleRecodejQuery对象
  47. *
  48. */
  49. function ToolBar(opt){
  50. var defaults = {};
  51. this.options=$.extend(defaults, opt);
  52. this.common;
  53. }
  54. ToolBar.prototype.createToolBar=function(con_id,grid){
  55. this.common=grid;
  56. $("#"+con_id).append("<div id='toolbar_operation' class='_operation'></div>");
  57. var items=this.options.items
  58. for(var item in items){
  59. $("#toolbar_operation").append("<div class='_line'></div>");
  60. if(items[item].line==null){
  61. $("#toolbar_operation").append("<div><a href='javascript:;'><span class="+items[item].iconClass+">"+items[item].text+"</span></a></div>");
  62. if(items[item].params==null){
  63. $("#toolbar_operation div:last-child").on("click",items[item].click);
  64. }else{
  65. $("#toolbar_operation div:last-child").on("click",{params:items[item].params},items[item].click);
  66. }
  67. }
  68. if(items[item].line==true){
  69. $("#toolbar_operation").append("<div class='_line'>|</div>");
  70. }
  71. }
  72. $("#toolBar_id").append("<div class='_ToolBar_id_change'><ul><li><a id='toolBar_singleRecode' href='javascript:;'><span class='icon_view'>单条记录视图</span></a></li>" +
  73. "<li><a id='toolBar_grid' href='javascript:;'><span class='icon_view'>grid表格视图</span></a></li></ul></div><div class='_clear'></div>")
  74. }
  75. ToolBar.prototype.bindEvent=function(onId,stateData,fn_event){
  76. $("#"+onId).on("click",{state:stateData},fn_event);
  77. }
  78. /*********************************************打桩 成功 *********************************************/
  79. /*
  80. *创建SingleRecodejQuery对象
  81. *
  82. */
  83. function SingleRecode(opt){
  84. var defaults = {};
  85. this.options=$.extend(defaults, opt);
  86. }
  87. SingleRecode.prototype.createSingleRecode=function(con_id,grid){
  88. $("#"+con_id).empty();
  89. for (var record in grid.records){
  90. var cloumnData=grid.records[record];
  91. $("#"+con_id).append("<ul id="+JSON.stringify(record)+"></ul>");
  92. var columns=grid.options.columns;
  93. for(var i=0;i<columns.length;i++){
  94. var column=columns[i];
  95. var record_str=JSON.stringify(record);
  96. var id_str = record_str.substring(1, record_str.length-1);
  97. if(column.hide==null){
  98. $("#"+id_str).append("<li ><span>"+column.display+": </span><p name='"+column.name+"' ><a href='javascript:;' title='"+cloumnData[column.name]+"'>"+cloumnData[column.name]+"</a></p></li>");
  99. }
  100. }
  101. }
  102. // $("#"+con_id).addClass("_form_id");
  103. $("#"+con_id+" ul").each(function (i){$(this).find("li").eq(0).addClass("firstLi")});
  104. }
  105. /*********************************************打桩 成功 *********************************************/
  106. /*
  107. *创建分页对象
  108. *
  109. */
  110. function PaperObject(opt,grid){
  111. var defaults = {
  112. pageSize:"10",
  113. //total:"200",
  114. page:"10",
  115. showSelect:"false",
  116. selectDirection:"top",
  117. selectData:'{"list":[{"key":10,"value":10},{"key":20,"value":20},{"key":50,"value":50},{"key":100,"value":100}]}',
  118. inputPosition:"center",
  119. showNumber:"1",
  120. centerPageNum:"4"
  121. };
  122. this.options = $.extend(defaults, opt);
  123. var papergrid=grid;
  124. }
  125. PaperObject.prototype.createPaper=function(papercon_id){
  126. $("#"+papercon_id).append("<div class='pageArrow _pageArrow' total='200' id='page'></div>");
  127. $("#page").attr(this.options);
  128. $("#page").render();
  129. // $("#page").on("pageChange",{aa:"num"},function(e,index){
  130. // alert(index);
  131. // alert(e.data.aa);
  132. // alert($(this).attr("pageSize"));
  133. // });
  134. // $("#page").bind("sizeChange",function(e,num){
  135. // alert(num);
  136. // });
  137. }
  138. PaperObject.prototype.bindEvent=function(gridAndSingleRecodeObject,fn_changePage){
  139. $("#page").on("pageChange",{gridAndSingleRecode:gridAndSingleRecodeObject},fn_changePage);
  140. $("#page").on("sizeChange",{gridAndSingleRecode:gridAndSingleRecodeObject},
  141. function(e,num){
  142. gridAndSingleRecodeObject.grid.setOptions({pageSize:num});
  143. gridAndSingleRecodeObject.grid.setOptions({page:1});
  144. //alert(typeof gridAndSingleRecodeObject.paper.options.page);
  145. gridAndSingleRecodeObject.paper.options.page=0;
  146. $("#page").render();
  147. //alert(gridAndSingleRecodeObject.paper.options.page);
  148. $.post(gridAndSingleRecodeObject.grid.options.url,
  149. {"listId" : "321","condition" :"IS_DEL=0","pager.pageNo":1, "pager.pageSize":$(this).attr("pageSize")},
  150. function(result){
  151. $("#page").attr("total",result["pager.totalRows"]);
  152. $("#page").render();
  153. gridAndSingleRecodeObject.grid.setOptions({data : result});
  154. gridAndSingleRecodeObject.grid.loadData();
  155. gridAndSingleRecodeObject.singleRecode=$("#singleRecode_id").quickSingleRecode(gridAndSingleRecodeObject.options.singleRecodeOptions,gridAndSingleRecodeObject.grid);
  156. },"json");
  157. //alert("pagesize:"+num);
  158. //alert("page:"+parseInt($(this).attr("page")));
  159. // e.data.gridAndSingleRecode.grid.setOptions({pageSize:num});
  160. // e.data.gridAndSingleRecode.grid.setOptions({page:1});
  161. // alert(111);
  162. // alert(e.data.gridAndSingleRecode.grid.options.page);
  163. // //alert("grid表格每页数据:"+e.data.gridAndSingleRecode.grid.options.pageSize);
  164. // e.data.gridAndSingleRecode.grid.loadData();
  165. // gridAndSingleRecodeObject.singleRecode=$("#singleRecode_id").quickSingleRecode(gridAndSingleRecodeObject.options.singleRecodeOptions,gridAndSingleRecodeObject.grid);
  166. //// fn_changePage({data:{gridAndSingleRecode:gridAndSingleRecodeObject}},parseInt($(this).attr("page")));
  167. //// $("#page").on("pageChange",{gridAndSingleRecode:gridAndSingleRecodeObject},fn_changePage({data:{gridAndSingleRecode:gridAndSingleRecodeObject}},parseInt($(this).attr("page")));
  168. });
  169. }
  170. /*********************************************打桩 成功 *********************************************/
  171. /*
  172. *创建GridAndSingleRecode对象
  173. *
  174. */
  175. function GridAndSingleRecode(opt){
  176. var defaults = {gridOptions:{},
  177. singleRecodeOptions:{},
  178. paperOpration:{},
  179. toolBarOprations:{}
  180. };
  181. this.options = $.extend(defaults, opt);
  182. this.singleRecode;
  183. this.grid;
  184. this.paper;
  185. this.toolBar;
  186. }
  187. //创建实例
  188. GridAndSingleRecode.prototype.createGridAndSingleRecode=function (con_id){
  189. var content_id=con_id;
  190. $("#"+content_id).append("<div id='toolBar_id' class='_ToolBar_id'></div><div class='_clear'></div>");
  191. $("#"+content_id).append("<div id='main_content' class='_main_content'></div>");
  192. $("#main_content").append("<div id='grid_id' class='_grid_id'></div>");
  193. $("#main_content").append("<div id='singleRecode_id' class='_form_id'></div>");
  194. $("#"+content_id).append("<div id='paper_id' class='_paper_id'></div>");
  195. this.grid=$("#grid_id").quiGrid(this.options.gridOptions);
  196. // function writeObj(obj){
  197. // var description = "";
  198. // for(var i in obj){
  199. // var property=obj[i];
  200. // description+=i+" = "+property+"\n";
  201. // }
  202. // alert(description);
  203. // }
  204. // alert(typeof this.grid.records.data);
  205. // alert( writeObj(this.grid.records))
  206. //alert( this.grid.records.data["pager.totalRows"]);
  207. //alert(typeof this.grid.options.data["form.paginate.totalRows"]);
  208. //$("#grid_id div[class='l-panel-bar']").hide();
  209. this.toolBar=$("#toolBar_id").quickToolBar(this.options.toolBarOptions,this.grid);
  210. $("#singleRecode_id").hide();
  211. this.paper=$("#paper_id").quickPaper(this.options.paperOpration,this.grid);
  212. this.toolBar.bindEvent("toolBar_singleRecode",{num:2,gridAndSingleRecodeParam:this},this.changeView);
  213. this.toolBar.bindEvent("toolBar_grid",{num:1,gridAndSingleRecodeParam:this},this.changeView);
  214. this.changePage(this,changePage);
  215. }
  216. //改变状态
  217. GridAndSingleRecode.prototype.changeView=function(event){
  218. if(0==event.data.state.num%2){
  219. event.data.state.gridAndSingleRecodeParam.singleRecode=$("#singleRecode_id").quickSingleRecode(event.data.state.gridAndSingleRecodeParam.options.singleRecodeOptions,event.data.state.gridAndSingleRecodeParam.grid);
  220. $("#grid_id").hide();
  221. $("#singleRecode_id").show();
  222. };
  223. if(1==event.data.state.num%2){
  224. $("#singleRecode_id").hide();
  225. $("#grid_id").show();
  226. };
  227. }
  228. GridAndSingleRecode.prototype.rendPaper=function(){
  229. alert("!!!!"+$("span[class='l-bar-text']").text())
  230. var mountStr=$("span[class='l-bar-text']").text();
  231. var mount=mountStr.substring(mountStr.lastIndexOf('总')+1,mountStr.lastIndexOf('条'));
  232. alert(parseInt(mount));
  233. $("#page").attr("total",parseInt(mount));
  234. $("#page").render();
  235. alert(this.paper.total);
  236. }
  237. //改变数据
  238. GridAndSingleRecode.prototype.changeData=function(){
  239. singleRecode=$("#singleRecode_id").quickSingleRecode(this.options.ingleRecodeOptions,grid);
  240. }
  241. GridAndSingleRecode.prototype.changePage=function(gridAndSingleRecodeObject,fn_change){
  242. var gridAndSingleRecode=gridAndSingleRecodeObject;
  243. this.paper.bindEvent(gridAndSingleRecode,fn_change);
  244. }
  245. function changePage(e,index){
  246. $.post(e.data.gridAndSingleRecode.grid.options.url,
  247. $.extend(e.data.gridAndSingleRecode.grid.options.params,{"pager.pageNo":index+1, "pager.pageSize":$(this).attr("pageSize")}),
  248. function(result){
  249. $("#page").attr("total",result["pager.totalRows"]);
  250. $("#page").render();
  251. e.data.gridAndSingleRecode.grid.setOptions({ data : result});
  252. e.data.gridAndSingleRecode.grid.loadData();
  253. e.data.gridAndSingleRecode.singleRecode=$("#singleRecode_id").quickSingleRecode(e.data.gridAndSingleRecode.options.singleRecodeOptions,e.data.gridAndSingleRecode.grid);
  254. },"json");
  255. }