Browse Source

Merge pull request #80 from fancycode/download_presentations

Allow downloading of presentations.
pull/82/head
Simon Eisenmann 11 years ago
parent
commit
50dd173610
  1. 13
      src/styles/components/_presentation.scss
  2. 9
      static/js/directives/pdfcanvas.js
  3. 30
      static/js/directives/presentation.js
  4. 3
      static/partials/presentation.html

13
src/styles/components/_presentation.scss

@ -210,14 +210,21 @@
display: block; display: block;
} }
.presentation .thumbnail .delete { .presentation .thumbnail .presentation-action {
position: absolute; position: absolute;
top: 1px; top: 1px;
right: 1px;
display: none; display: none;
} }
.presentation .thumbnail:hover .delete { .presentation .thumbnail .download {
left: 1px;
}
.presentation .thumbnail .delete {
right: 1px;
}
.presentation .thumbnail:hover .presentation-action {
display: block; display: block;
} }

9
static/js/directives/pdfcanvas.js

@ -36,6 +36,7 @@ define(['require', 'underscore', 'jquery'], function(require, _, $) {
this.currentPageNumber = null; this.currentPageNumber = null;
this.pendingPageNumber = null; this.pendingPageNumber = null;
this.renderTask = null; this.renderTask = null;
this.url = null;
}; };
PDFCanvas.prototype._close = function() { PDFCanvas.prototype._close = function() {
@ -49,6 +50,10 @@ define(['require', 'underscore', 'jquery'], function(require, _, $) {
this.doc.destroy(); this.doc.destroy();
this.doc = null; this.doc = null;
} }
if (this.url) {
URL.revokeObjectURL(this.url);
this.url = null;
}
this.pendingPageNumber = null; this.pendingPageNumber = null;
this.currentPageNumber = -1; this.currentPageNumber = -1;
this.maxPageNumber = -1; this.maxPageNumber = -1;
@ -74,8 +79,8 @@ define(['require', 'underscore', 'jquery'], function(require, _, $) {
var fp = source.file || source; var fp = source.file || source;
if (typeof URL !== "undefined" && URL.createObjectURL) { if (typeof URL !== "undefined" && URL.createObjectURL) {
var url = URL.createObjectURL(fp); this.url = URL.createObjectURL(fp);
this._openFile(url); this._openFile(this.url);
} else { } else {
var fileReader = new FileReader(); var fileReader = new FileReader();
fileReader.onload = _.bind(function(evt) { fileReader.onload = _.bind(function(evt) {

30
static/js/directives/presentation.js

@ -53,6 +53,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'],
this.file = null; this.file = null;
this.handler = null; this.handler = null;
this.session = null; this.session = null;
this.url = null;
}; };
BasePresentation.prototype.stop = function() { BasePresentation.prototype.stop = function() {
@ -75,7 +76,6 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'],
BasePresentation.call(this, scope, fileInfo, token); BasePresentation.call(this, scope, fileInfo, token);
this.owner = owner; this.owner = owner;
this.progress = 0; this.progress = 0;
this.url = null;
this.presentable = false; this.presentable = false;
this.downloading = true; this.downloading = true;
this.uploaded = false; this.uploaded = false;
@ -129,6 +129,15 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'],
} }
}; };
DownloadPresentation.prototype.browserOpen = function(target) {
target = target || "_blank";
if (this.downloading) {
console.log("Presentation download not finished yet, not opening", this);
return;
}
$window.open(this.url, target);
};
DownloadPresentation.prototype.close = function() { DownloadPresentation.prototype.close = function() {
this.openCallback = null; this.openCallback = null;
}; };
@ -176,6 +185,14 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'],
callback(this.file); callback(this.file);
}; };
UploadPresentation.prototype.browserOpen = function(target) {
target = target || "_blank";
if (!this.url) {
this.url = URL.createObjectURL(this.file.file);
}
$window.open(this.url, target);
};
UploadPresentation.prototype.close = function() { UploadPresentation.prototype.close = function() {
}; };
@ -199,6 +216,10 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'],
this.scope.$destroy(); this.scope.$destroy();
this.scope = null; this.scope = null;
} }
if (this.url) {
URL.revokeObjectURL(this.url);
this.url = null;
}
this.session = null; this.session = null;
BasePresentation.prototype.clear.call(this); BasePresentation.prototype.clear.call(this);
}; };
@ -651,6 +672,13 @@ define(['jquery', 'underscore', 'text!partials/presentation.html', 'bigscreen'],
presentation.clear(); presentation.clear();
}; };
$scope.downloadPresentation = function(presentation, $event) {
if ($event) {
$event.preventDefault();
}
presentation.browserOpen();
};
$scope.toggleFullscreen = function(elem) { $scope.toggleFullscreen = function(elem) {
if (BigScreen.enabled) { if (BigScreen.enabled) {

3
static/partials/presentation.html

@ -43,7 +43,8 @@
title="{{ presentation.info.name }}"> title="{{ presentation.info.name }}">
<div class="fa active fa-check" ng-show="presentation === currentPresentation"></div> <div class="fa active fa-check" ng-show="presentation === currentPresentation"></div>
<div class="fa notavailable fa-ban" ng-show="presentation !== currentPresentation && !presentation.presentable"></div> <div class="fa notavailable fa-ban" ng-show="presentation !== currentPresentation && !presentation.presentable"></div>
<a class="btn btn-danger delete" ng-show="presentation.uploaded" ng-click="deletePresentation(presentation, $event)"><i class="fa fa-trash-o fa-lg"></i></a> <a class="btn btn-primary presentation-action download" ng-show="presentation.uploaded || !presentation.downloading" ng-click="downloadPresentation(presentation, $event)"><i class="fa fa-download fa-lg"></i></a>
<a class="btn btn-danger presentation-action delete" ng-show="presentation.uploaded" ng-click="deletePresentation(presentation, $event)"><i class="fa fa-trash-o fa-lg"></i></a>
<div class="fa filetype fa-file-pdf-o"></div> <div class="fa filetype fa-file-pdf-o"></div>
<div class="caption"> <div class="caption">
<span class="name">{{ presentation.info.name }}</span><br> <span class="name">{{ presentation.info.name }}</span><br>

Loading…
Cancel
Save