ext portal+dwr+spring实现个性主页面拖拉效果的核心代码

  1. 个性化主页设置,左边是一棵树,左边是一个portal.点击树加载到portal中去,实现了与数据库的交互.
  2. ccom.dzf.indexset= function (config){
  3. Ext.apply( this ,config);
  4. this .init();
  5. };
  6. Ext.extend(com.dzf.indexset,Ext.util.Observable,{
  7. init: function (){
  8. this .createWin();
  9. },
  10. createWin: function (){
  11. var proxy= this ;
  12. var win= new Ext.Window({
  13. height:450,
  14. width:800,
  15. items:[{
  16. xtype: 'tabpanel' ,
  17. border: false ,
  18. activeTab:0,
  19. defaults:{
  20. height:380
  21. },
  22. items:[{
  23. title: '主页设置' ,
  24. layout: 'column' ,
  25. border: false ,
  26. items:[{
  27. columnWidth:.2,
  28. title: '模块列表' ,
  29. defaults:{
  30. height:380
  31. },
  32. items:[ this .getTree()]
  33. },{
  34. xtype: 'portal' ,
  35. columnWidth:.8,
  36. id: 'portalset' ,
  37. defaults:{
  38. height:380
  39. }
  40. }]
  41. },{
  42. title: '设置密码'
  43. }]
  44. }],
  45. buttons:[{
  46. text: '确定' ,
  47. handler: function (){
  48. win.close();
  49. var portal=Ext.getCmp(proxy.panelid);
  50. //portal.desto;
  51. items=portal.items.items[0].destroy();
  52. //for(vari=0;i<items.length;i++){
  53. //varp=items[i].items.items;
  54. //items[i].doLayout();
  55. for(varj=0;j<p.length;j++){
  56. count++;
  57. }
  58. //}
  59. //portal.doLayout();
  60. new com.dzf.index({
  61. panelid: 'center-panel' ,
  62. margins: '35555' ,
  63. style: 'padding:0px10px0px10px'
  64. });
  65. }
  66. }]
  67. });
  68. win.show();
  69. },
  70. getTree: function (){
  71. var tree= new Ext.tree.TreePanel({
  72. border: false ,
  73. onlyLeafCheckable: false ,
  74. checkModel: "multiple" ,
  75. id: 'tree' ,
  76. autoScroll: true ,
  77. enableDD: false ,
  78. containerScroll: true ,
  79. rootVisible: false ,
  80. loader: new Ext.tree.DWRTreeLoader({
  81. dwrCall:indexportalService.getUserModule,
  82. getParams: function (node){
  83. return {};
  84. },
  85. baseAttrs:{
  86. uiProvider:Ext.tree.TreeCheckNodeUI
  87. }
  88. }),
  89. tools:[{
  90. id: 'refresh' , //根据id的不同会出现不同的按钮
  91. handler: function (){
  92. var tree=Ext.getCmp( 'extExample-tree-checkboxTree' );
  93. tree.root.reload(); //让根节点重新加载
  94. tree.body.mask( '数据加载中……' , 'x-mask-loading' ); //给tree的body加上蒙版
  95. tree.root.expand( true , false , function (){
  96. tree.body.unmask(); //全部展开之后让蒙版消失
  97. indexportalService.getPortalColumns(com.dzf.indexset.prototype.BuildPortColumn);
  98. });
  99. }
  100. }]
  101. });
  102. var root= new Ext.tree.AsyncTreeNode({
  103. text: '根' ,
  104. draggable: false
  105. });
  106. tree.setRootNode(root);
  107. root.expand( true , false , function (){
  108. indexportalService.getPortalColumns(com.dzf.indexset.prototype.BuildPortColumn);
  109. });
  110. //root.loadComplete(true,false,function(){
  111. //indexportalService.getPortalColumns(com.dzf.indexset.prototype.BuildPortColumn);
  112. //});
  113. treeCheckAction= function (node,checked){
  114. var id=node.id;
  115. var title=node.text;
  116. var portlet=Ext.getCmp(id+ "set" );
  117. if (checked){
  118. if (portlet){
  119. return ;
  120. }
  121. var count=0;
  122. var portal=Ext.getCmp( "portalset" ).items.items;
  123. for ( var i=0;i<portal.length;i++){
  124. var p=portal[i].items.items;
  125. for ( var j=0;j<p.length;j++){
  126. count++;
  127. }
  128. }
  129. if (count<=4){
  130. var order=0;
  131. var parent=Ext.getCmp( "portalcolumn" +node.attributes.userid
  132. +node.attributes.modulecolumn+ "set" );
  133. var panel= new Ext.ux.Portlet({
  134. id:id+ "set" ,
  135. title:title
  136. });
  137. if (!parent){
  138. parent=Ext.getCmp( "portalset" ).items.items[0];
  139. }
  140. parent.add(panel);
  141. parent.doLayout();
  142. order=parent.items.items.length-1;
  143. var params={
  144. id:id,
  145. order:order,
  146. columnwidth:parent.columnWidth
  147. };
  148. indexportalService.savePortlet(params);
  149. } else {
  150. node.ui.checkbox.checked= false ;
  151. Ext.MessageBox.alert( "提示" , "你最多能选择5个!" )
  152. }
  153. } else {
  154. com.dzf.indexset.prototype.removePorlet(portlet);
  155. }
  156. }
  157. tree.on( "check" ,treeCheckAction, this );
  158. return tree;
  159. },
  160. tools:[{
  161. id: 'close' ,
  162. handler: function (e,target,panel){
  163. com.dzf.indexset.prototype.removePorlet(panel);
  164. }
  165. }],
  166. removePorlet: function (panel){
  167. //Ext.Msg.confirm('删除模块','您确认要删除"'+panel.title+'"吗?',
  168. //function(btn,
  169. //text){
  170. //if(btn=='yes'){
  171. var id=panel.id;
  172. var columnid=panel.ownerCt.id;
  173. var params={
  174. id:id,
  175. columnid:columnid
  176. };
  177. //发送删除数据的请求
  178. indexportalService.removePorlet(params, function (data){
  179. var json=Ext.util.JSON.decode(data);
  180. if (json.success){
  181. var id=panel.id;
  182. var parent=panel.ownerCt;
  183. parent.remove(panel, true );
  184. parent.doLayout();
  185. if (id.indexOf( "set" )>0)
  186. id=id.substring(0,id.indexOf( "set" ));
  187. Ext.getCmp( "tree" ).getNodeById(id).ui.checkbox.checked= false ;
  188. } else {
  189. Ext.Msg.alert( 'WebMessage' ,panel.title+ '删除失败!' );
  190. }
  191. });
  192. //}else{
  193. //return;
  194. //}
  195. //});
  196. },
  197. BuildPortColumn: function (data){
  198. var jsonData=Ext.util.JSON.decode(data);
  199. for ( var i=0;i<jsonData.length;i++){
  200. var columnid=jsonData[i].fuserprocolumn_id+ "set" ;
  201. var columnwidth=jsonData[i].fuserprocolumn_width/100;
  202. var portal=Ext.getCmp( "portalset" );
  203. var PortalColumn= new Ext.ux.PortalColumn({
  204. id:columnid,
  205. columnWidth:columnwidth,
  206. style: 'padding:10px010px10px' ,
  207. defaults:{
  208. tools:com.dzf.indexset.prototype.tools,
  209. height:60
  210. }
  211. });
  212. portal.add(PortalColumn);
  213. portal.doLayout();
  214. }
  215. indexportalService
  216. .getPortalPortlet(com.dzf.indexset.prototype.BuildPortletSet);
  217. },
  218. BuildPortletSet: function (data){
  219. var jsonData=Ext.util.JSON.decode(data);
  220. for ( var i=0;i<jsonData.length;i++){
  221. var columnid=jsonData[i].fuserprocolumn_id+ "set" ;
  222. var id=jsonData[i].modelcode+ "set" ;
  223. var title=jsonData[i].modelname;
  224. var order=jsonData[i].fuserprofile_order;
  225. var parent=Ext.getCmp(columnid);
  226. if (!parent){
  227. parent=Ext.getCmp( "portalset" ).items.items[0];
  228. }
  229. var panel= new Ext.ux.Portlet({
  230. id:id,
  231. title:title
  232. });
  233. parent.add(panel);
  234. parent.doLayout();
  235. if (id.indexOf( "set" )>0)
  236. id=id.substring(0,id.indexOf( "set" ));
  237. Ext.getCmp( "tree" ).getNodeById(id).ui.checkbox.checked= true ;
  238. }
  239. }
  240. })
  241. protal源码改了下可以进行移动保存
  242. Ext.ux.Portlet=Ext.extend(Ext.Panel,{
  243. anchor: '100%' ,
  244. collapsible: true ,
  245. draggable: true ,
  246. cls: 'x-portlet'
  247. });
  248. Ext.reg( 'portlet' ,Ext.ux.Portlet);
  249. Ext.ux.PortalColumn=Ext.extend(Ext.Container,{
  250. layout: 'anchor' ,
  251. autoEl: 'div' ,
  252. defaultType: 'portlet' ,
  253. cls: 'x-portal-column'
  254. });
  255. Ext.reg( 'portalcolumn' ,Ext.ux.PortalColumn);
  256. Ext.ux.Portal=Ext.extend(Ext.Panel,{
  257. layout: 'column' ,
  258. autoScroll: true ,
  259. cls: 'x-portal' ,
  260. defaultType: 'portalcolumn' ,
  261. initComponent: function (){
  262. Ext.ux.Portal.superclass.initComponent.call( this );
  263. this .addEvents({
  264. validatedrop: true ,
  265. beforedragover: true ,
  266. dragover: true ,
  267. beforedrop: true ,
  268. drop: true
  269. });
  270. },
  271. initEvents: function (){
  272. Ext.ux.Portal.superclass.initEvents.call( this );
  273. this .dd= new Ext.ux.Portal.DropZone( this ,
  274. this .dropConfig);
  275. },
  276. beforeDestroy: function (){
  277. if ( this .dd){
  278. this .dd.unreg();
  279. }
  280. Ext.ux.Portal.superclass.beforeDestroy.call( this );
  281. }
  282. });
  283. Ext.reg( 'portal' ,Ext.ux.Portal);
  284. Ext.ux.Portal.DropZone= function (portal,cfg){
  285. this .portal=portal;
  286. Ext.dd.ScrollManager.register(portal.body);
  287. Ext.ux.Portal.DropZone.superclass.constructor.call( this ,
  288. portal.bwrap.dom,cfg);
  289. portal.body.ddScrollConfig= this .ddScrollConfig;
  290. };
  291. Ext.extend(Ext.ux.Portal.DropZone,Ext.dd.DropTarget,{
  292. ddScrollConfig:{
  293. vthresh:50,
  294. hthresh:-1,
  295. animate: true ,
  296. increment:200
  297. },
  298. createEvent: function (dd,e,data,col,c,pos){
  299. return {
  300. portal: this .portal,
  301. panel:data.panel,
  302. columnIndex:col,
  303. column:c,
  304. position:pos,
  305. data:data,
  306. source:dd,
  307. rawEvent:e,
  308. status: this .dropAllowed
  309. };
  310. },
  311. notifyOver: function (dd,e,data){
  312. var xy=e.getXY(),portal= this .portal,px=dd.proxy;
  313. //casecolumnwidths
  314. if (! this .grid){
  315. this .grid= this .getGrid();
  316. }
  317. //handlecasescrollwherescrollbarsappearduringdrag
  318. var cw=portal.body.dom.clientWidth;
  319. if (! this .lastCW){
  320. this .lastCW=cw;
  321. } else if ( this .lastCW!=cw){
  322. this .lastCW=cw;
  323. portal.doLayout();
  324. this .grid= this .getGrid();
  325. }
  326. //determinecolumn
  327. var col=0,xs= this .grid.columnX,cmatch= false ;
  328. for ( var len=xs.length;col<len;col++){
  329. if (xy[0]<(xs[col].x+xs[col].w)){
  330. cmatch= true ;
  331. break ;
  332. }
  333. }
  334. //nomatch,fixlastindex
  335. if (!cmatch){
  336. col--;
  337. }
  338. //findinsertposition
  339. var p,match= false ,pos=0,c=portal.items.itemAt(col),items=c.items.items;
  340. for ( var len=items.length;pos<len;pos++){
  341. p=items[pos];
  342. var h=p.el.getHeight();
  343. if (h!==0&&(p.el.getY()+(h/2))>xy[1]){
  344. match= true ;
  345. break ;
  346. }
  347. }
  348. var overEvent= this .createEvent(dd,e,data,col,c,match&&p
  349. ?pos
  350. :c.items.getCount());
  351. if (portal.fireEvent( 'validatedrop' ,overEvent)!== false
  352. &&portal.fireEvent( 'beforedragover' ,overEvent)!== false ){
  353. //makesureproxywidthisfluid
  354. px.getProxy().setWidth( 'auto' );
  355. if (p){
  356. px.moveProxy(p.el.dom.parentNode,match?p.el.dom: null );
  357. } else {
  358. px.moveProxy(c.el.dom, null );
  359. }
  360. this .lastPos={
  361. c:c,
  362. col:col,
  363. p:match&&p?pos: false
  364. };
  365. this .scrollPos=portal.body.getScroll();
  366. portal.fireEvent( 'dragover' ,overEvent);
  367. return overEvent.status;;
  368. } else {
  369. return overEvent.status;
  370. }
  371. },
  372. notifyOut: function (){
  373. delete this .grid;
  374. },
  375. notifyDrop: function (dd,e,data){
  376. delete this .grid;
  377. if (! this .lastPos){
  378. return ;
  379. }
  380. var c= this .lastPos.c,col= this .lastPos.col,pos= this .lastPos.p;
  381. var dropEvent= this .createEvent(dd,e,data,col,c,pos!== false
  382. ?pos
  383. :c.items.getCount());
  384. if ( this .portal.fireEvent( 'validatedrop' ,dropEvent)!== false
  385. && this .portal.fireEvent( 'beforedrop' ,dropEvent)!== false ){
  386. dd.proxy.getProxy().remove();
  387. dd.panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
  388. if (pos!== false ){
  389. c.insert(pos,dd.panel);
  390. } else {
  391. c.add(dd.panel);
  392. }
  393. /**
  394. *取得当前portlet在portalcolumn中的索引
  395. */
  396. var index=0;
  397. var portletId=dd.panel.id;
  398. if (pos!= false ){
  399. var portlets=c.items;
  400. for ( var i=0;i<portlets.length;i++){
  401. if (c.items.itemAt(i).id===portletId){
  402. index=i;
  403. break ;
  404. }
  405. }
  406. } else {
  407. if (pos.toString()== '0' ){
  408. index=0;
  409. } else {
  410. index=c.items.length-1;
  411. }
  412. }
  413. c.doLayout();
  414. //更新移动后的Portlet
  415. var params={
  416. id:dd.panel.id,
  417. columnid:c.id,
  418. forder:index
  419. };
  420. indexportalService.movePortlet(params);
  421. this .portal.fireEvent( 'drop' ,dropEvent);
  422. //scrollpositionislostondrop,fixit
  423. var st= this .scrollPos.top;
  424. if (st){
  425. var d= this .portal.body.dom;
  426. setTimeout( function (){
  427. d.scrollTop=st;
  428. },10);
  429. }
  430. }
  431. delete this .lastPos;
  432. },
  433. //internalcacheofbodyandcolumncoords
  434. getGrid: function (){
  435. var box= this .portal.bwrap.getBox();
  436. box.columnX=[];
  437. this .portal.items.each( function (c){
  438. box.columnX.push({
  439. x:c.el.getX(),
  440. w:c.el.getWidth()
  441. });
  442. });
  443. return box;
  444. },
  445. //unregisterthedropzonefromScrollManager
  446. unreg: function (){
  447. //Ext.dd.ScrollManager.unregister(this.portal.body);
  448. Ext.ux.Portal.DropZone.superclass.unreg.call( this );
  449. }
  450. });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值