1 /****************************************************************************************************************************** 2 * (c) ITSV GmbH - http://www.itsv.at/ 3 * 4 * Software Operations 5 * Zentrale Daten und Services 6 * Wolfgang Scherer 7 * 8 * CCDB - Competence Center Controlling Database 9 * 10 * MODULE: document.js 11 * 12 * USES: mfile.js 13 * db.js 14 * 15 * SEE ALSO: http://zpvwiki.sozvers.at/wiki/ZPV_Controlling_Datenbank#App 16 * 17 * DESCRIPTION: This module contains document handling 18 */ 19 20 /* 21 * CLASS: Document 22 */ 23 function Document(initializer) { 24 this.objtype = 'document'; 25 this.attributes = new Array(); 26 this.status = 'initializing'; 27 this.statusListeners = new Array(); 28 if (initializer) { 29 if (initializer.objtype) { 30 switch (initializer.objtype) { 31 case 'document': // initializer is a document itself 32 case 'doctype': // initializer is a doctype structure 33 copyObject(this,initializer); 34 this.setStatus('ok'); 35 break; 36 case 'empty': 37 this.setStatus('ok'); 38 break; 39 default: 40 console.error("Illegal document initializer type \""+initializer.objtype+"\""); 41 } 42 } else { 43 console.error("Illegal initializer: has no objtype"); 44 } 45 } 46 this.addStatusListener = function(statusCallback) { 47 this.statusListeners.push(statusCallback); 48 return this.statusListeners.length-1; // return the slot number of this listener to enable removing it later 49 } 50 this.removeStatusListener = function(id) { 51 this.statusListeners[id] = null; // disable this status listener 52 } 53 this.notifyStatusListeners = function(statobj) { 54 for (var sli = 0; sli<statusListeners.length; sli++) { 55 if (statusListeners[sli]) { 56 statusListeners[sli](null,statobj); 57 } 58 } 59 } 60 this.setStatus(newstatus) { 61 var oldstatus = this.status; 62 this.status = newstatus; 63 this.notifyStatusListeners({document: this, oldstatus: oldstatus, newstatus: this.status}); 64 } 65 66 67 var localexportobject = { 68 Document : Document 69 } 70 71 var logger; 72 var mastername; 73 74 module.exports = function(theLogger,theMasterName) { 75 logger = theLogger; 76 mastername = theMasterName; 77 /* 78 console.log("CCDB: this is the instantiation followup of "+__filename+", the master is "+mastername+"/"+theMasterName); 79 var c = 0; 80 var oal = ""; 81 for (var oa in module.exports) { 82 oal += ((c<1)?"":",")+oa; 83 c++; 84 } 85 console.log("CCDB: module.exports has "+c+" attributes: "+oal); 86 */ 87 return module.exports; 88 } 89 90 for (var oa in localexportobjects) { 91 module.exports[oa] = localexportobjects[oa]; 92 } 93 94