diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/content-action.ts b/ng2-components/ng2-alfresco-documentlist/src/components/content-action.ts index 4b2b8c02ef..95dcf049f2 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/content-action.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/content-action.ts @@ -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 { diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts index f7e511dd86..42c745caf3 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts @@ -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; - } - }); - } - } } diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts b/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts index 84824b33d0..061b83feb1 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts @@ -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; } } diff --git a/ng2-components/ng2-alfresco-documentlist/src/models/content-action.model.ts b/ng2-components/ng2-alfresco-documentlist/src/models/content-action.model.ts index 23797e6202..bfd303d523 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/models/content-action.model.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/models/content-action.model.ts @@ -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 { diff --git a/ng2-components/ng2-alfresco-documentlist/src/models/content-column.model.ts b/ng2-components/ng2-alfresco-documentlist/src/models/content-column.model.ts index 8ea94acc53..24ff9fcf0b 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/models/content-column.model.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/models/content-column.model.ts @@ -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; + } + } }