json-object-editor
Version:
JOE the Json Object Editor | Platform Edition
145 lines (140 loc) • 8.42 kB
JavaScript
var form ={
title: '${name}',
info:"Build a form to collect information from your audience. Add questions from the question panel.",
menuicon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="-8 -8 48 48"><path d="M16 2C14.7 2 13.8 2.9 13.4 4L11 4 6 4 5 4 5 5 5 28 5 29 6 29 26 29 27 29 27 28 27 5 27 4 26 4 21 4 18.6 4C18.2 2.9 17.3 2 16 2zM16 4C16.6 4 17 4.4 17 5L17 6 18 6 20 6 20 8 12 8 12 6 14 6 15 6 15 5C15 4.4 15.4 4 16 4zM7 6L10 6 10 9 10 10 11 10 21 10 22 10 22 9 22 6 25 6 25 27 7 27 7 6zM9 12L9 13 9 16 9 17 10 17 13 17 14 17 14 16 14 13 14 12 13 12 10 12 9 12zM16 13L16 15 23 15 23 13 16 13zM11 14L12 14 12 15 11 15 11 14zM9 19L9 24 14 24 14 19 9 19zM16 20L16 22 23 22 23 20 16 20z"/></svg>',
// Curated summary for agents
summary:{
description:'Form builder for collecting structured data from visitors with sections and questions.',
purpose:'Forms collect data from visitors through questions organized into sections. A form references questions for visitor ID and submission date tracking, can include code assets (includes), and supports custom validation and server actions. Forms are used in the Questionnaire and Church apps.',
labelField:'name',
defaultSort:{ field:'joeUpdated', dir:'desc' },
searchableFields:['name','info','_id'],
allowedSorts:['joeUpdated','created','name'],
relationships:{
outbound:[
{ field:'visitor_id_field', targetSchema:'question', cardinality:'one' },
{ field:'submission_date_field', targetSchema:'question', cardinality:'one' },
{ field:'questions', targetSchema:'question', cardinality:'many' },
{ field:'includes', targetSchema:'include', cardinality:'many' },
{ field:'tags', targetSchema:'tag', cardinality:'many' }
],
inbound:{ graphRef:'server/relationships.graph.json' }
},
joeManagedFields:['created','joeUpdated'],
fields:[
{ name:'_id', type:'string', required:true },
{ name:'itemtype', type:'string', required:true, const:'form' },
{ name:'name', type:'string', required:true },
{ name:'info', type:'string' },
{ name:'visitor_id_field', type:'string', isReference:true, targetSchema:'question' },
{ name:'submission_date_field', type:'string', isReference:true, targetSchema:'question' },
{ name:'sections', type:'objectList' },
{ name:'questions', type:'string', isArray:true, isReference:true, targetSchema:'question' },
{ name:'validate', type:'code' },
{ name:'callback', type:'code' },
{ name:'server_action', type:'code' },
{ name:'form_button_label', type:'string' },
{ name:'hostname', type:'string' },
{ name:'save_submission', type:'boolean' },
{ name:'upsert_submission', type:'boolean' },
{ name:'includes', type:'string', isArray:true, isReference:true, targetSchema:'include' },
{ name:'tags', type:'string', isArray:true, isReference:true, targetSchema:'tag' },
{ name:'joeUpdated', type:'string', format:'date-time', required:true },
{ name:'created', type:'string', format:'date-time', required:true }
]
},
fields:[
'name',
{ name:'visitor_id_field',
display:'visitor id field', type:'select',blank:true,width:'50%',
values:function(){return _joe.Data.question.where({canBeId:true});},
idprop:function(q){
var ques = _joe.getDataItem(q._id,'question');
if(ques.fieldname){return "fieldname";}
return "name";
}
},
{ name:'submission_date_field',width:'50%',
display:'submission date field', type:'select',blank:true,
values:function(){return _joe.Data.question.where({canBeDate:true});},
idprop:function(q){
var ques = _joe.getDataItem(q._id,'question');
if(ques.fieldname){return "fieldname";}
return "name";
}
},
{section_start:'Content'},
{name:'sections',type:'objectList',properties:['name','id'],comment:'name will be displayed, id is for css and js'},
// {name:'questions',type:'objectReference',values:'question'},
{name:'questions',type:'buckets',values:'question',reloadable:true,
comment:'Drag questions to the section of the form they belong in. <joe-button onclick="_joe.Fields.rerender(\'questions\');" class="joe-reload-button joe-button joe-iconed-button">reload form sections</joe-button>',
bucketCount:function(item){
return (item.sections && item.sections.length) || 1;
},
bucketNames:function(item){
var names = [];
(item.sections ||[]).map(function(s){
names.push(s.name);
})
return names;
},
template:function(f,q){
return `<joe-subtext>${q.question_type}</joe-subtext>
<joe-title>${q.name}</joe-title>
<joe-subtitle>${q.title || ''}</joe-subtitle>
<joe-subtitle>${q.fieldname||''}</joe-subtitle>`;
}
},
{section_end:'Content'},
{section_start:'Functions',collapsed:true},
{label:'On Client'},
{name:'validate',type:'code',language:'javascript',
comment:'function passed form values as object, <br/> Return true to continue processing form.<br/>Return false to cancel form, return a string to cancel form with message.<br/>ex function(visitor_submission_object){<br/> return true; <br/>}'},
{name:'callback',type:'code',language:'javascript',
comment:'function called on server response callback: function(data)'},
{label:'On Server'},
{name:'server_action',type:'code',language:'javascript',
comment:'function called on server, function(submission,form_info,request)'},
{section_end:'Functions'},
{sidebar_start:'right'},
'updated',
{section_start:'Preview'},
{name:'preview',type:'content',
template:function(item){
if(__jsc && __jsc.port){
return `<joe-button icon="form" class="joe-orange-button joe-button full-width"
onclick="window.open('/API/plugin/formBuilder/render?formid=${item._id}')">
Preview Form</joe-button>`;
}
return '<joe-button icon="form" class="joe-orange-button joe-button full-width" \
onclick="window.open(\'//'+location.hostname+':'+
__jsc.port+'/API/plugin/formBuilder/render?formid=${_id}\')">\
Preview Form</joe-button>';}
},
{section_end:'Preview'},
{section_start:'Adv'},
{name:'form_button_label',display:'form button label',type:'text',comment:'label for the form submit button'},
{name:'hostname',comment:'joe hostname'},
{name:'save_submission', type:'boolean', display:'save submission',comment:"use standard submission object"},
{name:'upsert_submission', type:'boolean', display:'upsert submission',
comment:"if submission exists (visitorID && submisson_date), update it"},
{section_end:'Adv'},
{section_start:'includes'},
'includes',
{name:'createInclude', type:'create',schema:'include',label:false},
{section_end:'includes'},
'tags',
{sidebar_end:'right'},
{section_start:'system',collapsed:true},
'_id','created','itemtype',
{section_end:'system'}
],
idprop: '_id',
listView:{
title: function(item){
return '<joe-title>${name}</joe-title><joe-subtitle>${COUNT[${sections}]} sections, </joe-subtitle><joe-subtext>${_id}</joe-subtext>'
},
listWindowTitle: 'Forms'
}
};
module.exports = form;