Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
7.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. // setup an App namespace
  8. // This is done to prevent collisions in the global namespace
  9. Ext.ns('App');
  10. /**
  11. * App.BookStore
  12. * @extends Ext.data.Store
  13. * @cfg {String} url This will be a url of a location to load the BookStore
  14. * This is a specialized Store which maintains books.
  15. * It already knows about Amazon's XML definition and will expose the following
  16. * Record defintion:
  17. * - Author
  18. * - Manufacturer
  19. * - ProductGroup
  20. * - DetailPageURL
  21. */
  22. App.BookStore = function(config) {
  23. var config = config || {};
  24. Ext.applyIf(config, {
  25. reader: new Ext.data.XmlReader({
  26. // records will have an "Item" tag
  27. record: 'Item',
  28. id: 'ASIN',
  29. totalRecords: '@total'
  30. }, [
  31. // set up the fields mapping into the xml doc
  32. // The first needs mapping, the others are very basic
  33. {name: 'Author', mapping: 'ItemAttributes > Author'},
  34. 'Title',
  35. 'Manufacturer',
  36. 'ProductGroup',
  37. // Detail URL is not part of the column model of the grid
  38. 'DetailPageURL'
  39. ])
  40. });
  41. // call the superclass's constructor
  42. App.BookStore.superclass.constructor.call(this, config);
  43. };
  44. Ext.extend(App.BookStore, Ext.data.Store);
  45. /**
  46. * App.BookGrid
  47. * @extends Ext.grid.GridPanel
  48. * This is a custom grid which will display book information. It is tied to
  49. * a specific record definition by the dataIndex properties.
  50. *
  51. * It follows a very custom pattern used only when extending Ext.Components
  52. * in which you can omit the constructor.
  53. *
  54. * It also registers the class with the Component Manager with an xtype of
  55. * bookgrid. This allows the application to take care of the lazy-instatiation
  56. * facilities provided in Ext's Component Model.
  57. */
  58. App.BookGrid = Ext.extend(Ext.grid.GridPanel, {
  59. // override
  60. initComponent : function() {
  61. Ext.apply(this, {
  62. // Pass in a column model definition
  63. // Note that the DetailPageURL was defined in the record definition but is not used
  64. // here. That is okay.
  65. columns: [
  66. {header: "Author", width: 120, dataIndex: 'Author', sortable: true},
  67. {header: "Title", dataIndex: 'Title', sortable: true},
  68. {header: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},
  69. {header: "Product Group", dataIndex: 'ProductGroup', sortable: true}
  70. ],
  71. sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
  72. // Note the use of a storeId, this will register thisStore
  73. // with the StoreMgr and allow us to retrieve it very easily.
  74. store: new App.BookStore({
  75. storeId: 'gridBookStore',
  76. url: 'sheldon.xml'
  77. }),
  78. // force the grid to fit the space which is available
  79. viewConfig: {
  80. forceFit: true
  81. }
  82. });
  83. // finally call the superclasses implementation
  84. App.BookGrid.superclass.initComponent.call(this);
  85. }
  86. });
  87. // This will associate an string representation of a class
  88. // (called an xtype) with the Component Manager
  89. // It allows you to support lazy instantiation of your components
  90. Ext.reg('bookgrid', App.BookGrid);
  91. /**
  92. * App.BookDetail
  93. * @extends Ext.Panel
  94. * This is a specialized Panel which is used to show information about
  95. * a book.
  96. *
  97. * This demonstrates adding 2 custom properties (tplMarkup and
  98. * startingMarkup) to the class. It also overrides the initComponent
  99. * method and adds a new method called updateDetail.
  100. *
  101. * The class will be registered with an xtype of 'bookdetail'
  102. */
  103. App.BookDetail = Ext.extend(Ext.Panel, {
  104. // add tplMarkup as a new property
  105. tplMarkup: [
  106. 'Title: <a href="{DetailPageURL}" target="_blank">{Title}</a><br/>',
  107. 'Author: {Author}<br/>',
  108. 'Manufacturer: {Manufacturer}<br/>',
  109. 'Product Group: {ProductGroup}<br/>'
  110. ],
  111. // startingMarup as a new property
  112. startingMarkup: 'Please select a book to see additional details',
  113. // override initComponent to create and compile the template
  114. // apply styles to the body of the panel and initialize
  115. // html to startingMarkup
  116. initComponent: function() {
  117. this.tpl = new Ext.Template(this.tplMarkup);
  118. Ext.apply(this, {
  119. bodyStyle: {
  120. background: '#ffffff',
  121. padding: '7px'
  122. },
  123. html: this.startingMarkup
  124. });
  125. // call the superclass's initComponent implementation
  126. App.BookDetail.superclass.initComponent.call(this);
  127. },
  128. // add a method which updates the details
  129. updateDetail: function(data) {
  130. this.tpl.overwrite(this.body, data);
  131. }
  132. });
  133. // register the App.BookDetail class with an xtype of bookdetail
  134. Ext.reg('bookdetail', App.BookDetail);
  135. /**
  136. * App.BookMasterDetail
  137. * @extends Ext.Panel
  138. *
  139. * This is a specialized panel which is composed of both a bookgrid
  140. * and a bookdetail panel. It provides the glue between the two
  141. * components to allow them to communicate. You could consider this
  142. * the actual application.
  143. *
  144. */
  145. App.BookMasterDetail = Ext.extend(Ext.Panel, {
  146. // override initComponent
  147. initComponent: function() {
  148. // used applyIf rather than apply so user could
  149. // override the defaults
  150. Ext.applyIf(this, {
  151. frame: true,
  152. title: 'Book List',
  153. width: 540,
  154. height: 400,
  155. layout: 'border',
  156. items: [{
  157. xtype: 'bookgrid',
  158. itemId: 'gridPanel',
  159. region: 'north',
  160. height: 210,
  161. split: true
  162. },{
  163. xtype: 'bookdetail',
  164. itemId: 'detailPanel',
  165. region: 'center'
  166. }]
  167. })
  168. // call the superclass's initComponent implementation
  169. App.BookMasterDetail.superclass.initComponent.call(this);
  170. },
  171. // override initEvents
  172. initEvents: function() {
  173. // call the superclass's initEvents implementation
  174. App.BookMasterDetail.superclass.initEvents.call(this);
  175. // now add application specific events
  176. // notice we use the selectionmodel's rowselect event rather
  177. // than a click event from the grid to provide key navigation
  178. // as well as mouse navigation
  179. var bookGridSm = this.getComponent('gridPanel').getSelectionModel();
  180. bookGridSm.on('rowselect', this.onRowSelect, this);
  181. },
  182. // add a method called onRowSelect
  183. // This matches the method signature as defined by the 'rowselect'
  184. // event defined in Ext.grid.RowSelectionModel
  185. onRowSelect: function(sm, rowIdx, r) {
  186. // getComponent will retrieve itemId's or id's. Note that itemId's
  187. // are scoped locally to this instance of a component to avoid
  188. // conflicts with the ComponentMgr
  189. var detailPanel = this.getComponent('detailPanel');
  190. detailPanel.updateDetail(r.data);
  191. }
  192. });
  193. // register an xtype with this class
  194. Ext.reg('bookmasterdetail', App.BookMasterDetail);
  195. // Finally now that we've defined all of our classes we can instantiate
  196. // an instance of the app and renderTo an existing div called 'binding-example'
  197. // Note now that classes have encapsulated this behavior we can easily create
  198. // an instance of this app to be used in many different contexts, you could
  199. // easily place this application in an Ext.Window for example
  200. Ext.onReady(function() {
  201. // create an instance of the app
  202. var bookApp = new App.BookMasterDetail({
  203. renderTo: 'binding-example'
  204. });
  205. // We can retrieve a reference to the data store
  206. // via the StoreMgr by its storeId
  207. Ext.StoreMgr.get('gridBookStore').load();
  208. });