Files
docx-js/ts/properties/components.ts

105 lines
2.7 KiB
TypeScript
Raw Normal View History

2016-04-03 20:00:30 +01:00
import {XmlComponent} from "../docx/xml-components";
import {DocumentAttributes} from "../docx/xml-components/document-attributes";
2016-04-09 20:16:35 +01:00
abstract class Component extends XmlComponent {
protected createNullBlockOrValue(value: string): XmlComponent {
/*if (value === undefined) {
2016-04-03 20:00:30 +01:00
return [{}];
} else {
return value;
2016-04-09 20:16:35 +01:00
}*/
return null;
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class Title extends Component {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("dc:title");
this.root.push(this.createNullBlockOrValue(value));
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class Subject extends Component {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("dc:subject");
this.root.push(this.createNullBlockOrValue(value));
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class Creator extends Component {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("dc:creator");
this.root.push(this.createNullBlockOrValue(value));
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class Keywords extends Component {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("cp:keywords");
this.root.push(this.createNullBlockOrValue(value));
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class Description extends Component {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("dc:description");
this.root.push(this.createNullBlockOrValue(value));
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class LastModifiedBy extends Component {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("cp:lastModifiedBy");
this.root.push(this.createNullBlockOrValue(value));
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class Revision extends Component {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("cp:revision");
2016-04-03 20:00:30 +01:00
var revision = this.createNullBlockOrValue(value);
2016-04-09 20:16:35 +01:00
this.root.push(this.createNullBlockOrValue(value));
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
abstract class DateComponent extends XmlComponent {
2016-04-03 20:00:30 +01:00
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';
}
}
2016-04-09 20:16:35 +01:00
export class Created extends DateComponent {
2016-04-03 20:00:30 +01:00
constructor() {
2016-04-09 20:16:35 +01:00
super("dcterms:created");
this.root.push(new DocumentAttributes({
2016-04-03 20:00:30 +01:00
type: "dcterms:W3CDTF"
}));
2016-04-09 20:16:35 +01:00
this.root.push(this.getCurrentDate());
2016-04-03 20:00:30 +01:00
}
}
export class Modified extends DateComponent implements XmlComponent {
constructor() {
2016-04-09 20:16:35 +01:00
super("dcterms:modified");
this.root.push(new DocumentAttributes({
2016-04-03 20:00:30 +01:00
type: "dcterms:W3CDTF"
}));
2016-04-09 20:16:35 +01:00
this.root.push(this.getCurrentDate());
2016-04-03 20:00:30 +01:00
}
}