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

102 lines
2.6 KiB
TypeScript
Raw Normal View History

2016-05-01 23:48:45 +01:00
import {XmlUnitComponent} from "../docx/xml-components";
2016-04-03 20:00:30 +01:00
import {XmlComponent} from "../docx/xml-components";
2016-05-01 22:49:40 +01:00
import {DocumentAttributes} from "../docx/document/document-attributes";
2016-04-03 20:00:30 +01:00
2016-05-01 23:48:45 +01:00
abstract class Component extends XmlUnitComponent {
2016-05-01 22:24:20 +01:00
protected createNullBlockOrValue(value: string): any {
2016-05-01 23:48:45 +01:00
return value;
2016-05-01 22:24:20 +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");
2016-05-01 23:48:45 +01:00
this.root = 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");
2016-05-01 23:48:45 +01:00
this.root = 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");
2016-05-01 23:48:45 +01:00
this.root = 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");
2016-05-01 23:48:45 +01:00
this.root = 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");
2016-05-01 23:48:45 +01:00
this.root = 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");
2016-05-01 23:48:45 +01:00
this.root = 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-05-01 23:48:45 +01:00
this.root = 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
}
}