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     getAutoCreate : function()
52     {
53         var cfg = {
54             tag : 'div',
55             cls : 'roo-document-viewer',
56             cn : [
57                 {
58                     tag : 'div',
59                     cls : 'roo-document-viewer-body',
60                     cn : [
61                         {
62                             tag : 'div',
63                             cls : 'roo-document-viewer-thumb',
64                             cn : [
65                                 {
66                                     tag : 'img',
67                                     cls : 'roo-document-viewer-image'
68                                 }
69                             ]
70                         }
71                     ]
72                 },
73                 {
74                     tag : 'div',
75                     cls : 'roo-document-viewer-footer',
76                     cn : {
77                         tag : 'div',
78                         cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
79                         cn : [
80                             {
81                                 tag : 'div',
82                                 cls : 'btn-group',
83                                 cn : [
84                                     {
85                                         tag : 'button',
86                                         cls : 'btn btn-default roo-document-viewer-trash',
87                                         html : '<i class="fa fa-trash"></i>'
88                                     }
89                                 ]
90                             }
91                         ]
92                     }
93                 }
94             ]
95         };
96         
97         return cfg;
98     },
99     
100     initEvents : function()
101     {
102         
103         this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
104         this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
105         
106         this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
107         this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
108         
109         this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
110         this.imageEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
111         
112         this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
113         this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
114         
115         this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
116         this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
117         
118         this.bodyEl.on('click', this.onClick, this);
119         
120         this.trashBtn.on('click', this.onTrash, this);
121         
122     },
123     
124     initial : function()
125     {
126 //        this.thumbEl.setStyle('line-height', this.thumbEl.getHeight(true) + 'px');
127         
128         
129         this.fireEvent('initial', this);
130         
131     },
132     
133     onClick : function(e)
134     {
135         e.preventDefault();
136         
137         this.fireEvent('click', this);
138     },
139     
140     onTrash : function(e)
141     {
142         e.preventDefault();
143         
144         this.fireEvent('trash', this);
145     }
146     
147 });