Move load(), parse() into the object. Edit frame now saves.
This commit is contained in:
parent
bfa0853d75
commit
2b5ecf6c75
96
load/defs.js
96
load/defs.js
@ -96,9 +96,9 @@ function TexFrame() {
|
||||
}
|
||||
|
||||
if ((this.type == FRAME_TYPE_LOGIN) || (this.type == FRAME_TYPE_RESPONSE)) {
|
||||
return header+this.parse(this.content);
|
||||
return header+this.parse(base64_decode(this.content));
|
||||
} else {
|
||||
return header+this.content;
|
||||
return header+base64_decode(this.content);
|
||||
}
|
||||
};
|
||||
|
||||
@ -113,44 +113,8 @@ function TexFrame() {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object.defineProperty(this,'page', {
|
||||
get: function() {
|
||||
if (this.frame == null || this.index == null) return null;
|
||||
return this.frame+this.index;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(this,'fields', {
|
||||
get: function() {
|
||||
return this.frame_fields;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(this,'accessible',{
|
||||
get: function() {
|
||||
log(LOG_DEBUG,'- Checking if user can access frame: '+this.page);
|
||||
log(LOG_DEBUG,' - User: '+JSON.stringify(user.number));
|
||||
log(LOG_DEBUG,' - Frame Owner: '+JSON.stringify(this.owner)+', System Frame: '+(SYSTEM_FRAMES.indexOf(this.owner)>-1));
|
||||
|
||||
system_frame = (SYSTEM_FRAMES.indexOf(this.owner)>-1);
|
||||
|
||||
// user.number 0 is unidentified user.
|
||||
if (user.number) {
|
||||
return (
|
||||
(this.isAccessible && this.isPublic) ||
|
||||
(this.isAccessible && ! this.isPublic && user.isMember) ||
|
||||
(user.isOwner)
|
||||
);
|
||||
|
||||
} else {
|
||||
return (system_frame && this.isPublic && this.isAccessible);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Load a frame from disk (.tex file)
|
||||
TexFrame.prototype.load = function(filename) {
|
||||
this.load = function(filename) {
|
||||
log(LOG_DEBUG,'Loading frame from: '+filename);
|
||||
|
||||
f = new File(system.mods_dir+'ansitex/text/'+filename+'.tex');
|
||||
@ -165,7 +129,7 @@ TexFrame.prototype.load = function(filename) {
|
||||
this[property] = load[property];
|
||||
}
|
||||
|
||||
this.content = base64_decode(this.content);
|
||||
//this.content = base64_decode(this.content);
|
||||
|
||||
} catch (error) {
|
||||
log(LOG_ERROR,'Frame error: '+error);
|
||||
@ -189,7 +153,7 @@ TexFrame.prototype.load = function(filename) {
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
TexFrame.prototype.parse = function(text) {
|
||||
this.parse = function(text) {
|
||||
var c = 1; // column
|
||||
var r = 2; // row (row 1 is the header)
|
||||
var output = '';
|
||||
@ -413,4 +377,54 @@ TexFrame.prototype.parse = function(text) {
|
||||
return output;
|
||||
};
|
||||
|
||||
this.save=function() {
|
||||
file = system.mods_dir+'ansitex/text/'+this.page+'.tex';
|
||||
w = new File(file);
|
||||
if (! w.open('w')) {
|
||||
log(LOG_ERROR,'! ERROR: Unable to create TEX file for '+this.page);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
w.write(JSON.stringify(this));
|
||||
w.close();
|
||||
|
||||
log(LOG_DEBUG,'Saved file: '+this.page+'.tex');
|
||||
}
|
||||
|
||||
Object.defineProperty(this,'page', {
|
||||
get: function() {
|
||||
if (this.frame == null || this.index == null) return null;
|
||||
return this.frame+this.index;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(this,'fields', {
|
||||
get: function() {
|
||||
return this.frame_fields;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(this,'accessible',{
|
||||
get: function() {
|
||||
log(LOG_DEBUG,'- Checking if user can access frame: '+this.page);
|
||||
log(LOG_DEBUG,' - User: '+JSON.stringify(user.number));
|
||||
log(LOG_DEBUG,' - Frame Owner: '+JSON.stringify(this.owner)+', System Frame: '+(SYSTEM_FRAMES.indexOf(this.owner)>-1));
|
||||
|
||||
system_frame = (SYSTEM_FRAMES.indexOf(this.owner)>-1);
|
||||
|
||||
// user.number 0 is unidentified user.
|
||||
if (user.number) {
|
||||
return (
|
||||
(this.isAccessible && this.isPublic) ||
|
||||
(this.isAccessible && ! this.isPublic && user.isMember) ||
|
||||
(user.isOwner)
|
||||
);
|
||||
|
||||
} else {
|
||||
return (system_frame && this.isPublic && this.isAccessible);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this;
|
@ -65,7 +65,7 @@ function edit(fo) {
|
||||
editor.menu.addItem('Save & Exit', save_and_exit);
|
||||
|
||||
x = new Graphic;
|
||||
x.ANSI = fo.content;
|
||||
x.ANSI = base64_decode(fo.content);
|
||||
log(LOG_DEBUG,JSON.stringify(x));
|
||||
|
||||
const bin = x.BIN;
|
||||
@ -99,7 +99,8 @@ function edit(fo) {
|
||||
frame.close();
|
||||
complete = true;
|
||||
console.clear(LIGHTGRAY);
|
||||
fo.content = editor.exportAnsi().join('');
|
||||
fo.content = base64_encode(editor.exportAnsi().join(''));
|
||||
fo.save();
|
||||
console.putmsg(fo.render());
|
||||
return '';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user