#9 i18n fixes for columns and actions

This commit is contained in:
Denys Vuika
2016-05-23 16:11:20 +01:00
parent 9331e07c6e
commit 3f28925d35
5 changed files with 55 additions and 40 deletions

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import {Component, OnInit, Input, Output, EventEmitter} from 'angular2/core';
import {Component, OnInit, OnChanges, Input, Output, EventEmitter} from 'angular2/core';
import {ContentActionModel} from './../models/content-action.model';
import {ContentActionList} from './content-action-list';
import {DocumentActionsService} from '../services/document-actions.service';
@@ -26,7 +26,7 @@ import {ContentActionHandler} from '../models/content-action.model';
selector: 'content-action',
template: ''
})
export class ContentAction implements OnInit {
export class ContentAction implements OnInit, OnChanges {
@Input()
title: string = 'Action';
@@ -46,30 +46,39 @@ export class ContentAction implements OnInit {
@Output()
execute = new EventEmitter();
model: ContentActionModel;
constructor(
private list: ContentActionList,
private documentActions: DocumentActionsService,
private folderActions: FolderActionsService) {
this.model = new ContentActionModel();
}
ngOnInit() {
let model = new ContentActionModel();
model.type = this.type;
model.title = this.title;
model.icon = this.icon;
model.target = this.target;
this.model = new ContentActionModel({
type: this.type,
title: this.title,
icon: this.icon,
target: this.target
});
if (this.handler) {
model.handler = this.getSystemHandler(this.target, this.handler);
this.model.handler = this.getSystemHandler(this.target, this.handler);
} else if (this.execute) {
model.handler = (document: any): void => {
this.model.handler = (document: any): void => {
this.execute.emit({
value: document
});
};
}
this.list.registerAction(model);
this.list.registerAction(this.model);
}
ngOnChanges() {
// update localizable properties
this.model.title = this.title;
}
private getSystemHandler(target: string, name: string): ContentActionHandler {

View File

@@ -38,18 +38,4 @@ export class ContentColumnList {
this.documentList.columns.push(column);
}
}
/**
* Update the title with the new value
* @param column Column definition model.
*/
updateColumn(column: ContentColumnModel): void {
if (this.documentList && column) {
this.documentList.columns.forEach((tmpColumn) => {
if (tmpColumn.source === column.source) {
tmpColumn.title = column.title;
}
});
}
}
}

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, OnInit, Input } from 'angular2/core';
import { Component, OnInit, Input, OnChanges } from 'angular2/core';
import { ContentColumnList } from './content-column-list';
import { ContentColumnModel } from './../models/content-column.model';
@@ -23,7 +23,7 @@ import { ContentColumnModel } from './../models/content-column.model';
selector: 'content-column',
template: ''
})
export class ContentColumn implements OnInit {
export class ContentColumn implements OnInit, OnChanges {
@Input()
title: string = '';
@@ -40,31 +40,32 @@ export class ContentColumn implements OnInit {
@Input('class')
cssClass: string;
model: ContentColumnModel;
constructor(private list: ContentColumnList) {
this.model = new ContentColumnModel();
}
ngOnInit() {
let model = new ContentColumnModel();
model.title = this.title;
model.srTitle = this.srTitle;
model.source = this.source;
model.cssClass = this.cssClass;
this.model = new ContentColumnModel({
title: this.title,
srTitle: this.srTitle,
source: this.source,
cssClass: this.cssClass
});
if (!model.srTitle && model.source === '$thumbnail') {
model.srTitle = 'Thumbnail';
if (!this.model.srTitle && this.model.source === '$thumbnail') {
this.model.srTitle = 'Thumbnail';
}
if (this.list) {
this.list.registerColumn(model);
this.list.registerColumn(this.model);
}
}
ngOnChanges(change) {
let model = new ContentColumnModel();
model.title = this.title;
model.source = this.source;
if (this.list) {
this.list.updateColumn(model);
}
// update localizable properties
this.model.title = this.title;
this.model.srTitle = this.srTitle;
}
}

View File

@@ -21,6 +21,16 @@ export class ContentActionModel {
handler: ContentActionHandler;
type: string;
target: string;
constructor(obj?: any) {
if (obj) {
this.icon = obj.icon;
this.title = obj.title;
this.handler = obj.handler;
this.type = obj.type;
this.target = obj.target;
}
}
}
export interface ContentActionHandler {

View File

@@ -20,4 +20,13 @@ export class ContentColumnModel {
srTitle: string;
source: string;
cssClass: string;
constructor(obj?: any) {
if (obj) {
this.title = obj.title;
this.srTitle = obj.srTitle;
this.source = obj.source;
this.cssClass = obj.cssClass;
}
}
}