Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON as client data format #20

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified centrallix-os/sys/js/htdrv_fileupload.js
100755 → 100644
Empty file.
147 changes: 77 additions & 70 deletions centrallix-os/sys/js/htdrv_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,36 +264,37 @@ function form_cb_is_discard_ready()

function form_load_fields(data, no_clear, modify, onefield)
{
var name_to_id = [];

if (!data)
{
// No data supplied -- load hints based on previous information, if available.
for(var i in this.elements)
{
if (this.last_hints[this.elements[i].fieldname])
cx_set_hints(this.elements[i], this.last_hints[this.elements[i].fieldname], 'data');
else
cx_set_hints(this.elements[i], '', 'data');
//return;
}
else
{
for(var j in data)
{
if (data[j].oid)
name_to_id[data[j].oid] = j;
}
}

// Loop through the form elements to load the data.
for(var i in this.elements)
{
if (onefield && onefield != this.elements[i].fieldname) continue;
var field = this.elements[i].fieldname;

// are we loading just one field instead of all of them?
if (onefield && onefield != field)
continue;

if (!this.elements[i]._form_type &&
(typeof name_to_id[this.elements[i].fieldname]) != 'undefined' &&
(typeof data[name_to_id[this.elements[i].fieldname]].type) != 'undefined')
this.elements[i]._form_type = data[name_to_id[this.elements[i].fieldname]].type;
// Make a note of the data type.
if (!this.elements[i]._form_type && data)
{
var t = data.getAttrType(field);
if (t !== null)
this.elements[i]._form_type = t;
}

if (this.elements[i].fieldname == '__position')
// Synthetic "position" form element?
if (field == '__position')
{
var txt = "";
if (this.mode == "New")
Expand All @@ -313,18 +314,24 @@ function form_load_fields(data, no_clear, modify, onefield)
}
this.elements[i].setvalue(txt);
}
else if ((typeof name_to_id[this.elements[i].fieldname]) != 'undefined' && (typeof data[name_to_id[this.elements[i].fieldname]].value) != 'undefined')
{
var id = name_to_id[this.elements[i].fieldname];
this.elements[i].setvalue(data[id].value);
if (modify)
this.elements[i]._form_IsChanged = true;
cx_set_hints(this.elements[i], data[id].hints, 'data');
this.last_hints[this.elements[i].fieldname] = data[id].hints;
}
else if (!no_clear)
else
{
this.elements[i].clearvalue();
// Normal field -- check to see if it exists in the data.
var attr = null;
if (data && (attr = data.getAttr(field)))
{
// It does exist -- set its value and presentation hints
this.elements[i].setvalue(attr.get());
if (modify)
this.elements[i]._form_IsChanged = true;
cx_set_hints(this.elements[i], attr.getHints(), 'data');
this.last_hints[field] = attr.getHints();
}
else if (!no_clear)
{
// It does not exist - clear it.
this.elements[i].clearvalue();
}
}
}
}
Expand Down Expand Up @@ -375,19 +382,20 @@ function form_cb_object_available(data, osrc, why)
if (data)
{
this.ClearAll(true);
for(var j in data)
var alist = data.getAttrList();
for(var aname in alist)
{
if (!this.ifcProbe(ifValue).Exists(data[j].oid, true))
if (!this.ifcProbe(ifValue).Exists(aname, true))
{
this.ifcProbe(ifValue).Add(data[j].oid, form_cb_getvalue);
this.valuelist.push(data[j].oid);
this.ifcProbe(ifValue).Add(aname, form_cb_getvalue);
this.valuelist.push(aname);
}
this.ifcProbe(ifValue).Changing(data[j].oid, data[j].value, true);
this.ifcProbe(ifValue).Changing(aname, data.getAttrValue(aname), true);
}
this.data=data;
if (data.__osrc_is_last || (this.didsearch && data.id == this.recid))
this.lastrecid = data.id;
this.recid = data.id;
if (data.__osrc_is_last || (this.didsearch && data.getID() == this.recid))
this.lastrecid = data.getID();
this.recid = data.getID();

this.LoadFields(this.data);

Expand Down Expand Up @@ -1130,67 +1138,66 @@ function form_action_queryexec()
{
if(!htr_boolean(wgtrGetServerProperty(this,'allow_query',1))) {alert('Query not allowed');return 0;}
if(!(this.mode=='Query')) {alert("You can't execute a query if you're not in Query mode.");return 0;}
/** build an query object to give the osrc **/
var query=new Array();
query.oid=null;
query.joinstring='AND';

// build an query object to give the osrc
var query = new $CX.Types.osrcObject();
query.setID(null);
query.setJoin('AND');

this.recid = 1;
this.lastrecid = null;


// Set status for user
for(var i in this.statuswidgets)
{
this.statuswidgets[i].setvalue('QueryExec');
}

// Add the criteria to the query object
for(var i in this.elements)
{
if(this.elements[i]._form_IsChanged)
{
var v = this.elements[i].getvalue();
if (v != null && v != '')
{
var t=new Object();
t.oid=this.elements[i].fieldname;
t.value=v;
if (typeof this.elements[i]._form_type == 'undefined')
t.type='undefined';
else
t.type=this.elements[i]._form_type;
if(isArray(v))
t.type+='array';
query.push(t);
// Determine data type
var type = 'undefined';
if (typeof this.elements[i]._form_type != 'undefined')
type = this.elements[i]._form_type;
if (isArray(v))
type += 'array';

// Add the criteria
query.newAttr(this.elements[i].fieldname, v, type);
}
}
}
/** Done with the query -- YEAH **/
//if(confirm('Send to "'+this.osrc.name+'"(osrc):'+query))
{
this.Pending=true;
this.IsUnsaved=false;
this.is_savable = false;
//this.cb['DataAvailable'].add(this,new Function('this.osrc.ifcProbe(ifAction).Invoke("First", this)'));
this.osrc.ifcProbe(ifAction).Invoke("QueryObject", {query:query, client:this, ro:this.readonly});
}
delete query;

this.Pending=true;
this.IsUnsaved=false;
this.is_savable = false;
this.osrc.ifcProbe(ifAction).Invoke("QueryObject", {query:query, client:this, ro:this.readonly});
}

function form_build_dataobj()
{
var dataobj=new Array();
// Get a new object
var dataobj=new $CX.Types.osrcObject();

// For each changed element, add an attribute to the data object we're creating.
for(var i in this.elements)
{
if(this.elements[i]._form_IsChanged)
{
var t=new Object();
t.oid=this.elements[i].fieldname;
t.value=this.elements[i].getvalue();
t.type=this.elements[i]._form_type;
dataobj.push(t);
dataobj.newAttr(this.elements[i].fieldname, this.elements[i].getvalue(), this.elements[i]._form_type);
}
}

// Set the record ID
if (this.mode == "New" || !this.data)
dataobj.oid = 0;
dataobj.setID(0);
else
dataobj.oid=this.data.oid;
dataobj.setID(this.data.getID());

return dataobj;
}

Expand Down
Empty file modified centrallix-os/sys/js/htdrv_map.js
100755 → 100644
Empty file.
Loading