HTExt.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /**
  2. * 扩展 container
  3. * by cjj
  4. */
  5. Ext.override(Ext.Container, {
  6. getCmpByName : function(name) {
  7. var getByName = function(container, name) {
  8. var items = container.items;
  9. if (items != null) {
  10. for (var i = 0; i < items.getCount(); i++) {
  11. var comp = items.get(i);
  12. var cp = getByName(comp, name);
  13. if (cp != null)
  14. return cp;
  15. if (comp.getName && name == comp.getName()) {
  16. return comp;
  17. break;
  18. }
  19. }
  20. }
  21. return null;
  22. };
  23. return getByName(this, name);
  24. }
  25. });
  26. Ext.ns('HT');
  27. /**
  28. * 转换时间
  29. */
  30. HT.parseLongTime = function(v,dateFormat){
  31. if(Ext.isEmpty(v))
  32. return "";
  33. return Ext.Date.format( new Date(v),(dateFormat?dateFormat:'Y-m-d H:i:s'));
  34. };
  35. HT.parseLongDate = function(v,dateFormat){
  36. if(Ext.isEmpty(v))
  37. return "";
  38. return Ext.Date.format( new Date(v),(dateFormat?dateFormat:'Y-m-d'));
  39. };
  40. HT.loadingText = lang.tip.loadingText;
  41. /**
  42. * 加载
  43. */
  44. HT.loadMask = function(message){
  45. Ext.Viewport.setMasked({
  46. xtype: 'loadmask',
  47. message: message?message:HT.loadingText
  48. });
  49. }
  50. /**
  51. * 取消
  52. */
  53. HT.unMask = function(){
  54. Ext.Viewport.unmask();
  55. }
  56. /**
  57. * 分页数据
  58. */
  59. Ext.define('HT.Store', {
  60. extend:'Ext.data.Store',
  61. name:'htStore',
  62. constructor: function (conf) {
  63. conf = conf || {};
  64. Ext.apply(conf,{
  65. model:conf.model,
  66. pageSize:conf.pageSize?conf.pageSize:10,//对应的每页数据量
  67. currentPage:conf.currentPage?conf.currentPage:1,//当前页
  68. autoLoad: conf.autoLoad?conf.autoLoad:true,
  69. proxy: {
  70. type: "ajax",
  71. url: conf.url,
  72. pageParam: conf.pageParam?conf.pageParam:'page', //设置page参数,默认为page
  73. limitParam: conf.limitParam?conf.limitParam:'pageSize', //设置pageSize参数,默认为pageSize
  74. reader: {
  75. type: 'json',
  76. rootProperty: conf.rootProperty?conf.rootProperty:'results',//顶部数据
  77. totalProperty :conf.totalProperty?conf.totalProperty:'totalCounts'//总记录数
  78. }
  79. }
  80. });
  81. this.callParent([conf]);
  82. }
  83. });
  84. /**
  85. * 分页
  86. */
  87. Ext.define('HT.List', {
  88. extend: 'Ext.List',
  89. name: 'htList',
  90. constructor: function (conf) {
  91. conf = conf || {};
  92. Ext.apply(conf,{
  93. title:conf.title?conf.title:'',
  94. store: conf.store,
  95. scrollable:true,
  96. loadingText:conf.loadingText?conf.loadingText:HT.loadingText,
  97. emptyText:'<p class="no-searches">'+( conf.emptyText?conf.emptyText:lang.tip.noRecords)+'</p>'
  98. });
  99. this.callParent([conf]);
  100. }
  101. });
  102. /**
  103. * 分页
  104. */
  105. Ext.define('HT.PageList', {
  106. extend: 'Ext.List',
  107. name: 'htPageList',
  108. constructor: function (conf) {
  109. conf = conf || {};
  110. Ext.apply(conf,{
  111. title:conf.title?conf.title:'',
  112. store: conf.store,
  113. loadingText:conf.loadingText?conf.loadingText:HT.loadingText,
  114. plugins: [{
  115.     xclass: 'Ext.plugin.PullRefresh',
  116.     pullRefreshText: conf.pullRefreshText?conf.pullRefreshText:lang.tip.pullRefreshText,
  117.     releaseRefreshText: conf.releaseRefreshText?conf.releaseRefreshText:lang.tip.releaseRefreshText,
  118.     loading: conf.loading?conf.loading:lang.tip.loading,
  119. lastUpdatedText:lang.tip.lastUpdatedText,
  120. loadingText :HT.loadingText,
  121.     refreshFn: conf.refreshFn
  122. },{
  123. xclass: 'Ext.plugin.ListPaging',
  124.         loadMoreText: conf.loadMoreText?conf.loadMoreText:lang.tip.loadMoreText,
  125.         noMoreRecordsText: conf.noMoreRecordsText?conf.noMoreRecordsText:lang.tip.noMoreRecordsText,
  126.         autoPaging: true//设置为TRUE将自动触发
  127.       }],
  128. emptyText: '<p class="no-searches">'+( conf.emptyText?conf.emptyText:lang.tip.noRecords)+'</p>',
  129. itemTpl:conf.itemTpl,
  130. listeners:[{
  131. "beforerefresh" : function(){
  132. this.loadMark.enable();
  133. }}
  134. ]
  135. });
  136. this.callParent([conf]);
  137. }
  138. });
  139. /**
  140. * 提交表单
  141. *
  142. * @example
  143. *
  144. * <pre>
  145. * 使用以下所示:
  146. * $postForm({
  147. * formPanel : this.formPanel,
  148. * scope : this,
  149. * url : __ctxPath + '/admin/saveBook.do',
  150. * params : {},
  151. * callback : function(fp, action) {
  152. * if (this.callback) {
  153. * this.callback.call(this.scope);
  154. * }
  155. * this.close();
  156. * }
  157. * });
  158. * </pre>
  159. *
  160. * @param {}
  161. * conf
  162. */
  163. var $postForm = function(conf) {
  164. var scope = conf.scope ? conf.scope : this,
  165. waitMsg = Ext.isEmpty(conf.waitMsg) ? lang.tip.waitMsg : conf.waitMsg,
  166. successMsg = Ext.isEmpty(conf.successMsg)
  167. ? lang.tip.successMsg
  168. : conf.successMsg,
  169. failureMsg = Ext.isEmpty(conf.failureMsg)
  170. ? lang.tip.failureMsg
  171. : conf.failureMsg;
  172. // Mask the form
  173. conf.formPanel.setMasked({
  174. xtype: 'loadmask',
  175. message: waitMsg
  176. });
  177. conf.formPanel.submit({
  178. scope : scope,
  179. url : conf.url,
  180. method : 'post',
  181. params : conf.params,
  182. //waitMsg : waitMsg,
  183. success : function(fp, action) {
  184. if (conf.callback) {
  185. conf.callback.call(scope, fp, action);
  186. }
  187. if (conf.success) {
  188. conf.success.call(scope, fp, action);
  189. }
  190. },
  191. failure : function(fp, action) {
  192. if (!Ext.isEmpty(action) && !Ext.isEmpty(action.msg)) {
  193. failureMsg = action.msg;
  194. }
  195. Ext.Msg.alert('', action.msg);
  196. if (conf.callback) {
  197. conf.callback.call(scope, fp, action);
  198. }
  199. }
  200. });
  201. };
  202. /**
  203. * 扩展String的方法
  204. * var str=String.format("姓名:{0},性别:{1}","ray","男");
  205. * alert(str);
  206. * @return {}
  207. */
  208. String.format=function(){
  209. var template=arguments[0];
  210. var args=arguments;
  211. var str=template.replace(/\{(\d+)\}/g,function(m,i){
  212. var k=parseInt(i)+1;
  213. return args[k];
  214. });
  215. return str;
  216. };