use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class UISpec method generateDataTypeValidator.
/**
* This is a bit of JSON needed by the UI so they can validate data types like integer,float etc
* CSPACE-4330
* @param f
* @param context
* @return
* @throws JSONException
*/
private JSONObject generateDataTypeValidator(FieldSet fs, UISpecRunContext context, JSONArray decorators) throws JSONException {
Field f = (Field) fs;
JSONObject out = new JSONObject();
JSONObject options = new JSONObject();
String type = f.getDataType();
if (type.equals("")) {
type = "string";
}
options.put("type", type);
options.put("label", f.getLabel());
JSONObject decorator = getDecorator("fluid", null, "cspace.inputValidator", options, f.isReadOnly());
if (!f.isRefactored()) {
if (f.hasContainer()) {
decorator.put("container", getSelector(f, context));
}
}
if (decorators == null) {
decorators = new JSONArray();
}
decorators.put(decorator);
out.put(DECORATORS_KEY, decorators);
out.put("value", actualFieldEntry(f, context));
return out;
}
use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class UISpec method actualAutocomplete.
/**
* display the autocomplete markup for the uispec
* @param f
* @param context
* @return
* @throws JSONException
*/
private JSONObject actualAutocomplete(FieldSet fs, UISpecRunContext context, JSONArray decorators) throws JSONException {
JSONObject out = new JSONObject();
Field f = (Field) fs;
JSONObject options = new JSONObject();
String extra = "";
if (f.getRecord().isType("authority")) {
extra = "vocabularies/";
}
String[] contextdata = context.getUIRecordUrl();
String autocompleteurl = extra + f.getRecord().getWebURL();
if (contextdata.length > 0) {
autocompleteurl = contextdata[0];
}
options.put("queryUrl", "../../../tenant/" + tenantname + "/" + autocompleteurl + "/autocomplete/" + f.getID());
options.put("vocabUrl", "../../../tenant/" + tenantname + "/" + autocompleteurl + "/source-vocab/" + f.getID());
if (!f.getAutocompleteFuncName().equals("")) {
JSONObject invokers = new JSONObject();
JSONObject subitem = new JSONObject();
String[] test = f.getAutocompleteFuncName().split("\\|");
if (test.length > 1) {
subitem.put("funcName", test[1]);
invokers.put(test[0], subitem);
}
options.put("invokers", invokers);
}
if (!f.getAutocompleteStrings().equals("")) {
JSONObject strings = new JSONObject();
String val = f.getAutocompleteStrings();
String[] lines = val.split("\\r?\\n");
for (int i = 0; i < lines.length; i++) {
String[] data = lines[i].split("\\|");
if (data.length == 2) {
strings.put(data[0].trim(), data[1].trim());
}
}
options.put("strings", strings);
}
JSONObject decorator = getDecorator("fluid", null, "cspace.autocomplete", options, f.isReadOnly());
if (!f.isRefactored()) {
if (f.hasContainer()) {
decorator.put("container", getSelector(f, context));
}
}
if (decorators == null) {
decorators = new JSONArray();
}
decorators.put(decorator);
out.put(DECORATORS_KEY, decorators);
if (f.isRefactored()) {
out.put("value", actualFieldEntry(f, context));
}
return out;
}
use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class UISpec method actualDeURN.
/**
* This is a bit of JSON needed by the UI so they display fields decorated
* with de-URN behavior (extracting display names from URNs) in the UIspec
* @param f
* @param context
* @return
* @throws JSONException
*/
private JSONObject actualDeURN(FieldSet fs, UISpecRunContext context, JSONArray decorators) throws JSONException {
JSONObject out = new JSONObject();
Field f = (Field) fs;
JSONObject decorator = getDecorator("fluid", null, "cspace.util.urnToStringFieldConverter", null, f.isReadOnly());
if (!f.isRefactored()) {
if (f.hasContainer()) {
decorator.put("container", getSelector(f, context));
}
}
if (decorators == null) {
decorators = new JSONArray();
}
decorators.put(decorator);
out.put(DECORATORS_KEY, decorators);
out.put("value", actualFieldEntry(f, context));
return out;
}
use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class UISpec method generateComputedField.
/**
* Generate the JSON needed by the UI to create a computed field.
* @param f
* @param context
* @return
* @throws JSONException
*/
protected JSONObject generateComputedField(FieldSet fs, UISpecRunContext context) throws JSONException {
Field f = (Field) fs;
JSONObject out = new JSONObject();
JSONArray decorators = new JSONArray();
JSONObject options = new JSONObject();
String type = f.getDataType();
if (type.equals("")) {
type = "string";
}
options.put("type", type);
options.put("label", f.getLabel());
options.put("readOnly", f.isReadOnly());
if (StringUtils.isNotEmpty(f.getUIFunc())) {
options.put("func", f.getUIFunc());
}
if (StringUtils.isNotEmpty(f.getUIArgs())) {
options.put("args", f.getUIArgs().split(","));
}
String root = "";
String elPath = "";
// really needs to be refactored so it doesn't have to be repeated here.
if (f.getParent().isExpander() || f.isRepeatSubRecord()) {
root = "{row}";
String[] paths = f.getIDPath();
elPath = paths[paths.length - 1];
} else if (f.getParent() instanceof Repeat) {
// remove bogus repeats used in search
Repeat rp = (Repeat) f.getParent();
if (!rp.getSearchType().equals("repeator") && !this.spectype.equals("search")) {
root = "{row}";
String[] paths = f.getIDPath();
elPath = paths[paths.length - 1];
} else if (this.spectype.equals("search")) {
root = "{row}";
String[] paths = f.getIDPath();
elPath = paths[paths.length - 1];
} else {
elPath = displayAsveryplainWithoutEnclosure(f, context);
}
} else {
elPath = displayAsveryplainWithoutEnclosure(f, context);
}
options.put("root", root);
options.put("elPath", elPath);
JSONObject decorator = getDecorator("fluid", null, "cspace.computedField", options, f.isReadOnly());
if (!f.isRefactored()) {
if (f.hasContainer()) {
decorator.put("container", getSelector(f, context));
}
}
decorators.put(decorator);
out.put("decorators", decorators);
out.put("value", actualFieldEntry(f, context));
return out;
}
use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class UISpec method actualHierarchyEntry.
/**
* Create hierarchy specific output for uispec
* @param out
* @param f
* @param context
* @throws JSONException
*/
private void actualHierarchyEntry(JSONObject out, FieldSet f, UISpecRunContext context) throws JSONException {
String condition = "cspace.hierarchy.assertEquivalentContexts";
Record thisr = f.getRecord();
JSONObject cond = new JSONObject();
if (f instanceof Field) {
FieldSet fs = (FieldSet) f.getParent();
JSONObject args = new JSONObject();
args.put(fs.getID(), displayAsveryplain(fs, context));
cond.put("args", args);
cond.put("funcName", condition);
}
JSONObject ttree = new JSONObject();
actualMessageKey(ttree, thisr.getUILabelSelector(f.getID()), f.getLabel());
// This looks wrong - a single decorator is being set as the value of the
// plural decorators key, which usually holds an array of decorators.
// However, it turns out that UI is forgiving, and handles either Object or Array
JSONObject decorator = getDecorator("addClass", "hidden", null, null, f.isReadOnly());
JSONObject decorators = new JSONObject();
decorators.put(DECORATORS_KEY, decorator);
JSONObject ftree = new JSONObject();
ftree.put(thisr.getUILabelSelector(f.getID()), decorators);
JSONObject cexpander = new JSONObject();
cexpander.put("type", "fluid.renderer.condition");
cexpander.put("condition", cond);
cexpander.put("trueTree", ttree);
cexpander.put("falseTree", ftree);
actualTrueTreeSub(out, cexpander);
}
Aggregations