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.

187 lines
6.1 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Imgorg.UploadQueue = Ext.extend(Ext.Panel,{
  16. swfu: '',
  17. autoRemove: false,
  18. uploaded: false,
  19. initComponent: function() {
  20. Ext.apply(this,{
  21. layout: 'fit',
  22. autoScroll: true,
  23. items: [{
  24. xtype: 'dataview',
  25. id: 'img-uploaddv',
  26. autoWidth: true,
  27. tpl: new Ext.XTemplate(
  28. '<tpl for=".">',
  29. '<div class="upload-file" id="{id}">',
  30. '<div class="upload-name">{name}</div>',
  31. '<div id="{id}-pb" class="upload-pb"></div>',
  32. '<div class="x-clear"></div>',
  33. '<div class="upload-info">{size:fileSize}</div>',
  34. '</div>',
  35. '</tpl>'
  36. ),
  37. store: new Ext.data.JsonStore({
  38. root: '',
  39. id: 'id',
  40. fields: [
  41. {name: 'creationdate', type: 'date'},
  42. {name: 'modificationdate', type: 'date'},
  43. 'filestatus','id','index','name','size','type','dbid'
  44. ]
  45. }),
  46. itemSelector: 'div.upload-file',
  47. selectedClass: 'upload-file-selected',
  48. singleSelect: true
  49. }],
  50. tbar:[{
  51. text: 'Start Upload',
  52. handler: this.startUpload,
  53. scope: this,
  54. iconCls: 'start-upload'
  55. },{
  56. text: 'Clear',
  57. handler: this.cancelUpload,
  58. scope: this,
  59. iconCls: 'cancel'
  60. },'-',{
  61. text: 'Add to Album',
  62. handler: this.addAllAlbum,
  63. scope: this,
  64. iconCls: 'album-add'
  65. },{
  66. text: 'Tag',
  67. handler: this.tagAll,
  68. scope: this,
  69. iconCls: 'tag'
  70. },
  71. '->',{
  72. xtype: 'checkbox',
  73. checked: this.autoRemove,
  74. listeners: {
  75. check: function(cb, checked) {
  76. this.autoRemove = checked;
  77. },
  78. scope: this
  79. }
  80. },'Auto-Remove Uploaded']
  81. });
  82. Imgorg.UploadQueue.superclass.initComponent.call(this);
  83. this.progressBars = {};
  84. Ext.ux.SwfuMgr.on('filequeued', this.addFile, this);
  85. Ext.ux.SwfuMgr.on('uploadprogress', this.updateProgress, this);
  86. Ext.ux.SwfuMgr.on('uploadsuccess', this.uploadSuccess, this);
  87. },
  88. getDv: function() {
  89. if (!this.imgUplDv) {
  90. this.imgUplDv = this.getComponent('img-uploaddv');
  91. }
  92. return this.imgUplDv;
  93. },
  94. startUpload: function() {
  95. this.swfu.startUpload();
  96. },
  97. cancelUpload: function() {
  98. this.swfu.cancelUpload();
  99. for (var pb in this.progressBars) {
  100. this.progressBars[pb].destroy();
  101. }
  102. this.getDv().store.removeAll();
  103. this.uploaded = false;
  104. },
  105. addFile: function(swfu, file) {
  106. this.getDv().store.loadData([file], true);
  107. },
  108. addAllAlbum: function(btn) {
  109. if (!this.uploaded) {
  110. Ext.Msg.alert('Warning', 'You must upload files before you can add them to an Album');
  111. return;
  112. }
  113. var dv = this.getDv();
  114. var recs = dv.getRecords(dv.getNodes());
  115. if (!this.albumWin) {
  116. this.albumWin = new Imgorg.AlbumWin();
  117. }
  118. this.albumWin.selectedRecords = recs;
  119. this.albumWin.show(btn.btnEl.dom);
  120. },
  121. tagAll: function(btn) {
  122. if (!this.uploaded) {
  123. Ext.Msg.alert('Warning', 'You must upload files before you can Tag them');
  124. return;
  125. }
  126. var dv = this.getDv();
  127. var recs = dv.getRecords(dv.getNodes());
  128. Imgorg.TagWin.selectedRecords = recs;
  129. Imgorg.TagWin.show(btn.btnEl.dom);
  130. },
  131. updateProgress: function(swfu, file, complete, total) {
  132. if (this.progressBars[file.id]) {
  133. this.progressBars[file.id].updateProgress(file.percentUploaded/100,Math.round(file.percentUploaded)+'% Completed... '+Ext.util.Format.fileSize(file.currentSpeed)+'s');
  134. } else {
  135. this.progressBars[file.id] = new Ext.ProgressBar({
  136. text:'0% Completed...',
  137. renderTo: file.id+'-pb'
  138. });
  139. }
  140. },
  141. uploadSuccess: function(swfu, file, data) {
  142. var store = this.getDv().store;
  143. var rec = store.getById(file.id);
  144. if (this.progressBars[file.id]) {
  145. this.progressBars[file.id].updateProgress(1, '100% Completed...');
  146. }
  147. if (this.autoRemove) {
  148. store.remove(rec);
  149. }
  150. var data = Ext.decode(Ext.util.Format.stripTags(data));
  151. rec.data.dbid = data.result.res.id;
  152. this.uploaded = true;
  153. }
  154. });
  155. Ext.reg('img-uploadqueue', Imgorg.UploadQueue);
  156. Ext.ux.SwfuManager = Ext.extend(Ext.util.Observable, {
  157. constructor: function(config) {
  158. Ext.ux.SwfuManager.superclass.constructor.call(this, config);
  159. this.addEvents(
  160. 'filequeued',
  161. 'uploadstart',
  162. 'uploadprogress',
  163. 'uploaderror',
  164. 'uploadsuccess'
  165. );
  166. }
  167. });
  168. Ext.ux.SwfuMgr = new Ext.ux.SwfuManager();