Roo/bootstrap/DocumentViewer.js
[roojs1] / Roo / bootstrap / DocumentViewer.js
1
2 /*
3 * Licence: LGPL
4 */
5
6 /**
7  * @class Roo.bootstrap.DocumentViewer
8  * @extends Roo.bootstrap.Component
9  * Bootstrap DocumentViewer class
10  * @cfg {Boolean} showDownload (true|false) show download button (default true)
11  * @cfg {Boolean} showTrash (true|false) show trash button (default true)
12  * @cfg {Boolean} clickToDownload (true|false) click to download (default true)
13  * 
14  * @constructor
15  * Create a new DocumentViewer
16  * @param {Object} config The config object
17  */
18
19 Roo.bootstrap.DocumentViewer = function(config){
20     Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
21     
22     this.addEvents({
23         /**
24          * @event initial
25          * Fire after initEvent
26          * @param {Roo.bootstrap.DocumentViewer} this
27          */
28         "initial" : true,
29         /**
30          * @event click
31          * Fire after click
32          * @param {Roo.bootstrap.DocumentViewer} this
33          */
34         "click" : true,
35         /**
36          * @event trash
37          * Fire after trash button
38          * @param {Roo.bootstrap.DocumentViewer} this
39          */
40         "trash" : true
41         
42     });
43 };
44
45 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component,  {
46     
47     showDownload : true,
48     
49     showTrash : true,
50     
51     clickToDownload : true,
52     
53     getAutoCreate : function()
54     {
55         var cfg = {
56             tag : 'div',
57             cls : 'roo-document-viewer',
58             cn : [
59                 {
60                     tag : 'div',
61                     cls : 'roo-document-viewer-body',
62                     cn : [
63                         {
64                             tag : 'div',
65                             cls : 'roo-document-viewer-thumb',
66                             cn : [
67                                 {
68                                     tag : 'img',
69                                     cls : 'roo-document-viewer-image'
70                                 }
71                             ]
72                         }
73                     ]
74                 },
75                 {
76                     tag : 'div',
77                     cls : 'roo-document-viewer-footer',
78                     cn : {
79                         tag : 'div',
80                         cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
81                         cn : [
82                             {
83                                 tag : 'div',
84                                 cls : 'btn-group',
85                                 cn : [
86                                     {
87                                         tag : 'button',
88                                         cls : 'btn btn-default roo-document-viewer-download',
89                                         html : '<i class="fa fa-download"></i>'
90                                     }
91                                 ]
92                             },
93                             {
94                                 tag : 'div',
95                                 cls : 'btn-group',
96                                 cn : [
97                                     {
98                                         tag : 'button',
99                                         cls : 'btn btn-default roo-document-viewer-trash',
100                                         html : '<i class="fa fa-trash"></i>'
101                                     }
102                                 ]
103                             }
104                         ]
105                     }
106                 }
107             ]
108         };
109         
110         return cfg;
111     },
112     
113     initEvents : function()
114     {
115         
116         this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
117         this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
118         
119         this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
120         this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
121         
122         this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
123         this.imageEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
124         
125         this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
126         this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
127         
128         this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
129         this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
130         
131         this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
132         this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
133         
134         this.bodyEl.on('click', this.onClick, this);
135         
136         this.downloadBtn.on('click', this.onDownload, this);
137         
138         this.trashBtn.on('click', this.onTrash, this);
139         
140     },
141     
142     initial : function()
143     {
144 //        this.thumbEl.setStyle('line-height', this.thumbEl.getHeight(true) + 'px');
145         
146         
147         this.fireEvent('initial', this);
148         
149     },
150     
151     onClick : function(e)
152     {
153         e.preventDefault();
154         
155         this.fireEvent('click', this);
156     },
157     
158     onDownload : function(e)
159     {
160         e.preventDefault();
161         
162         this.fireEvent('download', this);
163     },
164     
165     onTrash : function(e)
166     {
167         e.preventDefault();
168         
169         this.fireEvent('trash', this);
170     }
171     
172 });