📜 ⬆️ ⬇️

Client application architecture on ExtJS. Part 2

Extjs
In the previous article we covered such topics: how to organize the code, what the facade is, how to build it, and what the components are.
In this we will touch on three things: let's continue our conversation about component architecture, find out what plugins are and how they help in architecture, and also, as a result, I will give some tips.


Monolithic component



Visiting the forum or looking at examples of using Ext you will almost always see various objects scattered around the entire file, which are eventually attached to one component. For example:
')
Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  1. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  2. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  3. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  4. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  5. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  6. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  7. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  8. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  9. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  10. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  11. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  12. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  13. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  14. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  15. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  16. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  17. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  18. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  19. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  20. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  21. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  22. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  23. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  24. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  25. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  26. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  27. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  28. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  29. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  30. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  31. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  32. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  33. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  34. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);
  35. Copy Source | Copy HTML /** <br/> * somefile.js <br/> * @copyright (c) 2009, by someone <br/> * @date 20 November 2009 <br/> * <br/> */ function entityAdd(button, e){ /* */ } function entityRemove(button, e){ /* */ } function entityEdit(button, e){ /* */ } var somestore = new Ext.data.JsonStore({ /* */ }); var somewindow = new Ext.Window({ /* */ }) Ext. namespace ( "Application" ); Application.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { Ext.apply( this , { store: somestore , bbar: new Ext.PagingToolbar({ pageSize: 50 , store: somestore , displayInfo: true , displayMsg: "Displaying accounts {0} - {1} of {2}" , emptyMsg: "No accounts to display" }) , tbar: new Ext.Toolbar({ , items: [{ , text: "Add" , handler: entityAdd },{ , text: "Edit" , handler: entityEdit },{ , text: "Remove" , handler: entityRemove }] }) }); Application.Grid.superclass.initComponent.apply( this , arguments); } }); Ext.reg( "applicationgrid" , Application.Grid);


Notice that the component class accesses its repository and functions outside its context. This approach is completely unsuitable in large projects, as it leads to a number of problems:

What can I offer to solve these problems? I advise you to do "monolithic" components. Those. design them so that all external resources are members of the grid class. If you take the previous example, here is what code I mean:

Copy Source | Copy HTML
  1. Ext. namespace ( "Application" );
  2. Application.Grid = Ext.extend (Ext.grid.GridPanel, {
  3. initComponent: function () {
  4. // Customize the dialog box
  5. Ext.apply ( this , {
  6. somewindow: new Ext.Window ({ / * Window Settings * / })
  7. });
  8. // Set up the repository
  9. Ext.apply ( this , {
  10. store: new Ext.data.JsonStore ({ / * Storage Settings * / }); // [one]
  11. });
  12. // Customize the toolbar
  13. Ext.apply ( this , {
  14. bbar: new Ext.PagingToolbar ({
  15. pageSize: RESOURCES.SETTINGS.RECORDS_PER_PAGE // [2]
  16. , store: this .store
  17. , displayInfo: true
  18. , displayMsg: "Displaying accounts {0} - {1} of {2}"
  19. , emptyMsg: "No accounts to display"
  20. })
  21. , tbar: new Ext.Toolbar ({
  22. , items: [{
  23. , text: "Add"
  24. , handler: this .entityAdd.createDelegate ( this ) // [3]
  25. }, {
  26. , text: "Edit"
  27. , handler: this .entityEdit.createDelegate ( this )
  28. }, {
  29. , text: "Remove"
  30. , handler: this .entRemove.createDelegate ( this )
  31. }]
  32. })
  33. });
  34. Application.Grid.superclass.initComponent.apply ( this , arguments);
  35. }
  36. , onDestroy: function () {
  37. this .somewindow.destroy ();
  38. Application.Grid.superclass.onDestroy.call ( this );
  39. }
  40. , entityAdd: function (button, e) { / * Entity add code * / }
  41. , entityRemove: function (button, e) { / * Code for deleting an entity * / }
  42. , entityEdit: function (button, e) { / * Entity edit code * / }
  43. , somewindow: undefined
  44. });
  45. Ext.reg ( "applicationgrid" , Application.Grid);


[1] We need at least two Ext.apply blocks. The first is for setting up storage and the second is for setting up paginator. Reason: if you put the definition of the repository and paginator in one Ext.apply block, then the paginator will not be able to refer to the repository by this.store (it stores undefined until this.store block is executed).

[2] See previous article

[3] For an explanation of what createDelegate is, follow here . It is also worth telling briefly what scope is in ExtJS (you will often see it as an argument for a function or property in a configuration). In tutorials there is an accessible explanation of this popular term in the framework. But if it is simple, then scope is the object that will be passed to the function as its context (i.e. this function will be equal to the scope value).

So, what we get with a monolithic approach to component design. In conjunction with createDelegate, we get a component with predictable behavior and get rid of all the problems I listed above. So far, this design method has never let me down, and as experience suggests, we will get a pretty beautiful implementation of OOP, instead of the misery that we’ve got in the tutorials.

Having considered some of the nuances of component design, we can move on to the next topic, the plugin topic.

Plugins



Each successor to the Ext.Component class has a plugins property. Plug-ins can be ordinary functions (I have not tested this option), but most often these are the successors of Ext.util.Observable with the only required init method. How to write them is written here . And here is a simple article explaining the difference in approaches in designing with the use of plug-ins and components. If you briefly retell the article, something like this would come out: plugins are good for small add-ons over components. They are easy to add and easy to remove from the component. Components are more tied to your application and are good at designing a general view of classes.

I would like to expand on these articles a bit. First, when designing paginas, consider the context in which they can be used. For example, if you want to add some functionality to the grid, then you should note that your plugin can easily add to the plugin collection some drop-down list. Checking for such operations is very simple:

Copy Source | Copy HTML
  1. Ext. namespace ( "Ext.ux" );
  2. Ext.ux.Plugin = Ext.extend (Ext.util.Observable, {
  3. init: function (grid) {
  4. if (grid instanceof Ext.grid.GridPanel) {
  5. this .grid = grid;
  6. / * The rest of the code * /
  7. }
  8. }
  9. / * Other * /
  10. });
  11. Ext.preg ( "ourplugin" , Ext.ux.Plugin);


The init method gets an instance of the parent object. Those. the object in which the plugins collection will have our plugin. All we have to do is check it out if it belongs to the right class.

We also need to take into account the life cycle of parent objects when designing plug-ins. For example, a plugin can be added to a component that has not yet been rendered. And this means that with a lazy initialization of its child elements, we cannot turn to them. All we get is the configurations of its children. Therefore, it is desirable for us to perform all our actions after rendering the parent component. This is also very simple. Subscribing to the appropriate event:

Copy Source | Copy HTML
  1. Ext. namespace ( "Ext.ux" );
  2. Ext.ux.Plugin = Ext.extend (Ext.util.Observable, {
  3. init: function (grid) {
  4. if (grid instanceof Ext.grid.GridPanel) {
  5. this .grid = grid;
  6. if (grid.rendered) {
  7. // We have already received the rendered parent component, i.e.
  8. // plugin added after component rendering.
  9. this .onRender ();
  10. } else {
  11. // Otherwise, subscribe to the render event
  12. // parent component
  13. grid.on ({
  14. scope: this
  15. , single: true
  16. , render: this .onRender
  17. , reconfigure: this .onRender
  18. });
  19. }
  20. }
  21. }
  22. , onRender: function () {
  23. / * Parent component is rendered. You can get to work * /
  24. }
  25. });
  26. Ext.preg ( "ourplugin" , Ext.ux.Plugin);


Now we can freely add our plugin to the grid, as well as remove it from there. You should also carefully, as in the case of the components, treat the memory cleaning when the plug-in is eliminated.

The pagins helped me to reduce the amount of code on the project by half, since before them I implemented the extension of the functionality with inheritance.

In addition to plug-ins and components, there is another way to extend the functionality through files from / js / resources. Suppose your application is already sprawled and has a lot of various kinds of component-heirs from the grid. But here comes the requirement that all grids select the first line when loading. We have the opportunity to redefine behavior. In the file from / js / resources we can simply write:

Copy Source | Copy HTML
  1. Ext. override (Ext.grid.GridView, {
  2. onLoad: Ext.grid.GridView.prototype.onLoad.createSequence ( function () {
  3. if ( this .grid.store && this .grid.getSelectionModel (). selectFirstRow) {
  4. this .grid.getSelectionModel (). selectFirstRow.defer ( 1 , this .grid.getSelectionModel ());
  5. }
  6. })
  7. });


Similarly, you can solve, for example, problems such as highlighting the next / previous line when deleting one of the lines or highlighting the newly added line.

This concludes the topic of plugins and extending the functionality of our application. In conclusion, I would like to give some recommendations.

Tips and tricks



You have already noticed that in my examples I put commas before expressions. This habit is not specific to Ext, but having forgotten somewhere to put a comma or, on the contrary, putting a comma after the last element (IE is particularly sensitive about this) you will encounter difficult-to-find errors. With this method of putting commas, the number of errors associated with them will be greatly reduced.

When designing large applications, attach to one version of Ext and do not change it . In the third branch, I found a lot of unpleasant moments related to the fact that the code in 3.0.0 did not work in 3.0.1 or worked with errors.

In the documentation on the API, Ext allows you to view the source codes of its classes. Do not be afraid to look there. You will discover many new things.

The IPA on the charts at the time of this writing is very poorly covered. Use the previous advice, as well as study the graphics in the examples Ext.

On this I will finish the article. I hope she will help someone.

Source: https://habr.com/ru/post/75860/


All Articles