Detection of system config pages, some work on page.js using updated function configuration
This commit is contained in:
parent
674768845b
commit
6c3afe6f69
@ -94,6 +94,7 @@ const FRAME_TYPE_LOGIN = 12; //'l';
|
|||||||
const FRAME_TYPE_MAIL_TEMPLATE = 'm';
|
const FRAME_TYPE_MAIL_TEMPLATE = 'm';
|
||||||
/* Frame is a message */
|
/* Frame is a message */
|
||||||
const FRAME_TYPE_MESSAGE = 2; // 'M';
|
const FRAME_TYPE_MESSAGE = 2; // 'M';
|
||||||
|
const FRAME_TYPE_SYSTEM = 14;
|
||||||
|
|
||||||
/* Disable *# going backwards for the following frames */
|
/* Disable *# going backwards for the following frames */
|
||||||
const FRAMES_NO_HISTORY = ['980a','98b','981a','982a','983a','998a'];
|
const FRAMES_NO_HISTORY = ['980a','98b','981a','982a','983a','998a'];
|
||||||
|
@ -60,8 +60,8 @@ function MsgAreas() {
|
|||||||
if (SESSION_EXT === undefined)
|
if (SESSION_EXT === undefined)
|
||||||
var SESSION_EXT = 'tex';
|
var SESSION_EXT = 'tex';
|
||||||
|
|
||||||
if (conf !== undefined)
|
if ((conf !== undefined) && (conf.content.content !== undefined))
|
||||||
cfg[zone_id] = conf.content[SESSION_EXT].content.map(function(item) { return item.toLowerCase(); });
|
cfg[zone_id] = conf.content.content.map(function(item) { return item.toLowerCase(); });
|
||||||
else
|
else
|
||||||
cfg[zone_id] = [];
|
cfg[zone_id] = [];
|
||||||
}
|
}
|
||||||
|
106
load/page.js
106
load/page.js
@ -209,6 +209,7 @@ function Page(debug) {
|
|||||||
log(LOG_DEBUG,'|* Accessible: '+this.isAccessible);
|
log(LOG_DEBUG,'|* Accessible: '+this.isAccessible);
|
||||||
log(LOG_DEBUG,'|* Public: '+this.isPublic);
|
log(LOG_DEBUG,'|* Public: '+this.isPublic);
|
||||||
log(LOG_DEBUG,'|* Member: '+this.isMember);
|
log(LOG_DEBUG,'|* Member: '+this.isMember);
|
||||||
|
log(LOG_DEBUG,'|* Type: '+this.type);
|
||||||
|
|
||||||
// user.number 0 is unidentified user.
|
// user.number 0 is unidentified user.
|
||||||
if (user.number) {
|
if (user.number) {
|
||||||
@ -254,7 +255,7 @@ function Page(debug) {
|
|||||||
int = 0;
|
int = 0;
|
||||||
|
|
||||||
if (typeof int !== 'number')
|
if (typeof int !== 'number')
|
||||||
throw new Error('Cost must be a number');
|
throw new Error('Cost must be a number:'+JSON.stringify(int));
|
||||||
|
|
||||||
this.__properties__.cost = int;
|
this.__properties__.cost = int;
|
||||||
|
|
||||||
@ -344,6 +345,12 @@ function Page(debug) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(this,'isSystemConfig',{
|
||||||
|
get: function() {
|
||||||
|
return (this.type === FRAME_TYPE_SYSTEM);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Is this a system page
|
// Is this a system page
|
||||||
Object.defineProperty(this,'isSystemPage',{
|
Object.defineProperty(this,'isSystemPage',{
|
||||||
get: function() {
|
get: function() {
|
||||||
@ -352,17 +359,23 @@ function Page(debug) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Key Array
|
// Key Array
|
||||||
Page.prototype.__defineGetter__('key',function() {
|
Object.defineProperty(this,'key',{
|
||||||
return this.__properties__.key;
|
get: function() {
|
||||||
});
|
return this.__properties__.key;
|
||||||
Page.prototype.__defineSetter__('key',function(array) {
|
},
|
||||||
if (typeof array !== 'object')
|
|
||||||
throw new Error('key must be an array :'+typeof array);
|
|
||||||
|
|
||||||
if (array.length !== 10)
|
set: function(array) {
|
||||||
throw new Error('key must contain 10 items :'+array);
|
if (array === undefined)
|
||||||
|
return;
|
||||||
|
|
||||||
return this.__properties__.key = array;
|
if (typeof array !== 'object')
|
||||||
|
throw new Error('key must be an array :'+typeof array);
|
||||||
|
|
||||||
|
if (array.length !== 10)
|
||||||
|
throw new Error('key must contain 10 items :'+array);
|
||||||
|
|
||||||
|
return this.__properties__.key = array;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Page.prototype.__defineGetter__('name',function() {
|
Page.prototype.__defineGetter__('name',function() {
|
||||||
@ -445,7 +458,10 @@ function Page(debug) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
set: function(value) {
|
set: function(value) {
|
||||||
this.__properties__.raw[SESSION_EXT] = value;
|
if (this.isSystemConfig)
|
||||||
|
this.__properties__.raw = value
|
||||||
|
else
|
||||||
|
this.__properties__.raw[SESSION_EXT] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -481,7 +497,7 @@ function Page(debug) {
|
|||||||
*
|
*
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
this.build = function(force) {
|
Page.prototype.build = function(force) {
|
||||||
log(LOG_DEBUG,'* Building frame...');
|
log(LOG_DEBUG,'* Building frame...');
|
||||||
|
|
||||||
if (this.__compiled__.build && ! force)
|
if (this.__compiled__.build && ! force)
|
||||||
@ -527,7 +543,7 @@ function Page(debug) {
|
|||||||
/**
|
/**
|
||||||
* Build in any input_fields with values
|
* Build in any input_fields with values
|
||||||
*/
|
*/
|
||||||
this.build_input_fields = function() {
|
Page.prototype.build_input_fields = function() {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
var f = this.input_fields.filter(function(item) { return item.value.length; });
|
var f = this.input_fields.filter(function(item) { return item.value.length; });
|
||||||
@ -544,7 +560,7 @@ function Page(debug) {
|
|||||||
/**
|
/**
|
||||||
* Build in our dynamic_fields that can be populated automatically
|
* Build in our dynamic_fields that can be populated automatically
|
||||||
*/
|
*/
|
||||||
this.build_system_fields = function(context) {
|
Page.prototype.build_system_fields = function(context) {
|
||||||
log(LOG_DEBUG,'Building system fields with context:'+context);
|
log(LOG_DEBUG,'Building system fields with context:'+context);
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
@ -569,7 +585,7 @@ function Page(debug) {
|
|||||||
* @param last - the last attribute sent to the screen
|
* @param last - the last attribute sent to the screen
|
||||||
* @param color - whether to render the color attributes
|
* @param color - whether to render the color attributes
|
||||||
*/
|
*/
|
||||||
this.display = function(last,color) {
|
Page.prototype.display = function(last,color) {
|
||||||
var debug = false;
|
var debug = false;
|
||||||
|
|
||||||
if (! this.__compiled__.build)
|
if (! this.__compiled__.build)
|
||||||
@ -696,6 +712,7 @@ function Page(debug) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/**
|
/**
|
||||||
* Dump a page in an axis grid to view that it renders correctly
|
* Dump a page in an axis grid to view that it renders correctly
|
||||||
*
|
*
|
||||||
@ -720,7 +737,7 @@ function Page(debug) {
|
|||||||
*
|
*
|
||||||
* + for ANSItex, attribute(s) dont advance the cursor, clear screen sets the default to BG_BLACK|LIGHTGRAY
|
* + for ANSItex, attribute(s) dont advance the cursor, clear screen sets the default to BG_BLACK|LIGHTGRAY
|
||||||
* + for ViewData, an attribute does advance the cursor, and each attribute advances the cursor, also each new line starts with a default BG_BLACK|WHITE
|
* + for ViewData, an attribute does advance the cursor, and each attribute advances the cursor, also each new line starts with a default BG_BLACK|WHITE
|
||||||
*/
|
*
|
||||||
this.dump = function(last,color,debug) {
|
this.dump = function(last,color,debug) {
|
||||||
if (! this.__compiled__.build)
|
if (! this.__compiled__.build)
|
||||||
this.build();
|
this.build();
|
||||||
@ -866,6 +883,7 @@ function Page(debug) {
|
|||||||
if (color)
|
if (color)
|
||||||
write('\x1b[0m');
|
write('\x1b[0m');
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value for a dynamic field
|
* Set the value for a dynamic field
|
||||||
@ -873,7 +891,7 @@ function Page(debug) {
|
|||||||
* @param field
|
* @param field
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
this.dynamic_field = function(field,value) {
|
Page.prototype.dynamic_field = function(field,value) {
|
||||||
var fields = this.dynamic_fields.filter(function(item) { return item.name === field; });
|
var fields = this.dynamic_fields.filter(function(item) { return item.name === field; });
|
||||||
|
|
||||||
if (fields.length !== 1)
|
if (fields.length !== 1)
|
||||||
@ -883,11 +901,12 @@ function Page(debug) {
|
|||||||
this.dynamic_fields[this.dynamic_fields.indexOf(fields[0])].value = value;
|
this.dynamic_fields[this.dynamic_fields.indexOf(fields[0])].value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/**
|
/**
|
||||||
* Save the frame for later retrieval
|
* Save the frame for later retrieval
|
||||||
* @todo Inject back all input_fields and dynamic_fields
|
* @todo Inject back all input_fields and dynamic_fields
|
||||||
* @todo this is not complete?
|
* @todo this is not complete?
|
||||||
*/
|
*
|
||||||
this.export = function() {
|
this.export = function() {
|
||||||
var line;
|
var line;
|
||||||
|
|
||||||
@ -916,6 +935,7 @@ function Page(debug) {
|
|||||||
writeln();
|
writeln();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
Page.prototype.file_content = function(filename) {
|
Page.prototype.file_content = function(filename) {
|
||||||
log(LOG_DEBUG,'|-- Importing frame content: ['+filename+']');
|
log(LOG_DEBUG,'|-- Importing frame content: ['+filename+']');
|
||||||
@ -937,7 +957,7 @@ function Page(debug) {
|
|||||||
*
|
*
|
||||||
* @param page
|
* @param page
|
||||||
*/
|
*/
|
||||||
this.get = function(page) {
|
Page.prototype.get = function(page) {
|
||||||
if (!(page instanceof PageObject))
|
if (!(page instanceof PageObject))
|
||||||
throw new Error('page must be a PageObject');
|
throw new Error('page must be a PageObject');
|
||||||
|
|
||||||
@ -957,7 +977,7 @@ function Page(debug) {
|
|||||||
* @param field
|
* @param field
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
this.input_field = function(field,value) {
|
Page.prototype.input_field = function(field,value) {
|
||||||
var fields = this.input_fields.filter(function(item) { return item.name === field; });
|
var fields = this.input_fields.filter(function(item) { return item.name === field; });
|
||||||
|
|
||||||
if (fields.length !== 1)
|
if (fields.length !== 1)
|
||||||
@ -981,10 +1001,25 @@ function Page(debug) {
|
|||||||
log(LOG_ERROR,'|? File doesnt exist: ['+filename+']');
|
log(LOG_ERROR,'|? File doesnt exist: ['+filename+']');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var contents = JSON.parse(f.read());
|
|
||||||
|
try {
|
||||||
|
var x = f.read()
|
||||||
|
var contents = JSON.parse(x);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
log(LOG_ERROR,'|! ERROR parsing contents: ['+x+'] - error:'+e.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
contents.date = f.date;
|
contents.date = f.date;
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
|
// If this is a system config frame, then we can return
|
||||||
|
if ((contents.attrs&0x7) === FRAME_TYPE_SYSTEM) {
|
||||||
|
log(LOG_DEBUG,'System frame, not processing content: '+contents.attrs);
|
||||||
|
return this.preload(contents,SESSION_EXT);
|
||||||
|
}
|
||||||
|
|
||||||
// Load the page content
|
// Load the page content
|
||||||
if (contents.version === 2)
|
if (contents.version === 2)
|
||||||
contents.content = this.file_content(FRAMES_HOME+SESSION_EXT+'/'+this.name.toString()+'.'+CONTENT_EXT);
|
contents.content = this.file_content(FRAMES_HOME+SESSION_EXT+'/'+this.name.toString()+'.'+CONTENT_EXT);
|
||||||
@ -1064,7 +1099,7 @@ function Page(debug) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load a frame from a message base
|
// Load a frame from a message base
|
||||||
this.load = function(page) {
|
Page.prototype.load = function(page) {
|
||||||
var page = this.name.toString();
|
var page = this.name.toString();
|
||||||
var mb = new MsgAreas().getArea(FRAMES_MSG_BASE)
|
var mb = new MsgAreas().getArea(FRAMES_MSG_BASE)
|
||||||
var msg = mb.frames
|
var msg = mb.frames
|
||||||
@ -1099,7 +1134,7 @@ function Page(debug) {
|
|||||||
/**
|
/**
|
||||||
* After page load routines
|
* After page load routines
|
||||||
*/
|
*/
|
||||||
this.loadcomplete = function() {
|
Page.prototype.loadcomplete = function() {
|
||||||
var po = pageOwner(this.name.frame);
|
var po = pageOwner(this.name.frame);
|
||||||
|
|
||||||
switch (SESSION_EXT) {
|
switch (SESSION_EXT) {
|
||||||
@ -1133,7 +1168,7 @@ function Page(debug) {
|
|||||||
* @param height
|
* @param height
|
||||||
* @returns {boolean|null}
|
* @returns {boolean|null}
|
||||||
*/
|
*/
|
||||||
this.preload = function(contents,ext) {
|
Page.prototype.preload = function(contents,ext) {
|
||||||
switch (ext) {
|
switch (ext) {
|
||||||
// Messages
|
// Messages
|
||||||
case 'txt':
|
case 'txt':
|
||||||
@ -1193,6 +1228,7 @@ function Page(debug) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'cost':
|
case 'cost':
|
||||||
|
writeln('***:'+contents[index]);
|
||||||
this.cost = contents[index];
|
this.cost = contents[index];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1274,6 +1310,17 @@ function Page(debug) {
|
|||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
log(LOG_DEBUG,'|-- Type: '+SESSION_EXT);
|
log(LOG_DEBUG,'|-- Type: '+SESSION_EXT);
|
||||||
|
|
||||||
|
// Work out frame type
|
||||||
|
this.attrs = contents.attrs;
|
||||||
|
this.cost = contents.cost;
|
||||||
|
this.key = contents.key;
|
||||||
|
this.raw = contents.content;
|
||||||
|
this.date = contents.date;
|
||||||
|
|
||||||
|
if (this.isSystemConfig)
|
||||||
|
break;
|
||||||
|
|
||||||
if ((SESSION_EXT === 'vtx') && contents.dynamic_fields) {
|
if ((SESSION_EXT === 'vtx') && contents.dynamic_fields) {
|
||||||
log(LOG_DEBUG,'|--- Dynamic Fields: '+contents.dynamic_fields.length);
|
log(LOG_DEBUG,'|--- Dynamic Fields: '+contents.dynamic_fields.length);
|
||||||
this.dynamic_fields = contents.dynamic_fields;
|
this.dynamic_fields = contents.dynamic_fields;
|
||||||
@ -1294,13 +1341,6 @@ function Page(debug) {
|
|||||||
if ((SESSION_EXT === 'tex') && page.dynamic_fields)
|
if ((SESSION_EXT === 'tex') && page.dynamic_fields)
|
||||||
this.dynamic_fields = page.dynamic_fields;
|
this.dynamic_fields = page.dynamic_fields;
|
||||||
|
|
||||||
// Work out frame type
|
|
||||||
this.attrs = contents.attrs;
|
|
||||||
this.cost = contents.cost;
|
|
||||||
this.key = contents.key;
|
|
||||||
this.raw = contents.content;
|
|
||||||
this.date = contents.date;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1326,7 +1366,7 @@ function Page(debug) {
|
|||||||
/**
|
/**
|
||||||
* Save the frame to the message base
|
* Save the frame to the message base
|
||||||
*/
|
*/
|
||||||
this.save = function() {
|
Page.prototype.save = function() {
|
||||||
var msgbase = new MsgBase(FRAMES_MSG_BASE);
|
var msgbase = new MsgBase(FRAMES_MSG_BASE);
|
||||||
|
|
||||||
if (! msgbase.open()) {
|
if (! msgbase.open()) {
|
||||||
@ -1360,7 +1400,7 @@ function Page(debug) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scroll = function(x,y) {
|
Page.prototype.scroll = function(x,y) {
|
||||||
this.__compiled__.build = null;
|
this.__compiled__.build = null;
|
||||||
|
|
||||||
// @todo Check that we can scroll and if we are out of bounds.
|
// @todo Check that we can scroll and if we are out of bounds.
|
||||||
|
@ -21,15 +21,17 @@ var po = new PageObject(argv[0]);
|
|||||||
var SESSION_EXT = 'tex';
|
var SESSION_EXT = 'tex';
|
||||||
require('ansitex/load/session/ansitex.js','SESSION_ANSITEX');
|
require('ansitex/load/session/ansitex.js','SESSION_ANSITEX');
|
||||||
var p = new Page();
|
var p = new Page();
|
||||||
p.get(po);
|
if (! p.get(po))
|
||||||
|
throw new Error('Page doesnt exist:'+po.toString());
|
||||||
|
|
||||||
// Load Viewdata frame
|
if (! p.isSystemConfig) {
|
||||||
var SESSION_EXT = 'vtx';
|
// Load Viewdata frame
|
||||||
require('ansitex/load/session/viewdata.js','SESSION_VIEWDATA');
|
var SESSION_EXT = 'vtx';
|
||||||
|
require('ansitex/load/session/viewdata.js','SESSION_VIEWDATA');
|
||||||
|
|
||||||
var vtx = p.file_content(FRAMES_HOME+SESSION_EXT+'/'+po.toString()+'.'+CONTENT_EXT);
|
var vtx = p.file_content(FRAMES_HOME+SESSION_EXT+'/'+po.toString()+'.'+CONTENT_EXT);
|
||||||
|
if (vtx !== undefined)
|
||||||
if (vtx !== undefined)
|
p.raw = vtx;
|
||||||
p.raw = vtx;
|
}
|
||||||
|
|
||||||
p.save();
|
p.save();
|
||||||
|
Loading…
Reference in New Issue
Block a user