Files
docx-js/ts/properties/components.ts
2016-05-01 23:48:45 +01:00

102 lines
2.6 KiB
TypeScript

import {XmlUnitComponent} from "../docx/xml-components";
import {XmlComponent} from "../docx/xml-components";
import {DocumentAttributes} from "../docx/document/document-attributes";
abstract class Component extends XmlUnitComponent {
protected createNullBlockOrValue(value: string): any {
return value;
//return null;
}
}
export class Title extends Component {
constructor(value: string) {
super("dc:title");
this.root = this.createNullBlockOrValue(value);
}
}
export class Subject extends Component {
constructor(value: string) {
super("dc:subject");
this.root = this.createNullBlockOrValue(value);
}
}
export class Creator extends Component {
constructor(value: string) {
super("dc:creator");
this.root = this.createNullBlockOrValue(value);
}
}
export class Keywords extends Component {
constructor(value: string) {
super("cp:keywords");
this.root = this.createNullBlockOrValue(value);
}
}
export class Description extends Component {
constructor(value: string) {
super("dc:description");
this.root = this.createNullBlockOrValue(value);
}
}
export class LastModifiedBy extends Component {
constructor(value: string) {
super("cp:lastModifiedBy");
this.root = this.createNullBlockOrValue(value);
}
}
export class Revision extends Component {
constructor(value: string) {
super("cp:revision");
var revision = this.createNullBlockOrValue(value);
this.root = this.createNullBlockOrValue(value);
}
}
abstract class DateComponent extends XmlComponent {
protected getCurrentDate(): any {
var date = new Date(),
year = date.getFullYear(),
month = ('0' + (date.getMonth() + 1)).slice(-2),
day = ('0' + date.getDate()).slice(-2),
hours = ('0' + date.getHours()).slice(-2),
minutes = ('0' + date.getMinutes()).slice(-2),
seconds = ('0' + date.getSeconds()).slice(-2);
return year + '-' + month + '-' + day + 'T' + hours + ':' + minutes + ':' + seconds + 'Z';
}
}
export class Created extends DateComponent {
constructor() {
super("dcterms:created");
this.root.push(new DocumentAttributes({
type: "dcterms:W3CDTF"
}));
this.root.push(this.getCurrentDate());
}
}
export class Modified extends DateComponent implements XmlComponent {
constructor() {
super("dcterms:modified");
this.root.push(new DocumentAttributes({
type: "dcterms:W3CDTF"
}));
this.root.push(this.getCurrentDate());
}
}