// Abstract document class
// Each specific document class extends this one

'use strict';

var memoize          = require('memoizee/plain')
  , ensureDb         = require('dbjs/valid-dbjs')
  , defineDate       = require('dbjs-ext/date-time/date')
  , defineStringLine = require('dbjs-ext/string/string-line')
  , _                = require('mano').i18n.bind('Model: Documents')
  , defineFile       = require('./file')
  , defineStatusLog  = require('./lib/status-log');

module.exports = memoize(function (db) {
	var StringLine = defineStringLine(ensureDb(db))
	  , File       = defineFile(db)
	  , DateType   = defineDate(db)
	  , StatusLog  = defineStatusLog(db);

	db.Object.extend('Document', {
		files: { type: db.Object, nested: true },
		issuedBy: { type: db.Object, value: function () { return this.master.user; } },
		label: { type: StringLine, value: function () { return this.constructor.label; } },
		legend: { type: StringLine, value: function () { return this.constructor.legend; } },
		uniqueKey: { type: StringLine, value: function () { return this.key; } },
		issueDate: { type: DateType, required: true, label: _("Date of issuance") },
		orderedFiles: { type: File, multiple: true, value: function (_observe) {
			var files = [];
			_observe(this.files, true).forEach(function (file) {
				if (!_observe(file._path)) return;
				files.push(file);
			});
			return files.sort(function (a, b) {
				return a.getDescriptor('name')._lastOwnModified_ -
					b.getDescriptor('name')._lastOwnModified_;
			});
		} },
		statusLog: { type: StatusLog, multiple: true }
	}, {
		label: { type: StringLine },
		legend: { type: StringLine },
		abbr: { type: StringLine }
	});

	db.Document.prototype.files._descriptorPrototype_.type   = File;
	db.Document.prototype.files._descriptorPrototype_.nested = true;

	return db.Document;
}, { normalizer: require('memoizee/normalizers/get-1')() });

@@ -699,134 +699,8 @@
 , %7B%0A
-%09%09files: %7B type: db.Object, nested: true %7D,%0A%09%09issuedBy: %7B type: db.Object, value: function () %7B return this.master.user; %7D %7D,%0A
 %09%09la
@@ -945,16 +945,98 @@
 y; %7D %7D,%0A
+%09%09issuedBy: %7B type: db.Object, value: function () %7B return this.master.user; %7D %7D,%0A
 %09%09issueD
@@ -1106,16 +1106,60 @@
 ce%22) %7D,%0A
+%09%09files: %7B type: db.Object, nested: true %7D,%0A
 %09%09ordere

Reorder properties