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.

236 lines
6.2 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. var ImageChooser = function(config){
  8. this.config = config;
  9. }
  10. ImageChooser.prototype = {
  11. // cache data by image name for easy lookup
  12. lookup : {},
  13. show : function(el, callback){
  14. if(!this.win){
  15. this.initTemplates();
  16. this.store = new Ext.data.JsonStore({
  17. url: this.config.url,
  18. root: 'images',
  19. fields: [
  20. 'name', 'url',
  21. {name:'size', type: 'float'},
  22. {name:'lastmod', type:'date', dateFormat:'timestamp'}
  23. ],
  24. listeners: {
  25. 'load': {fn:function(){ this.view.select(0); }, scope:this, single:true}
  26. }
  27. });
  28. this.store.load();
  29. var formatSize = function(data){
  30. if(data.size < 1024) {
  31. return data.size + " bytes";
  32. } else {
  33. return (Math.round(((data.size*10) / 1024))/10) + " KB";
  34. }
  35. };
  36. var formatData = function(data){
  37. data.shortName = data.name.ellipse(15);
  38. data.sizeString = formatSize(data);
  39. data.dateString = new Date(data.lastmod).format("m/d/Y g:i a");
  40. this.lookup[data.name] = data;
  41. return data;
  42. };
  43. this.view = new Ext.DataView({
  44. tpl: this.thumbTemplate,
  45. singleSelect: true,
  46. overClass:'x-view-over',
  47. itemSelector: 'div.thumb-wrap',
  48. emptyText : '<div style="padding:10px;">No images match the specified filter</div>',
  49. store: this.store,
  50. listeners: {
  51. 'selectionchange': {fn:this.showDetails, scope:this, buffer:100},
  52. 'dblclick' : {fn:this.doCallback, scope:this},
  53. 'loadexception' : {fn:this.onLoadException, scope:this},
  54. 'beforeselect' : {fn:function(view){
  55. return view.store.getRange().length > 0;
  56. }}
  57. },
  58. prepareData: formatData.createDelegate(this)
  59. });
  60. var cfg = {
  61. title: 'Choose an Image',
  62. id: 'img-chooser-dlg',
  63. layout: 'border',
  64. minWidth: 500,
  65. minHeight: 300,
  66. modal: true,
  67. closeAction: 'hide',
  68. border: false,
  69. items:[{
  70. id: 'img-chooser-view',
  71. region: 'center',
  72. autoScroll: true,
  73. items: this.view,
  74. tbar:[{
  75. text: 'Filter:'
  76. },{
  77. xtype: 'textfield',
  78. id: 'filter',
  79. selectOnFocus: true,
  80. width: 100,
  81. listeners: {
  82. 'render': {fn:function(){
  83. Ext.getCmp('filter').getEl().on('keyup', function(){
  84. this.filter();
  85. }, this, {buffer:500});
  86. }, scope:this}
  87. }
  88. }, ' ', '-', {
  89. text: 'Sort By:'
  90. }, {
  91. id: 'sortSelect',
  92. xtype: 'combo',
  93. typeAhead: true,
  94. triggerAction: 'all',
  95. width: 100,
  96. editable: false,
  97. mode: 'local',
  98. displayField: 'desc',
  99. valueField: 'name',
  100. lazyInit: false,
  101. value: 'name',
  102. store: new Ext.data.ArrayStore({
  103. fields: ['name', 'desc'],
  104. data : [['name', 'Name'],['size', 'File Size'],['lastmod', 'Last Modified']]
  105. }),
  106. listeners: {
  107. 'select': {fn:this.sortImages, scope:this}
  108. }
  109. }]
  110. },{
  111. id: 'img-detail-panel',
  112. region: 'east',
  113. split: true,
  114. width: 150,
  115. minWidth: 150,
  116. maxWidth: 250
  117. }],
  118. buttons: [{
  119. id: 'ok-btn',
  120. text: 'OK',
  121. handler: this.doCallback,
  122. scope: this
  123. },{
  124. text: 'Cancel',
  125. handler: function(){ this.win.hide(); },
  126. scope: this
  127. }],
  128. keys: {
  129. key: 27, // Esc key
  130. handler: function(){ this.win.hide(); },
  131. scope: this
  132. }
  133. };
  134. Ext.apply(cfg, this.config);
  135. this.win = new Ext.Window(cfg);
  136. }
  137. this.reset();
  138. this.win.show(el);
  139. this.callback = callback;
  140. this.animateTarget = el;
  141. },
  142. initTemplates : function(){
  143. this.thumbTemplate = new Ext.XTemplate(
  144. '<tpl for=".">',
  145. '<div class="thumb-wrap" id="{name}">',
  146. '<div class="thumb"><img src="{url}" title="{name}"></div>',
  147. '<span>{shortName}</span></div>',
  148. '</tpl>'
  149. );
  150. this.thumbTemplate.compile();
  151. this.detailsTemplate = new Ext.XTemplate(
  152. '<div class="details">',
  153. '<tpl for=".">',
  154. '<img src="{url}"><div class="details-info">',
  155. '<b>Image Name:</b>',
  156. '<span>{name}</span>',
  157. '<b>Size:</b>',
  158. '<span>{sizeString}</span>',
  159. '<b>Last Modified:</b>',
  160. '<span>{dateString}</span></div>',
  161. '</tpl>',
  162. '</div>'
  163. );
  164. this.detailsTemplate.compile();
  165. },
  166. showDetails : function(){
  167. var selNode = this.view.getSelectedNodes();
  168. var detailEl = Ext.getCmp('img-detail-panel').body;
  169. if(selNode && selNode.length > 0){
  170. selNode = selNode[0];
  171. Ext.getCmp('ok-btn').enable();
  172. var data = this.lookup[selNode.id];
  173. detailEl.hide();
  174. this.detailsTemplate.overwrite(detailEl, data);
  175. detailEl.slideIn('l', {stopFx:true,duration:.2});
  176. }else{
  177. Ext.getCmp('ok-btn').disable();
  178. detailEl.update('');
  179. }
  180. },
  181. filter : function(){
  182. var filter = Ext.getCmp('filter');
  183. this.view.store.filter('name', filter.getValue());
  184. this.view.select(0);
  185. },
  186. sortImages : function(){
  187. var v = Ext.getCmp('sortSelect').getValue();
  188. this.view.store.sort(v, v == 'name' ? 'asc' : 'desc');
  189. this.view.select(0);
  190. },
  191. reset : function(){
  192. if(this.win.rendered){
  193. Ext.getCmp('filter').reset();
  194. this.view.getEl().dom.scrollTop = 0;
  195. }
  196. this.view.store.clearFilter();
  197. this.view.select(0);
  198. },
  199. doCallback : function(){
  200. var selNode = this.view.getSelectedNodes()[0];
  201. var callback = this.callback;
  202. var lookup = this.lookup;
  203. this.win.hide(this.animateTarget, function(){
  204. if(selNode && callback){
  205. var data = lookup[selNode.id];
  206. callback(data);
  207. }
  208. });
  209. },
  210. onLoadException : function(v,o){
  211. this.view.getEl().update('<div style="padding:10px;">Error loading images.</div>');
  212. }
  213. };
  214. String.prototype.ellipse = function(maxLength){
  215. if(this.length > maxLength){
  216. return this.substr(0, maxLength-3) + '...';
  217. }
  218. return this;
  219. };