#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. * 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 {ContentActionModel} from './../models/content-action.model';
import {ContentActionList} from './content-action-list'; import {ContentActionList} from './content-action-list';
import {DocumentActionsService} from '../services/document-actions.service'; import {DocumentActionsService} from '../services/document-actions.service';
@@ -26,7 +26,7 @@ import {ContentActionHandler} from '../models/content-action.model';
selector: 'content-action', selector: 'content-action',
template: '' template: ''
}) })
export class ContentAction implements OnInit { export class ContentAction implements OnInit, OnChanges {
@Input() @Input()
title: string = 'Action'; title: string = 'Action';
@@ -46,30 +46,39 @@ export class ContentAction implements OnInit {
@Output() @Output()
execute = new EventEmitter(); execute = new EventEmitter();
model: ContentActionModel;
constructor( constructor(
private list: ContentActionList, private list: ContentActionList,
private documentActions: DocumentActionsService, private documentActions: DocumentActionsService,
private folderActions: FolderActionsService) { private folderActions: FolderActionsService) {
this.model = new ContentActionModel();
} }
ngOnInit() { ngOnInit() {
let model = new ContentActionModel(); this.model = new ContentActionModel({
model.type = this.type; type: this.type,
model.title = this.title; title: this.title,
model.icon = this.icon; icon: this.icon,
model.target = this.target; target: this.target
});
if (this.handler) { if (this.handler) {
model.handler = this.getSystemHandler(this.target, this.handler); this.model.handler = this.getSystemHandler(this.target, this.handler);
} else if (this.execute) { } else if (this.execute) {
model.handler = (document: any): void => { this.model.handler = (document: any): void => {
this.execute.emit({ this.execute.emit({
value: document 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 { private getSystemHandler(target: string, name: string): ContentActionHandler {

View File

@@ -38,18 +38,4 @@ export class ContentColumnList {
this.documentList.columns.push(column); 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. * 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 { ContentColumnList } from './content-column-list';
import { ContentColumnModel } from './../models/content-column.model'; import { ContentColumnModel } from './../models/content-column.model';
@@ -23,7 +23,7 @@ import { ContentColumnModel } from './../models/content-column.model';
selector: 'content-column', selector: 'content-column',
template: '' template: ''
}) })
export class ContentColumn implements OnInit { export class ContentColumn implements OnInit, OnChanges {
@Input() @Input()
title: string = ''; title: string = '';
@@ -40,31 +40,32 @@ export class ContentColumn implements OnInit {
@Input('class') @Input('class')
cssClass: string; cssClass: string;
model: ContentColumnModel;
constructor(private list: ContentColumnList) { constructor(private list: ContentColumnList) {
this.model = new ContentColumnModel();
} }
ngOnInit() { ngOnInit() {
let model = new ContentColumnModel(); this.model = new ContentColumnModel({
model.title = this.title; title: this.title,
model.srTitle = this.srTitle; srTitle: this.srTitle,
model.source = this.source; source: this.source,
model.cssClass = this.cssClass; cssClass: this.cssClass
});
if (!model.srTitle && model.source === '$thumbnail') { if (!this.model.srTitle && this.model.source === '$thumbnail') {
model.srTitle = 'Thumbnail'; this.model.srTitle = 'Thumbnail';
} }
if (this.list) { if (this.list) {
this.list.registerColumn(model); this.list.registerColumn(this.model);
} }
} }
ngOnChanges(change) { ngOnChanges(change) {
let model = new ContentColumnModel(); // update localizable properties
model.title = this.title; this.model.title = this.title;
model.source = this.source; this.model.srTitle = this.srTitle;
if (this.list) {
this.list.updateColumn(model);
}
} }
} }

View File

@@ -21,6 +21,16 @@ export class ContentActionModel {
handler: ContentActionHandler; handler: ContentActionHandler;
type: string; type: string;
target: 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 { export interface ContentActionHandler {

View File

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