Edit now creates new frames

This commit is contained in:
Deon George 2020-07-22 22:37:00 +10:00
parent 747e753466
commit 17ddda1cd5
4 changed files with 36 additions and 15 deletions

View File

@ -38,6 +38,7 @@ var MSG_SENDORNOT ='\1n\1h\1GKEY 1 TO SEND, 2 NOT TO SEND';
var MSG_LOGON ='\1n\1h\1GKEY 1 TO LOGON, 2 TO RETURN';
var MSG_SENT ='\1n\1h\1GMESSAGE SENT - KEY # TO CONTINUE';
var MSG_NOTSENT ='\1n\1h\1GMESSAGE NOT SENT - KEY # TO CONTINUE';
var ERR_NO_PARENT ='\1n\1h\1RPARENT FRAME DOESNT EXIST';
var ERR_NOT_IMPLEMENTED ='\1n\1h\1RNOT IMPLEMENTED YET?';
var ERR_ROUTE ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
var ERR_METHOD_NOT_EXIST ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
@ -89,9 +90,11 @@ function TexFrame() {
if (user.number || (this.type != FRAME_TYPE_LOGIN && NO_HISTORY_FRAMES.indexOf(this.page) == -1)) {
log(LOG_DEBUG,'- Owner: ['+this.pageowner+']');
cost = (this.isAccessible ? this.cost+FRAME_COSTUNIT : ' -')
header = '\1n'+this.pageownerlogo+' '.repeat(FRAME_HEADER-console.strlen(this.pageownerlogo))+'\1n '+
'\1W\1H'+this.page+' '.repeat(FRAME_PAGENUM-this.page.length)+' '+
'\1G\1H'+' '.repeat(FRAME_COST-this.cost.toString().length)+this.cost+FRAME_COSTUNIT+
(this.isAccessible ? '\1W' : '\1R')+'\1H'+this.page+' '.repeat(FRAME_PAGENUM-this.page.length)+' '+
'\1G\1H'+' '.repeat(FRAME_COST-cost.toString().length+1)+cost+'\1n'+
(console.screen_columns > 80 ? '\n\r' : '');
}
@ -402,7 +405,7 @@ function TexFrame() {
(this.isAccessible && this.pageowner == SYSTEM_OWNER && ! this.isPublic) ||
(this.isAccessible && this.isPublic) ||
(this.isAccessible && ! this.isPublic && this.isMember) ||
(user.isOwner)
(pageEditor(this.frame))
);
} else {

View File

@ -38,11 +38,10 @@ function edit(fo) {
scrollbar : null
};
owner = '\1h\1RA\1GN\1BS\1YI\1n\1'+'7\1ktex\1'+'0\1n';
log(LOG_DEBUG,' - Owner: '+JSON.stringify(fo.owner));
const frame = new Frame(1,1,console.screen_columns,console.screen_rows,BG_BLACK|LIGHTGRAY);
frame.gotoxy(1,1);
header = '\1n'+owner+' '.repeat(FRAME_HEADER-console.strlen(owner))+'\1n '+
header = '\1n'+fo.owner+' '.repeat(FRAME_HEADER-console.strlen(fo.owner))+'\1n '+
'\1W\1H'+fo.page+' '.repeat(FRAME_PAGENUM-fo.page.length)+' '+
'\1G\1H'+' Edit';
frame.putmsg(header);

View File

@ -193,7 +193,7 @@ function pageOwner(page) {
if (e !== BreakException) throw e;
}
//log(LOG_DEBUG,'+ pageOwner: page='+page+', owner: '+JSON.stringify(o));
log(LOG_DEBUG,'+ pageOwner: page='+page+', owner: '+JSON.stringify(o));
return o;
}
@ -228,7 +228,7 @@ function pageEditor(page) {
if (e !== BreakException) throw e;
}
//log(LOG_DEBUG,'+ pageEditor: page='+page+', editor: '+JSON.stringify(pageditor));
log(LOG_DEBUG,'+ pageEditor: page='+page+', editor: '+JSON.stringify(pageditor));
return pageditor;
}

23
main.js
View File

@ -690,22 +690,41 @@ while(bbs.online) {
require('ansitex/load/edit.js','CONTROL_EDIT');
// @todo validate that the user is authorised to edit it.
// If we are editing a specific frame, attempt to load it
if (fe) {
current = fo;
fo = new TexFrame();
fo.load(pageStr(fe));
// If the frame doesnt exist, check that the parent frame exists in case we are creating a new one
if (fo.page == null) {
log(LOG_DEBUG,'- ACTION_EDIT: check index: '+fe.index+' ('+String.fromCharCode(fe.index.charCodeAt(0)-1)+')');
// We can always create an 'a' frame
if (fe.index !== 'a') {
fo = new TexFrame();
fo.load(pageStr({frame: fe.frame, index: String.fromCharCode(fe.index.charCodeAt(0)-1)}));
log(LOG_DEBUG,'- ACTION_EDIT: check index: '+JSON.stringify(fo)+' ('+String.fromCharCode(fe.index.charCodeAt(0)-1)+')');
if (fo.page == null) {
fo = current;
// sendbaseline ERR_PAGE
sendBaseline(ERR_ROUTE,false);
sendBaseline(ERR_NO_PARENT,false);
mode = action = false;
break;
}
}
// New frame
fo = new TexFrame();
fo.frame = fe.frame;
fo.index = fe.index;
fo.cost = 0;
fo.owner = base64_decode(pageOwner(pageStr(fe)).logo);
fo.content = base64_encode('Start your new page...');
}
}
control.push(new edit(fo));
mode = false;