Okay, I’m really stumped… been working on this on a while so I’m not ashamed to include code I’ve commented out.
I have a field on my Navigator called Categories. It’s a global set as checkboxes. Via a button on a separate form, as user can add values to the global, rename values, or delete them… No problem…
Here is the code attached to the Add Category button:
var newvalue = plugins.dialogs.showInputDialog('Add item to the list ' + globals.gListNames ,'');
if(newvalue)
{
controller.newRecord()
//user_id = globals.gUsersID
user_id = globals.gListNames
valuelist_item = newvalue
//valuelist = newvalue
controller.saveData();
Get_Field_Names();
application.updateUI()
}
The large global is called gListValues. It has a valuelist attached called: servoy_id pulling all my users from the users table and a method, Change_Item_Value, attached to its onDataChange:
var oldvalue = arguments[0]
//var query = "select valuelist_item from valuelist where user_id = " + globals.gUsersID
var query = "select valuelist_item from valuelist where user_id = " + globals.gListNames
var dataset = databaseManager.getDataSetByQuery (controller.getServerName(), query, null, 100);
var answer = plugins.dialogs.showQuestionDialog( "Value List", "Delete '" + globals.gListValues + "' from the list " +
globals.gListNames + "?", "Delete", "Modify", "Cancel")
if ( answer == "Delete" )
{
dataset.removeRow(1)
var navigator_value = forms.Navigator_Contacts.elements.categories.getSelectedElements()
var valuelist_value = forms.ValueList.elements.gListValues.getSelectedElements()
for(k=0; k<navigator_value.length; k++)
{
if(navigator_value[k] ==valuelist_value[0] )
{
plugins.dialogs.showErrorDialog( 'Error','You has no rights to delete '+ globals.gListValues +'.Because ' + globals.gListValues +' is selected in the Navigator' ,'okay')
return;
}
}
//query for checks in the check box! If there are records, prevent the user from deleting.
controller.find()
valuelist_item = globals.gListValues
//user_id = globals.gUsersID
servoy_id = globals.gListNames
//user_id = globals.gListNames
var x = controller.search()
if(x > 0)
{
//something found
controller.deleteRecord()
Get_Field_Names();
}
}
else
{
if ( answer == "Modify" )
{
var newvalue = plugins.dialogs.showInputDialog('Modify value','New value');
if(newvalue)
{
controller.find()
valuelist_item = globals.gListValues
//user_id = globals.gUsersID
servoy_id = globals.gListNames
var x = controller.search()
if(x > 0)
{
//something found
valuelist_item = newvalue
controller.saveData()
Get_Field_Names();
}
}
}
Get_Column_Values();
}
The method above calls another method called Get_User_Names:
var query = "SELECT valuelist_item FROM valuelist WHERE user_id = " + globals.gListNames + " ORDER BY valuelist_item"
var dataset = databaseManager.getDataSetByQuery (controller.getServerName(), query, null, -1);
var list = list1.concat(dataset.getColumnAsArray(1));
application.output(":"+list[0]+":")
application.setValueListItems('ValueList_Fields',list);
The user name field, gListNames, has an onDataChange method attached called: Get_Column_Values:
globals.gListValues = "";
var maxReturedRows = 1000;
var query = 'select valuelist_item from valuelist where ' + "group_id= '" + globals.gListNames + "'";
var dataset = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), query, null, maxReturedRows);
if(dataset.getMaxRowIndex() > 0){
application.setValueListItems( 'ValueList_Fields', dataset)
}else{
application.setValueListItems( 'ValueList_Fields', new Array('ERROR! User Not Found'))
}
As I said all of this works fine and please use it as I modified this from something I saw some time ago…
These categories appear on a per user basis and are triggered by their login name…
Now I want to be able to add categories to gListValues from those in gListValuesGroup, that will appear for EVERY user all the time based on whether or not they belong to my groups table…
Here the code for that… and it’s where I’m stuck…
The Add Category Button has an onAction attached:
if(!globals.gListGroups) {
var missingValue = plugins.dialogs.showWarningDialog('MISSING GROUP NAME!', 'Select a Group Name first! ','OKAY');
return;
}
var newvalue = plugins.dialogs.showInputDialog('Add item to the list ' + globals.gListGroups ,'');
if(newvalue)
{
controller.newRecord()
//group_id = workflow.groups.groupid
group_id = globals.gListGroups
valuelist_item = newvalue
controller.saveData();
Get_Field_NamesGroups();
application.updateUI()
}
The method above calls another method called: Get_Field_NamesGroups:
var query = "SELECT valuelist_item FROM valuelist WHERE group_id = " + globals.gListGroups + " ORDER BY valuelist_item"
var dataset = databaseManager.getDataSetByQuery (controller.getServerName(), query, null, -1);
var list = [""].concat(dataset.getColumnAsArray(1));
var list2 = [].concat(dataset.getColumnAsArray(1));
application.output(":"+list[0]+":")
application.output(":"+list2+":")
application.setValueListItems('ValueList_FieldsGroups',list2);
var Group_values = application.getValueListItems('ValueList_FieldsGroups')
Group_values = Group_values.getColumnAsArray(1)
The gListGroups drop down field has a value list attached from the group table using groupname and groupid pk, and an onDataChange attached called Change_Item_ValueGroups:
globals.gListValuesGroup = "";
var maxReturedRows = 1000;
var query = 'select valuelist_item from valuelist where ' + "globals.gUsersID = '" + globals.gListGroups + "'";
//"group_id = '" + globals.gListGroups + "'";
/*
var query = 'select DISTINCT valuelist.valuelist_item,groups.groupname from valuelist,users,groups where ' + "users.servoy_id = '" + globals.gListNames + " ' AND " + "globals.gUsersID = '" + globals.gListGroups + "' AND " + "valuelist.group_id = '" + globals.gListGroups + "'";
application.output(dataset.getValue(1,2));
*/
var dataset = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), query, null, maxReturedRows);
if(dataset.getMaxRowIndex() > 0){
application.setValueListItems( 'ValueList_FieldsGroups', dataset)
}else{
application.setValueListItems( 'ValueList_FieldsGroups', new Array('ERROR! User Not Found'))
}
var temp = application.getValueListItems('ValueList_ValuesGroups');
temp = temp.getColumnAsArray(1)
The gListValuesGroup global has a custom valuelist attached called Valuelist_FieldGroups and an onDataChange called Change_Item_ValueGroups:
var oldvalue = arguments[0]
var query = "select valuelist_item from valuelist where group_id =' " + globals.gListGroups +" '"
var dataset = databaseManager.getDataSetByQuery (controller.getServerName(), query, null, 100);
if(dataset.getMaxRowIndex() == 0) {
globals.gListValuesGroup = ""
return;
} else {
Get_Column_ValuesGroups();
// Get_Column_Values();
/*
var answer = plugins.dialogs.showQuestionDialog( "Value List", "Delete '" + globals.gListValuesGroup + "' from the list " + globals.gListGroups + "?", "Delete", "Modify", "Cancel")
if ( answer == "Delete" )
{
//query for checks in the check box! If there are records, prevent the user from deleting.
controller.find()
valuelist_item = globals.gListValuesGroup
group_id = globals.gGroupID
var x = controller.search()
if(x > 0)
{
//something found
controller.deleteRecord()
Get_Field_NamesGroups();
}
}
else
{
if ( answer == "Modify" )
{
var newvalue = plugins.dialogs.showInputDialog('Modify value','New value');
if(newvalue)
{
controller.find()
valuelist_item = globals.gListValues
user_id = globals.gUsersID
var x = controller.search()
if(x > 0)
{
//something found
valuelist_item = newvalue
controller.saveData()
Get_Field_Names();
}
}
}
}
//refresh the value list items
Get_Column_ValuesGroups();
*/
}
There is an onLoad on the form called Get_Group_Value:
//var query = "SELECT groups.group_id FROM users,groups WHERE users.servoy_id=" + globals.gListNames + ""
//var dataset = databaseManager.getDataSetByQuery (controller.getServerName(), query, null, -1);
//var value = dataset.getColumnAsArray(1)
//return;
var Group_values = application.getValueListItems('ValueList_FieldsGroups')
Group_values = Group_values.getColumnAsArray(1)
// Its a dummy value for the first value of the array....
var dummy_array=new Array()
dummy_array[0] = "dummy"
Group_values =dummy_array.concat(Group_values)
//application.output(":"+list1[0]+":")
var query = "SELECT valuelist_item FROM valuelist WHERE user_id = " + globals.gListNames + " ORDER BY valuelist_item"
var dataset = databaseManager.getDataSetByQuery (controller.getServerName(), query, null, -1);
var list = dataset.getColumnAsArray(1)
list=Group_values.concat(list);
application.output(":"+list[1]+":")
application.setValueListItems('ValueList_Fields',list);