Add a view for attachment previews

pull/749/head
lilia 10 years ago
parent bb2b53035e
commit f73596c240

@ -156,10 +156,8 @@
</form> </form>
</script> </script>
<script type='text/x-tmpl-mustache' id='attachment-preview'> <script type='text/x-tmpl-mustache' id='attachment-preview'>
<div class="imageAttachment"> <img src="{{ source }}" class="preview" />
<img src="{{ source }}" class="preview" /> <div class="close">x</div>
<div class="close">x</div>
</div>
</script> </script>
<script type='text/x-tmpl-mustache' id='file-size-modal'> <script type='text/x-tmpl-mustache' id='file-size-modal'>
<div id="modal" class="modal-wrapper"> <div id="modal" class="modal-wrapper">
@ -192,6 +190,7 @@
<script type="text/javascript" src="js/chromium.js"></script> <script type="text/javascript" src="js/chromium.js"></script>
<script type="text/javascript" src="js/views/notifications.js"></script> <script type="text/javascript" src="js/views/notifications.js"></script>
<script type="text/javascript" src="js/views/file_modal_view.js"></script> <script type="text/javascript" src="js/views/file_modal_view.js"></script>
<script type="text/javascript" src="js/views/attachment_preview_view.js"></script>
<script type="text/javascript" src="js/views/file_input_view.js"></script> <script type="text/javascript" src="js/views/file_input_view.js"></script>
<script type="text/javascript" src="js/views/list_view.js"></script> <script type="text/javascript" src="js/views/list_view.js"></script>
<script type="text/javascript" src="js/views/new_group_update_view.js"></script> <script type="text/javascript" src="js/views/new_group_update_view.js"></script>

@ -0,0 +1,31 @@
/* vim: ts=4:sw=4:expandtab
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var Whisper = Whisper || {};
(function () {
'use strict';
Whisper.AttachmentPreviewView = Backbone.View.extend({
className: 'imageAttachment',
initialize: function() {
this.template = $('#attachment-preview').html();
Mustache.parse(this.template);
},
render: function() {
this.$el.html(Mustache.render(this.template, {source: this.src}));
return this;
}
});
})();

@ -23,6 +23,7 @@ var Whisper = Whisper || {};
initialize: function() { initialize: function() {
this.$input = this.$el.find('input[type=file]'); this.$input = this.$el.find('input[type=file]');
this.modal = new Whisper.ModalView({el: $('#file-modal')}); this.modal = new Whisper.ModalView({el: $('#file-modal')});
this.thumb = new Whisper.AttachmentPreviewView();
}, },
events: { events: {
@ -31,9 +32,8 @@ var Whisper = Whisper || {};
}, },
addThumb: function(e) { addThumb: function(e) {
var attachmentPreview = $('#attachment-preview').html(); this.thumb.src = e.target.result;
Mustache.parse(attachmentPreview); this.$el.append(this.thumb.render().el);
this.$el.append($(Mustache.render(attachmentPreview, {source: e.target.result})));
}, },
previewImages: function() { previewImages: function() {
@ -76,7 +76,7 @@ var Whisper = Whisper || {};
}, },
clearForm: function() { clearForm: function() {
this.$el.find('div.imageAttachment').remove(); this.thumb.remove();
}, },
deleteFiles: function() { deleteFiles: function() {

Loading…
Cancel
Save