'Download' action for document list menu

- default ‘download’ action for document list menu
- readme updates

refs #20
This commit is contained in:
Denys Vuika
2016-05-03 13:58:37 +01:00
parent 8ec414036f
commit 5cf9b296d6
11 changed files with 112 additions and 25 deletions

View File

@@ -1,8 +1,12 @@
import { ContentActionHandler } from '../models/content-action.model';
import { AlfrescoService } from './alfresco.service';
export declare class DocumentActionsService {
private _alfrescoService;
private handlers;
constructor();
constructor(_alfrescoService: AlfrescoService);
getHandler(key: string): ContentActionHandler;
private handleStandardAction1(document);
private handleStandardAction2(document);
private setupActionHandlers();
private handleStandardAction1(obj);
private handleStandardAction2(obj);
private download(obj);
}

View File

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
System.register(['angular2/core'], function(exports_1, context_1) {
System.register(['angular2/core', './alfresco.service'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
@@ -26,33 +26,55 @@ System.register(['angular2/core'], function(exports_1, context_1) {
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1;
var core_1, alfresco_service_1;
var DocumentActionsService;
return {
setters:[
function (core_1_1) {
core_1 = core_1_1;
},
function (alfresco_service_1_1) {
alfresco_service_1 = alfresco_service_1_1;
}],
execute: function() {
DocumentActionsService = (function () {
function DocumentActionsService() {
function DocumentActionsService(_alfrescoService) {
this._alfrescoService = _alfrescoService;
this.handlers = {};
// todo: just for dev/demo purposes, to be replaced with real actions
this.handlers['system1'] = this.handleStandardAction1;
this.handlers['system2'] = this.handleStandardAction2;
this.setupActionHandlers();
}
DocumentActionsService.prototype.getHandler = function (key) {
return this.handlers[key];
if (key) {
var lkey = key.toLowerCase();
return this.handlers[lkey];
}
return null;
};
DocumentActionsService.prototype.handleStandardAction1 = function (document) {
DocumentActionsService.prototype.setupActionHandlers = function () {
this.handlers['download'] = this.download.bind(this);
// todo: just for dev/demo purposes, to be replaced with real actions
this.handlers['system1'] = this.handleStandardAction1.bind(this);
this.handlers['system2'] = this.handleStandardAction2.bind(this);
};
DocumentActionsService.prototype.handleStandardAction1 = function (obj) {
window.alert('standard document action 1');
};
DocumentActionsService.prototype.handleStandardAction2 = function (document) {
DocumentActionsService.prototype.handleStandardAction2 = function (obj) {
window.alert('standard document action 2');
};
DocumentActionsService.prototype.download = function (obj) {
if (obj && !obj.isFolder) {
var link = document.createElement('a');
document.body.appendChild(link);
link.setAttribute('download', 'download');
link.href = this._alfrescoService.getContentUrl(obj);
link.click();
document.body.removeChild(link);
}
};
DocumentActionsService = __decorate([
core_1.Injectable(),
__metadata('design:paramtypes', [])
__metadata('design:paramtypes', [alfresco_service_1.AlfrescoService])
], DocumentActionsService);
return DocumentActionsService;
}());

View File

@@ -1 +1 @@
{"version":3,"file":"document-actions.service.js","sourceRoot":"","sources":["document-actions.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;YAMH;gBAGI;oBAFQ,aAAQ,GAA4C,EAAE,CAAC;oBAG3D,qEAAqE;oBACrE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC;oBACtD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC;gBAC1D,CAAC;gBAED,2CAAU,GAAV,UAAW,GAAW;oBAClB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC;gBAEO,sDAAqB,GAA7B,UAA8B,QAAa;oBACvC,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAC/C,CAAC;gBAEO,sDAAqB,GAA7B,UAA8B,QAAa;oBACvC,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAC/C,CAAC;gBApBL;oBAAC,iBAAU,EAAE;;0CAAA;gBAqBb,6BAA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G,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACvB,IAAI,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;wBACvC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;wBAChC,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;wBAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;wBACrD,IAAI,CAAC,KAAK,EAAE,CAAC;wBACb,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;oBACpC,CAAC;gBACL,CAAC;gBAzCL;oBAAC,iBAAU,EAAE;;0CAAA;gBA0Cb,6BAAC;YAAD,CAAC,AAzCD,IAyCC;YAzCD,2DAyCC,CAAA"}

View File

@@ -17,26 +17,48 @@
import {Injectable} from 'angular2/core';
import {ContentActionHandler} from '../models/content-action.model';
import {AlfrescoService} from './alfresco.service';
@Injectable()
export class DocumentActionsService {
private handlers: { [id: string]: ContentActionHandler; } = {};
constructor() {
// todo: just for dev/demo purposes, to be replaced with real actions
this.handlers['system1'] = this.handleStandardAction1;
this.handlers['system2'] = this.handleStandardAction2;
constructor(private _alfrescoService: AlfrescoService) {
this.setupActionHandlers();
}
getHandler(key: string): ContentActionHandler {
return this.handlers[key];
if (key) {
let lkey = key.toLowerCase();
return this.handlers[lkey];
}
return null;
}
private handleStandardAction1(document: any) {
private setupActionHandlers() {
this.handlers['download'] = this.download.bind(this);
// todo: just for dev/demo purposes, to be replaced with real actions
this.handlers['system1'] = this.handleStandardAction1.bind(this);
this.handlers['system2'] = this.handleStandardAction2.bind(this);
}
private handleStandardAction1(obj: any) {
window.alert('standard document action 1');
}
private handleStandardAction2(document: any) {
private handleStandardAction2(obj: any) {
window.alert('standard document action 2');
}
private download(obj: any) {
if (obj && !obj.isFolder) {
let link = document.createElement('a');
document.body.appendChild(link);
link.setAttribute('download', 'download');
link.href = this._alfrescoService.getContentUrl(obj);
link.click();
document.body.removeChild(link);
}
}
}