";
}
}*/
return_html = return_html + "" + search_html + "";
return return_html;
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json);
dropdown_wortel = 1;
question_label_class_html = new_option_settings(true, true, false, '0.0', label, required, '', false, '', false, '', true, tag_value);
options_html = new_option_settings(true, false, false, '0.1', options['0.1'], '', '');
answers_options_inputs_button_html = "add new option "
extra_html = 'Make searchable ';
extra_html = extra_html + 'Import options from CSV file ';
extra_html = extra_html + 'Options import templateDownload ';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
options_html, //answers_options_inputs
answers_options_inputs_button_html, //answers_options_inputs_button
extra_html //extra
);
$.each(options, function (key, value) {
var res = key.toString().split(".")[0];
if (key != '0.1' && key != '0.0') { dropdown_wortel++; add_drop_item_with_import(value); }
});
if (extra) {
if (extra['searchable'] == 'on') {
$('[name=searchable]').prop('checked', true);
}
}
},
after_build: function (element, json) {
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
var work_array = load_question_json(json);
if (work_array.extra) {
if (work_array.extra['searchable'] == 'on') {
app.survey.enable_select2($('[name=dropdown-0-' + work_array.id + ']'));
}
}
},
logica: function (json_array) {
var current_response=get_specific_response(get_survey_id() );
//[{"1602":{"id":"1602","tab_id":0,"type":"dropdown_with_import","value":"1"},"not":false}]
var tab_id = json_array.tab_id;
if ($('#vraagwrapper_' + json_array.id + ':visible').length == 0 && $('#vraagwrapper_' + json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if ($('[name=dropdown-0-' + json_array.id + ']').val() == json_array.value) return true; //eerst naar de actieve waarde kijken.
else if (!(tab_id in current_response)) return false;
else if ($('[name=dropdown-0-' + json_array.id + ']').length == 0) if (current_response[tab_id][json_array.id][0]['value'] == json_array.value) return true; //daarna naar opgeslagen waarden kijken ALS het item niet actief is op de tab
return false;
},
get_value: function (id) {
return {
'0': {
'value': $('#dropdown-0-' + id).val(),
'type': 'dropdown',
'raw_value': $('#dropdown-' + $('#dropdown-0-' + id).val() + '-' + id).html(),
'required': ($('#dropdown-0-' + id).data('required') == '1'),
'hidden_by_logic': ($('#dropdown-0-' + id).parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
if (current_response[tab_id][id][0]['value'] == null && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required' });
}
return error_array;
}
};
function dropdown_with_import_editor(antwoorden_json) { return question_plugins.dropdown_with_import.editor_build(antwoorden_json); }
function dropdown_with_import_builder(json, taal) { return question_plugins.dropdown_with_import.build(json, taal); }
function add_drop_item_with_import(label) //well answers_options_well
{
if (typeof (label) == "undefined") label = '';
$('.answers_options_inputs').append(new_option_settings(true, false, false, '0.' + dropdown_wortel, label, '', ''));
$('.answers_options_inputs').append(' ');
}
function remove_drop_item(obj) {
if (confirm('Are you sure you want to remove this option?')) {
//$(obj).prev().prev().remove();
$(obj).prev().remove();
$(obj).remove();
}
}
function fileheader_test(header_String) {
if (header_String == "Label") {
$("#btn-import").removeClass('disabled');
$(".file_check").removeClass('glyphicon-remove').removeClass('glyphicon-minus').addClass('glyphicon-ok');
return true;
}
else {
$("#btn-import").addClass('disabled');
$(".file_check").removeClass('glyphicon-ok').removeClass('glyphicon-minus').addClass('glyphicon-remove');
return false;
}
}
$(document.body).on("change", "#import_file", function () {
var file = document.getElementById("import_file").files;
var reader = new FileReader();
handleFiles(file);
});
function handleFiles(files) {
// Check for the various File API support.
if (confirm('Are you sure you want to import this file? This will replace all existing options in the dropdown.')) {
if (window.FileReader) {
// FileReader are supported.
getAsText(files[0]);
} else {
alert('FileReader are not supported in this browser.');
}
}
else {
$('#import_file').val('');
}
}
function getAsText(fileToRead) {
var reader = new FileReader();
// Read file into memory as UTF-8
reader.readAsText(fileToRead);
// Handle errors load
reader.onload = loadHandler;
reader.onerror = errorHandler;
}
function loadHandler(event) {
var csv = event.target.result;
processData(csv);
}
function processData(csv) {
var allTextLines = csv.split(/\r\n|\n|\r/);
lines = [];
dropdown_wortel = 0;
$('.answers_options_inputs').html('');
for (var i = 0; i < allTextLines.length; i++) {
if (i == 0) if (!fileheader_test(allTextLines[i])) { alert('Incorrect formatting. File declined'); return false; }
var data = allTextLines[i].split(',');
if (data.length = 1) var data = allTextLines[i].split(';');
var tarr = {};
if (i == 0) continue;
//Datum,Email,Storename,Address,Housenr,Zipcode,Checklist_id
//Voornaam, Achternaam - nummer
tarr['persnummer'] = data[0];
tarr['achternaam'] = data[1];
tarr['voornaam'] = data[2];
tarr['titel'] = data[3];
dropdown_wortel++;
add_drop_item(data[0]);//(tarr['voornaam'].replace(/'/g,''')+', '+tarr['achternaam'].replace(/'/g,''')+' - '+tarr['persnummer']);
/* for (var j=0; j /g, ">").replace(/' + trans('required') + '';
var required_className = 'required';
}
var current_response = app.survey.get_current_response();
var disabled_string=app.survey.is_disabled(app.survey.get_survey_id()) ? " disabled " : "";
var return_html = '';
var fot_value = '';
try {
if( typeof current_response[app.survey.get_current_tab()] !== 'undefined' )
{
if(work_array['id'] in current_response[app.survey.get_current_tab()])
{
fot_value = current_response[app.survey.get_current_tab()][ work_array['id'] ][0].value;
}
}
} catch(e){
}
//console.log('fot_value',fot_value)
storage = ' ';
//console.log(work_array.extra);
test_dump = work_array;
if (!(work_array.extra == "")) {
if (!('no_storage' in work_array.extra) || is_electron) storage = '' + dropdown_tags;
}
else if (work_array.extra['photo_clients_tags'] == 'on') {
var client_select = 'Select a client: ' + required_tags_warning + ' Select a client ';
$.each(work_array.extra, function (i, v) {
if(!isNaN(i) )
{
if(v == work_array.default_value ) client_select = client_select + '' + v + ' ';
else client_select = client_select + '' + v + ' ';
}
});
client_select = client_select + '
';
return '' + string_fixed + required_marked + ' ' + storage + ' ' + client_select;
}
else {
return '' + string_fixed + required_marked + ' ' + storage + ' ';
}
//work_array.default_value = null;
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json);
client_option_html = '';
console.log('default_value',default_value);
$.each(availableTags_3, function (i, v) {
if(default_value == v ) {
console.log('default_value 2',default_value);
client_option_html = client_option_html + '' + v + ' ';
}
else client_option_html = client_option_html + '' + v + ' ';
});
question_label_class_html = question_options(
{
'label' : true,
'required' : true,
'input_type' : false,
'sub_id' : '0.0',
'label_value' : label,
'required_value' : required,
'input_type_value' : '',
'default_value' : null,
'default_value_value' : null,
'placeholder' : null,
'placeholder_value' : null,
'tag' : true,
'tag_value' : tag_value.replace("|", "").replace("|", ""),
'quiz_correct' : null,
'quiz_correct_meer_correct' : null
}) +' ' + 'pre set manual client tag
' ;
//question_label_class_html = new_option_settings(true, true, false, '0.0', label, required, '')
//tag_check = ' ';
console.log('extra',extra);
no_storage_checked = "";
extra_html = '';
var auto_tag = {'auto_tag_off':'','auto_tag_on':'','auto_tag_off_manual':''};
if('auto_tag' in extra)
{
if(extra['auto_tag'] == 'auto_tag_off')
{
auto_tag['auto_tag_off'] = 'checked';
}
else if(extra['auto_tag'] == 'auto_tag_off_manual')
{
auto_tag['auto_tag_off_manual'] = 'checked';
}
else
{
auto_tag['auto_tag_on'] = 'checked';
}
}
else
{
if(extra['photo_tags'] == 'on')
{
auto_tag['auto_tag_off_manual'] = 'checked';
}
else if(extra['photo_clients_tags'] == 'on')
{
auto_tag['auto_tag_off_manual'] = 'checked';
}
else
{
auto_tag['auto_tag_off'] = 'checked';
}
}
if ('no_storage' in extra) no_storage_checked = "checked";
//extra_html = extra_html + ' ';
extra_html = extra_html + 'Do not allow photo\'s from storage ';
extra_html = extra_html + ' No tag
Auto tag with subproject client or project client
Manual tag
';
extra_html = extra_html + 'Photo tag option (clients list) ';
extra_html = extra_html + 'Photo tag option (custom list) Tag options: Add more ';
extra_html = extra_html + 'Tag is required ';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
extra_html //extra
);
$('.tags_option').hide();
$('.pre_client_table').hide();
// $('#theForm').after(tag_check);
if(auto_tag['auto_tag_off_manual'] == 'checked') manual_tag(true);
if (extra) {
if (extra['photo_tags'] == 'on') {
manual_tag(true);
$('.tags_option').show();
$('[name=photo_tags]').prop('checked', true);
console.log('extra=>',extra);
$.each(extra, function (key, value) {
console.log(key +' => '+value)
if (key == 1) $('[name=' + key + ']').val(value);
else {
if(!isNaN(key) ) add_more_tags(value);
//$('[name='+key+']').val(value);
}
});
}
if (extra['photo_clients_tags'] == 'on') {
$('[name=photo_clients_tags]').prop('checked', true);
$('.pre_client_table').show();
manual_tag(true);
}
if (extra['required_tags'] == 'on') {
$('[name=required_tags]').prop('checked', true);
}
}
},
after_build: function (element, json) {
/* var is_electron = window && window.process && window.process.type;
if (is_electron) {
element.find(".photo-button").hide();
}
*/
if (element.find(".photo-value").val() !== "") {
element.find(".photo-button,.gallery-button").addClass("photo_taken");
element.find("i.camera-icon,i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
}
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
var id = $(element).find(".foto_tag").data('question_id');
var tab_id = app.survey.get_current_tab();//app.survey.view.get('active_tab');
var current_response = app.survey.get_current_response();
$(element).find(".photo-button").on("click",function(){
question_plugins.foto.take_picture($(this).data("id"));
});
$(element).find(".gallery-button").on("click",function(){
question_plugins.foto.browse_picture($(this).data("id"));
});
if (tab_id in current_response) {
if ($(element).find(".foto_tag").length) $(element).find(".foto_tag").val(current_response[tab_id][id][0].tags);
}
var work_array = app.survey.load_question_json(json);
if(work_array.extra['photo_clients_tags'] == 'on') {
console.log("loadage of photo clients tags");
var return_html = 'Select a client ';
var id = $(element).find(".foto_tag").data('question_id');
api_request('client_users', "get", {}, function (data) {
console.log("data get");
//console.log(data);
console.log('default_value',work_array.default_value);
$.each(data, function (i, v) {
if(v['full_name'] == work_array.default_value ) return_html = return_html + '' + v['full_name'] + ' ';
else return_html = return_html + '' + v['full_name'] + ' ';
});
$(element).find('select[name=foto_tag-0-' + id + ']').html(return_html);
});
}
app.survey.enable_select2($(element).find("select"));
},
logica: function (json_array) {
return true;
},
get_value: function (id) {
return {
'0': {
'value': $("#foto-0-" + id).val(),
'type': 'foto',
'required': ($('#foto-0-' + id).data('required') == '1'),
'required_tag': ($('#foto-0-' + id).data('required_tag') == '1'),
'tags': ($('#foto-0-' + id).data('pre-tag') != '|' ? ($('#foto-0-' + id).data('pre-tag') + '' + app.survey.get_tag(id) ) : app.survey.get_tag(id) ), //get_tag(id)
//'tag' : $("[name='foto_tag-0-" + id + "']").val(),
'hidden_by_logic': ($('#foto-0-' + id).parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response=app.survey.get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
if (current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required' });
if (current_response[tab_id][id][0]['tags'] == null && current_response[tab_id][id][0]['required_tag'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required_tag' });
}
return error_array;
}
};
function foto_editor(antwoorden_json) { return question_plugins.foto.editor_build(antwoorden_json); }
function foto_builder(json, taal) { return question_plugins.foto.build(json, taal); }
function manual_tag(on)
{
if(on)
{
$(".manual_tag_color").css("color", "#778288");
$(".manual_tag_visable").show();
$('.pre_client_table').show();
}
else
{
$('.pre_client_table').hide();
$(".manual_tag_color").css("color", "color:#c3cace;8");
$(".manual_tag_visable").hide();
$(".manual_tag_visable").prop('checked',false);
$('.tags_option').hide();
}
}
function tag_option_2(obj) {
if ($(obj).is(":checked")) {
$('.tags_option').hide(); $('[name=photo_tags]').prop('checked', false);
$('.pre_client_table').show();
}
else $('.pre_client_table').hide();
}
function tag_option(obj) {
if ($(obj).is(":checked")) { $('.tags_option').show(); $('[name=photo_clients_tags]').prop('checked', false); }
else $('.tags_option').hide();
}
function add_more_tags(lbl) {
console.log('tag count',$('.tag_labels').length);
$('#add_more_btn').before(' ')
}
question_plugins.foto.enable_select2 = function (element) {
var $customSelects = element;
$customSelects.select2({
width: '100%',
// closeOnSelect: false,
//
/**
* Adds needsclick class to all DOM elements in the Select2 results list
* so they can be accessible on iOS mobile when FastClick is initiated too.
*/
templateResult: function (result, container) {
if (!result.id) {
return result.text;
}
container.className += ' needsclick';
return result.text;
}
});
/**
* Additional to tweaking the templateResult option in Select2,
* add needsclick class to all DOM elements in the Select2 container,
* so they can be accessible on iOS mobile when FastClick is initiated too.
*
* More info about needsclick:
* https://github.com/ftlabs/fastclick#ignore-certain-elements-with-needsclick
*
*/
$customSelects.each(function (index, el) {
$(el).data('select2').$container.find('*').addClass('needsclick');
});
}
question_plugins.foto.browse_picture = function(id) {
if(app.electron.is_electron()){
app.electron.upload_photo(function(file){
var mime = "image/'png'";
$("[name='foto-0-" + id + "']").val(mime + "#" + file.link);
$("#btn_foto_vraag-" + id + ",#btn_gallery_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon,#btn_gallery_vraag-" + id + " i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
});
return;
}
if (typeof (navigator.camera) == "undefined") {
question_plugins.foto.simulate_take_picture(id);
return;
}
navigator.camera.getPicture(function (fileuri) {
var original_filename = fileuri.replace(/^.*[\\\/]/, '');
app.sender.insertFile(fileuri, function (file) {
navigator.camera.cleanup();
var mime = "";
if (file.extension == "jpg") mime = "image/jpeg";
if (file.extension == "png") mime = "image/png";
$("[name='foto-0-" + id + "']").val(mime + "#" + file.link);
$("#btn_foto_vraag-" + id + ",#btn_gallery_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon,#btn_gallery_vraag-" + id + " i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
}, function () { }, original_filename);
}, function () { },
{
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
targetWidth: 2048, targetHeight: 1536,
quality: 40, correctOrientation: true
});
}
question_plugins.foto.simulate_take_picture = function(id) {
$("#btn_foto_vraag-" + id + ",#btn_gallery_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon,#btn_gallery_vraag-" + id + " i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
var data_url='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
var blob=app.sender.dataurl_to_blob(data_url);
var filename=(new Date).getTime() + ".png";
filesystem.storeFile(filename, "", blob, function(){
app.sender.insertFile(filename, function(file){
var mime=data_url.split(";")[0].substring(5);
var mime = "image/jpeg";
$("#foto-0-" + id).val(mime + "#" + file.link);
},function(){},filename);
});
}
question_plugins.foto.take_picture = function(id) {
if(app.electron.is_electron()){
app.electron.upload_photo(function(file){
var mime = "image/'png'";
$("[name='foto-0-" + id + "']").val(mime + "#" + file.link);
$("#btn_foto_vraag-" + id + ",#btn_gallery_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon,#btn_gallery_vraag-" + id + " i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
});
return;
}
if (typeof (navigator.camera) == "undefined") {
question_plugins.foto.simulate_take_picture(id);
return;
}
app.loader.show(trans("loading"));
setTimeout(function () {
app.loader.hide();
}, 1000);
setTimeout(function () {
console.warn("taking picture");
navigator.camera.getPicture(function (fileuri) {
// filesystem.photodirectory.getFile(fileuri, {create:false}, function(file) {
var original_filename = fileuri.replace(/^.*[\\\/]/, '');
app.sender.insertFile(fileuri, function (file) {
navigator.camera.cleanup();//cleanup temp file.
if (typeof (cordova) !== "undefined" && typeof (StatusBar) !== "undefined") {
StatusBar.hide();
StatusBar.show();
}
var mime = "";
if (file.extension == "jpg") mime = "image/jpeg";
if (file.extension == "png") mime = "image/png";
$("[name='foto-0-" + id + "']").val(mime + "#" + file.link);
$("#btn_foto_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon").removeClass("mdi-camera").addClass("mdi-check");
}, function (err) {
console.warn(err);
}, original_filename);
}, function (err) {
console.error(err);
}, {
quality: 40, correctOrientation: true, destinationType: Camera.DestinationType.FILE_URI, targetWidth: 2048, targetHeight: 1536
});
}, 100);
}
var question_plugins = question_plugins || {};
question_plugins.grid_handsontable =
{
build: function(json,taal)
{
var work_array=load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var string_fixed = work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/ $(window).ready(function () { $(window).resize(function () { reset_grid(' + work_array.id + ') }); }); \<\/script\>';
var fullscreen_button =''+string_fixed+'Use fullscreen option to add or edit the grid
fullscreen ';
var buttons=' ';
var fake_header = '';//""+'';
var telefoon_fake_header_fix = '' ;
if (Object.keys(work_array.required).length) required_marked='' + trans('required') + ' ';
return "" +fake_header + telefoon_fake_header_fix+ required_marked + fullscreen_button+'
'+build_grid_table(work_array)+'
'+script_stuff + "
";
},
editor_build: function(json) //antwoorden_json
{
window.active = 'NL';hot=[];
parse_editor_json(json);
question_label_class_html =new_option_settings(true,false,false,'0.0',label,required,input_type,false,'',false,'',true,tag_value);
input='';
question_options_inputs = '\";
return_html = return_html + ""+search_html+" ";
return return_html;
},
editor_build: function(json) //antwoorden_json
{
parse_editor_json(json);
dropdown_wortel = 1;
question_label_class_html = new_option_settings(true,true,false,'0.0',label,required,'',false,'',false,'',true,tag_value)+' ';
//options_html =new_option_settings(true,false,false,'0.1',options['0.1'],'','');
//answers_options_inputs_button_html = "add new option "
extra_html = 'Make searchable ';
//extra_html = extra_html+'Import options from CSV file ';
//extra_html = extra_html+'Options import templateDownload ';
$.each(users, function(key, value)
{
var checked = '';
if(value.id in extra) checked = 'checked';
extra_html = extra_html+' '+value.name+' ';
});
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
extra_html //extra
);
$.each(options, function(key, value)
{
var res = key.toString().split(".")[0];
if(key!='0.1' && key!='0.0' ) {dropdown_wortel++;add_drop_item_with_import(value);}
});
if(extra)
{
if(extra['searchable']=='on')
{
$('[name=searchable]').prop('checked', true);
}
}
},
after_build: function(element,json)
{
if($(element).find('[data-logica_array]').data('logica_array') !='""')
{
if( app.survey.check_question_logic( $(element).find('[data-logica_array]').data('logica_array') ) )
{
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
var work_array = load_question_json(json);
app.survey.enable_select2($('[name=dropdown-0-' + work_array.id + ']'));
},
logica: function(json_array)
{
var current_response=get_specific_response(get_survey_id() );
//[{"1602":{"id":"1602","tab_id":0,"type":"dropdown_with_import","value":"1"},"not":false}]
var tab_id =json_array.tab_id;
if( $('#vraagwrapper_'+json_array.id+':visible').length == 0 && $('#vraagwrapper_'+json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if( $('[name=dropdown-0-'+json_array.id+']').val() == json_array.value ) return true; //eerst naar de actieve waarde kijken.
else if (!(tab_id in current_response)) return false;
else if($('[name=dropdown-0-'+json_array.id+']').length == 0 ) if( current_response[tab_id][json_array.id][0]['value'] == json_array.value ) return true; //daarna naar opgeslagen waarden kijken ALS het item niet actief is op de tab
return false;
},
get_value: function(id)
{
return { '0' : { 'value' : $('#dropdown-0-'+id).val(),
'type' : 'dropdown',
'raw_value':$('#dropdown-'+$('#dropdown-0-'+id).val()+'-'+id).html(),
'required' : ( $('#dropdown-0-'+id).data('required') =='1' ),
'hidden_by_logic' : ( $('#dropdown-0-'+id).parents('.hidden_by_logic').length == 1 )
}
};
},
validate: function(id,tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if( typeof current_response[tab_id] === 'undefined' )
{
error_array.push( { 'error' : 'ignored tab' } );
}
else
{
if( current_response[tab_id][id][0]['value'] ==null && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push( { 'error' : 'required' } );
}
return error_array;
}
};
function local_user_dropdown_editor(antwoorden_json) { return question_plugins.local_user_dropdown.editor_build(antwoorden_json); }
function local_user_dropdown_builder(json,taal) { return question_plugins.local_user_dropdown.build(json,taal); }
var question_plugins = question_plugins || {};
question_plugins.location_information =
{
build: function(json,taal)
{
var work_array=load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
console.warn("HEAEDER");
console.warn(work_array);
var string_fixed = work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + string_fixed + "" + work_array.extra['text_field_'+taal].replace(/\r/g, ' ')+ "
";
return qtext;
},
editor_build: function(json) //antwoorden_json
{
parse_editor_json(json);
question_label_class_html=new_option_settings(true,false,false,'0.0',label,'','');
extra_html = 'Extra text. html can be used. ';
$.each(talen,
function(i, v) {
extra_html = extra_html + '' + v.short_label + ': ';
});
extra_html = extra_html + '
';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
extra_html //extra
);
},
after_build: function(element,json)
{
if($(element).find('[data-logica_array]').data('logica_array') !='""')
{
if( app.survey.check_question_logic( $(element).find('[data-logica_array]').data('logica_array') ) )
{
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
},
logica: function(json_array)
{
return true;
},
get_value: function(id)
{
return false;
},
validate: function(id,tab_id) //test required
{
return '';
}
};
function location_information_editor(antwoorden_json) { return question_plugins.location_information.editor_build(antwoorden_json); }
function location_information_builder(json,taal) { return question_plugins.location_information.build(json,taal); }
var question_plugins = question_plugins || {};
question_plugins.location_meta =
{
build: function(json,taal)
{
var work_array=load_question_json(json);
var disabled = '';
var current_location_meta_raw = JSON.parse(app.get("checklists_index",'location')['meta']);
var current_location_meta = {};
$.each( current_location_meta_raw,function(key,item)
{
current_location_meta[ item['label'] ] = item['value'];
});
$.each( {"naam":"name","postal_code":"postal_code","city":"city","grp":"location_group"},function(key,item)
{
current_location_meta[ key ] = app.get("checklists_index",'location.'+item);
});
var current_response = get_current_response();
work_array['default_value'] = {};
//get_current_tab()
if (typeof current_response[get_current_tab()] !== 'undefined') {
if (work_array['id'] in current_response[get_current_tab()]) {
$.each( current_response[get_current_tab()][work_array['id']],function(key,item)
{
work_array['default_value'][ item['tags'].split('|')[1] ] = item['value'];
});
//work_array['default_value'] = current_response[get_current_tab()][work_array['id']];
}
}
console.log('work_array[\'default_value\']',work_array['default_value']);
current_location_meta[ 'address' ] = app.get("checklists_index",'location.street_name')+' '+app.get("checklists_index",'location.street_number')+app.get("checklists_index",'location.street_number_extension');
console.log('current_location_meta',current_location_meta);
taal = app.survey.determine_language(work_array,"label",taal);
var string_fixed = work_array['label'][taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + '';
var required_className = 'required';
}
var location_meta_hmtl = '';
if('general_view' in work_array['extra'] || 'general_edit' in work_array['extra']) location_meta_hmtl = 'Other location information ';
var i = 0;
var location_meta_temp = [];
// if(window.location_id in location_meta_data) location_meta_temp = location_meta_data[ window.location_id ];
// work_array['default_value'] = {};
console.log('work_array[\'extra\']',work_array['extra']);
//var location_general_info = get_location_by_id( window.location_id );
//if(location_general_info === null)
location_general_info ={};
$.each( work_array['extra'],function(key,item)
{
if( ["naam_options","address_options","postal_code_options","city_options","grp_options","quiz_correct"].indexOf(key) == -1 ) location_meta_temp = location_meta_temp.concat([{'id':key.split("_")[0],'label':key.split("_")[0],'type':'GLOBAL','input_type':'text'}]);
});
var location_meta_full = [{'id':'naam','label':'Name','type':'GENERAL','input_type':'text'},{'id':'address','label':'Address','type':'GENERAL','input_type':'text'},{'id':'postal_code','label':'Postal code','type':'GENERAL','input_type':'text'},{'id':'city','label':'City','type':'GENERAL','input_type':'text'},{'id':'grp','label':'Location group','type':'GENERAL','input_type':'text'}].concat(location_meta_temp);
console.log('location_meta_full',location_meta_full);
var last_type ='';
$.each(location_meta_full,function(index,item)
{
i ++;
var value = current_location_meta[ item['id'] ];
console.log('value=>',item['id'],current_location_meta,current_location_meta[ item['id'] ])
var disabled= '';
var readonly= '';
var input_type_text = 'text';
var mask_class = 'text';
// var global_location = '';
// if(item['id'] in location_meta_temp) value = location_meta_temp[ item['id'] ];
// else if (item['id'] in location_general_info) value = location_general_info[ item['id'] ];
// if(i in work_array['default_value']) value = work_array['default_value'][i]['value'];
// value = '';
if(item['id']+'_options' in work_array['extra'])
{
console.log('extra',work_array['extra'][ item['id']+'_options' ])
if(work_array['extra'][ item['id']+'_options' ] == '') return true; //skip
else if(work_array['extra'][ item['id']+'_options' ] == 'read_only') { readonly = ' read only '; disabled = "disabled";}
else if(work_array['extra'][ item['id']+'_options' ] == 'normal') console.log('jeeeej');
else if(work_array['extra'][ item['id']+'_options' ] == 'force_empty') { readonly = ' input forced empty ';value= '';}
}
else return true; //skip
if(item['id'] in work_array['default_value']) value = work_array['default_value'][ item['id'] ];
if( value == undefined) value = '';
if(last_type != item['type']) location_meta_hmtl = location_meta_hmtl + ""+item['type'].toUpperCase()+" LOCATION INFORMATION ";
last_type = item['type'];
if(item['input_type'] == 'text' || item['input_type'] == 'number')
{
location_meta_hmtl = location_meta_hmtl + ''+item['label']+readonly+'
';
}
else if(item['input_type'] == 'select')
{
location_meta_hmtl = location_meta_hmtl + ''+item['label']+readonly+' ;';
location_meta_hmtl = location_meta_hmtl + 'Select option ';
$.each(item['input_type_choices'].split("|"),function(index,item)
{
var selected ='';
if(value==item) selected= 'selected';
location_meta_hmtl = location_meta_hmtl + ''+item+' ';
});
location_meta_hmtl = location_meta_hmtl + '
';
}
});
// var location_general_info = get_location_by_id( window.location_id );
// if(location_general_info === null)
/* location_general_info ={};
var input_type_text = 'text';
var mask_class = 'text';
var global_location = '';
var value = '';
var disabled = '';
var readonly = '';*/
return ''+string_fixed + required_marked+' ' + location_meta_hmtl;
},
editor_build: function(json) //antwoorden_json
{
parse_editor_json(json);
var info_text = ' --uitleg--
';
var location_meta_hmtl = 'Label Meta type Settings ';
var location_meta_full = [{'label':'naam','type':'GENERAL'},{'label':'address','type':'GENERAL'},{'label':'postal_code','type':'GENERAL'},{'label':'city','type':'GENERAL'},{'label':'grp','type':'GENERAL'}].concat(location_meta);
$.each(location_meta_full,function(index,item)
{
var checked = {0:'checked',1:'',2:'',3:'' };
if(item['label']+'_options' in extra)
{
if(extra[ item['label']+'_options' ] == '') checked = {0:'checked',1:'',2:'',3:'' };
else if(extra[ item['label']+'_options' ] == 'read_only') checked = {0:'',1:'checked',2:'',3:'' };
else if(extra[ item['label']+'_options' ] == 'normal') checked = {0:'',1:'',2:'checked',3:'' };
else if(extra[ item['label']+'_options' ] == 'force_empty') checked = {0:'',1:'',2:'',3:'checked' };
}
location_meta_hmtl = location_meta_hmtl + ''+item['label']+' '+item['type']+' ';
location_meta_hmtl=location_meta_hmtl+''+
// 'Hide '+
'Read Only '+
'Normal '+
'Force Empty '+
' ';
});
location_meta_hmtl = location_meta_hmtl + '
';
question_label_class_html =new_option_settings(true,false,false,'0.0',label,required,input_type,false,default_value,false,placeholder['0.1'],true,tag_value);
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
info_text+location_meta_hmtl// extra_html //extra
);
},
after_build: function(element,json)
{
$(element).find('label').addClass('active');
console.log('element');
console.log(element);
console.log($(element).find('[data-logica_array]').data('logica_array'));
if($(element).find('[data-logica_array]').data('logica_array') !='""')
{
if( app.survey.check_question_logic( $(element).find('[data-logica_array]').data('logica_array') ) )
{
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
},
logica: function(json_array)
{
var current_response=get_specific_response(get_survey_id() );
var id =json_array.id;
var tab_id =json_array.tab_id;
var meta_type =json_array.operator_type;
var value =json_array.value;
if( $('#vraagwrapper_'+json_array.id+':visible').length == 0 && $('#vraagwrapper_'+json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if (typeof current_response[tab_id] != 'undefined' && $('#vraagwrapper_'+id).length == 0)
{
$.each(current_response[tab_id][id], function(key, sub_questions)
{
if(meta_type == sub_questions.tags) { value = sub_questions.value; return false;}
});
}
else if ( $('#vraagwrapper_'+id+' [data-tag="'+meta_type+'"]').val() == value ) return true;
else if ( $('#vraagwrapper_'+id+' [data-tag="'+meta_type+'"] option:selected').val() == value ) return true;
else return false;
},
get_value: function(id)
{
var sub_questions= $('.location_meta_'+id);
var return_array = {};
$.each(sub_questions, function(key, value)
{
return_array[$(value).data('sub_id')] = {
'value' : $(value).val(),
'type' : 'location_meta',
'tags' : $(value).data('tag'),
'required' : ( $(value).data('required') =='1' ),
'hidden_by_logic' : ( $(value).parents('.hidden_by_logic').length == 1 )
}
});
return return_array
},
validate: function(id,tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if( typeof current_response[tab_id] === 'undefined' )
{
error_array.push( { 'error' : 'ignored tab' } );
}
else
{
//if( current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push( { 'error' : 'required' } );
}
return error_array;
}
};
function location_meta_editor(antwoorden_json) { return question_plugins.location_meta.editor_build(antwoorden_json); }
function location_meta_builder(json,taal) { return question_plugins.location_meta.build(json,taal); }
var question_plugins = question_plugins || {};
question_plugins.location_pick =
{
build: function (json, taal) {
var work_array = load_question_json(json);
// load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var current_response = get_current_response();
var ids=[];var names=[];var idstring="";var namestring="";
if (get_current_tab() in current_response && work_array['id'] in current_response[get_current_tab()]) {
$.each(current_response[get_current_tab()][work_array['id']], function(i,response){
ids.push(response.value);
names.push(response.tag);
});
idstring=ids.join(",");
namestring=names.join(",");
}
/*if (typeof current_response[get_current_tab()] !== 'undefined') { //TODO: RESTORE VALUE
if (work_array['id'] in current_response[get_current_tab()]) {
work_array['default_value'][current_response[get_current_tab()][work_array['id']][0].value] = 'checked';
}
}*/
var multiple_locations="no";
if ('multiple_locations' in work_array.extra && work_array.extra['multiple_locations']==1) multiple_locations="yes";
var required_marked = '';
if (work_array['required'] == 1) {
required_marked = '' + trans('required') + ' ';
required_className = 'required';
}
var return_html = '' + string_fixed + required_marked + ' ';
return_html = return_html + '' + trans("select_a_choice") + ' ';
return_html = return_html + ' ';
return_html = return_html + ' ';
//value="'+work_array['default_value']+'"
//data-bounded_value="'+bounded_value+'"
//data-check_logica_on_change="'+work_array['logica_check_current_tab']+'" data-logica_array=\''+ JSON.stringify(work_array['logica_array'])+'\'
return return_html + '
';
},
editor_build: function(json) //antwoorden_json
{
parse_editor_json(json);
var multiple_locations = "";
if ('multiple_locations' in extra) multiple_locations = "checked";
extra_html = 'Allow selecting multiple locations ';
question_label_class_html=new_option_settings(true,false,false,'0.0',label,'','');
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
extra_html //extra
);
},
after_build: function (element,json) {
var work_array = load_question_json(json);
console.warn("EL");
console.warn(element);
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
$(element).find("button").on("click", function(){
var multiple=$(this).data("multiple");
if(multiple=="yes"){
//todo: hand existing as defaults.
app.location.pick(function(locations){
var names=[];var ids=[];
$.each(locations,function(i,location){
names.push(location.name);
ids.push(location.id);
});
$("#location_pick-0-" + work_array.id).val(names.join(","));
$("#location_pick-1-" + work_array.id).val(ids.join(","));
},function(){},{},"list");
} else {
app.location.pickSingle(function(locations){
var location=locations[0];
$("#location_pick-0-" + work_array.id).val(location.name);
$("#location_pick-1-" + work_array.id).val(location.id);
},function(){
},{},"list");
}
});
},
logica: function (json_array) {
var current_response=get_specific_response(get_survey_id() );
console.log(json_array);
console.log(!(tab_id in current_response));
var tab_id = json_array.tab_id;
if ($('#vraagwrapper_' + json_array.id + ':visible').length == 0 && $('#vraagwrapper_' + json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if ($('[name=radio_yesno-0-' + json_array.id + ']:checked').val() == json_array.value) return true; //eerst naar de actieve waarde kijken.
else if (!(tab_id in current_response)) return false;
else if ($('[name=radio_yesno-0-' + json_array.id + ']:checked').length == 0) if (current_response[tab_id][json_array.id][0]['value'] == json_array.value) return true; //daarna naar opgeslagen waarden kijken ALS het item niet actief is op de tab
return false;
},
get_value: function (id) {
var value = '';
if ($("#location_pick-0-" + id).val().split(",").length>0){
var names = $("#location_pick-0-" + id).val().split(",");
var ids = $("#location_pick-1-" + id).val().split(",");
var sets={};
$.each(names,function(i,name){
sets[i]= {
'value': ids[i],
'tag' : name,
'type': 'location_pick',
'required': ($('[name=location_pick-0-' + id + ']').data('required') == '1'),
'hidden_by_logic': ($('[name=location_pick-0-' + id + ']').parents('.hidden_by_logic').length == 1)
};
});
return sets;
}
return {
'0': {
'value': '',
'type': 'location_pick',
'required': ($('[name=location_pick-0-' + id + ']').data('required') == '1'),
'hidden_by_logic': ($('[name=location_pick-0-' + id + ']').parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
if (current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required' });
}
return error_array;
}
};
function location_pick_editor(antwoorden_json) { return question_plugins.location_pick.editor_build(antwoorden_json); }
function location_pick_builder(json, taal) { return question_plugins.location_pick.build(json, taal); }
var question_plugins = question_plugins || {};
question_plugins.meerkeuze =
{
meerkeuze_counter: 1,
build: function (json, taal) {
var work_array = load_question_json(json);
var required_string = '';
taal = app.survey.determine_language(work_array,"label",taal);
var string_fixed = work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + '';
var required_className = 'required';
}
if (work_array.required == '1') required_string = ' (minimum of ' + work_array.extra.min_antwoorden + ' answer(s) needed) ';
work_array['default_value'] = {};
var disabled_string=app.survey.is_disabled(app.survey.get_survey_id()) ? " disabled " : "";
/*if( typeof current_response[app.survey.view.get('active_tab')] !== 'undefined' )
{
if(work_array['id'] in current_response[app.survey.view.get('active_tab')])
{
work_array['default_value'] = current_response[ app.survey.view.get('active_tab')][ work_array['id'] ]
}
}*/
var current_response = get_current_response();
//get_current_tab()
if (typeof current_response[get_current_tab()] !== 'undefined') {
if (work_array['id'] in current_response[get_current_tab()]) {
work_array['default_value'] = current_response[get_current_tab()][work_array['id']];
}
}
//oud:
/*var return_html = string_fixed +required_string+ '' +required_marked;
$.each(work_array.options, function(key, value)
{
return_html = return_html +
'' + value[taal] + '
';
});
return_html = return_html +' ';
return return_html;
*/
//new
var return_html = '' + string_fixed + required_marked + ' ';
$.each(work_array.options, function (key, value) {
if (key === '0.0') return true;
var checked = '';
if (key.replace('0.', "") in work_array['default_value']) if (work_array['default_value'][key.replace('0.', "")].value == 1) checked = 'checked';
var quiz_correct_class = '';
var quiz_correct = '';
if (work_array.extra) {
if ('quiz_correct' in work_array.extra) {
if ('quiz_correct_' + key.replace('0.', "") in work_array.extra['quiz_correct']) {
quiz_correct = ' V ';
quiz_correct_class = 'correct ';
}
else quiz_correct = ' X ';
}
}
taal = app.survey.determine_language(work_array.options,key,taal);
string_fixed = value[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/ ' + string_fixed + ' ';
//werkt niet op IOS tijdelijk anders
/* return_html = return_html + ' ' + string_fixed + quiz_correct + '
';*/
//wordt nu:
/*
Default checkbox
*/
return_html = return_html + '
' + string_fixed + quiz_correct + '
';
//maar ooit terug zetten
});
return return_html;
},
editor_build: function (json) //antwoorden_json
{
question_plugins.meerkeuze.meerkeuze_counter = 1;
//extra ={'quiz_correct':{}};
parse_editor_json(json);
if (!('quiz_correct' in extra)) extra['quiz_correct'] = {};
question_label_class_html = new_option_settings(true, true, false, '0.0', label, required, '', false, '', false, '', true, tag_value) + '
';
options_html = new_option_settings(true, false, false, '0.1', options['0.1'], '', '', null, null, null, null, null, null, ('quiz_correct_1' in extra['quiz_correct']), true);
extra_html = '
';//'+extra.min_antwoorden+'
answers_options_inputs_button = '
Add new option';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
options_html, //answers_options_inputs
answers_options_inputs_button, //answers_options_inputs_button
extra_html //extra
);
$.each(options, function (key, value) {
var res = key.toString().split(".")[0];
console.log(res);
if (key != '0.1' && key != '0.0') {
question_plugins.meerkeuze.meerkeuze_counter++; create_new_meerkeuze_option(value, question_plugins.meerkeuze.meerkeuze_counter);
}
});
},
after_build: function (element,json) {
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
//$(element).find(".checkbox").bootstrapMaterialDesign();
$(element).find("input").off("click").on("click",function(){
$('.tappable-scroll-container:visible')[0].scrollTop+=1;
$('.tappable-scroll-container:visible')[0].scrollTop-=1;
});
},
logica: function (json_array) {
var current_response=get_specific_response(get_survey_id() );
var tab_id = json_array.tab_id;
if ($('#vraagwrapper_' + json_array.id + ':visible').length == 0 && $('#vraagwrapper_' + json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if ($('[name=meerkeuze-' + json_array.value + '-' + json_array.id + ']:checked').val() == json_array.value) return true; //eerst naar de actieve waarde kijken.
else if (!(tab_id in current_response)) return false;
else if (typeof current_response[tab_id] != 'undefined' && $('[name=meerkeuze-' + json_array.value + '-' + json_array.id + ']:checked').length == 0) if (current_response[tab_id][json_array.id][json_array.value]['value'] == 1) return true; //daarna naar opgeslagen waarden kijken ALS het item niet actief is op de tab
return false;
},
get_value: function (id) {
var sub_questions = $('.meerkeuze_' + id);
var return_array = {};
$.each(sub_questions, function (key, value) {
return_array[$(value).data('sub_id')] = {
'value': $(value).prop('checked') ? 1 : 0,
'type': 'meerkeuze',
'correct': $('[name=meerkeuze-' + $(value).data('sub_id') + '-' + id + '].correct:checked').length >> 0 ? 1 : 0,
'min_antwoorden': $(value).data('min_antwoorden'),
'min__correct_antwoorden': $('.meerkeuze_' + id + '.correct').length,
'aantal_antwoorden': $('.meerkeuze_' + id + ':checked').length,
'required': ($(value).data('required') == '1'),
'hidden_by_logic': ($(value).parents('.hidden_by_logic').length == 1)
}
});
return return_array
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if (tab_id in current_response) {
if (!(current_response[tab_id][id][1]['aantal_antwoorden'] >= current_response[tab_id][id][1]['min_antwoorden']) && current_response[tab_id][id][1]['required'] && !current_response[tab_id][id][1]['hidden_by_logic']) error_array.push({ 'error': 'required' });
}
else {
error_array.push({ 'error': 'ignored tab' });
}
return error_array;
}
};
function meerkeuze_editor(antwoorden_json) { return question_plugins.meerkeuze.editor_build(antwoorden_json); }
function meerkeuze_builder(json, taal) { return question_plugins.meerkeuze.build(json, taal); }
function create_new_meerkeuze_option(label, meerkeuze_wortel) {
if (typeof (label) == "undefined") label = '';
$(".answers_options_inputs").append(new_option_settings(true, false, false, '0.' + meerkeuze_wortel, label, '', '', null, null, null, null, null, null, ('quiz_correct_' + meerkeuze_wortel in extra['quiz_correct']), true));
$(".question_label_class").append('
');
$('.answers_options_inputs').append('
');
}
var question_plugins = question_plugins || {};
question_plugins.multi_radio =
{
build: function (json, taal) {
var work_array = load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var required_marked = '';
if (work_array.required == 1) {
required_marked = '
' + trans('required') + ' ';
var required_className = 'required';
}
/* if( typeof current_response[app.survey.view.get('active_tab')] !== 'undefined' )
{
if(work_array['id'] in current_response[app.survey.view.get('active_tab')])
{
work_array['default_value'] = current_response[app.survey.view.get('active_tab')][ work_array['id'] ][0].value;
}
}*/
var current_response = get_current_response();
//get_current_tab()
if (typeof current_response[get_current_tab()] !== 'undefined') {
if (work_array['id'] in current_response[get_current_tab()]) {
work_array['default_value'] = current_response[get_current_tab()][work_array['id']][0].value;
}
}
var string_fixed = work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/';
$.each(work_array.options, function(key, value)
{
string_fixed= value[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/
';
});
return_html=return_html+'
';
return return_html;*/
//new
var return_html = '
' + string_fixed + required_marked + ' ';
$.each(work_array.options, function (key, value) {
var checked = '';
if (key.replace('0.', "") == work_array['default_value']) checked = 'checked';
var quiz_correct_class = '';
var quiz_correct = '';
if (work_array.extra) {
if ('quiz_correct' in work_array.extra) {
if ('quiz_correct_' + key.replace('0.', "") in work_array.extra['quiz_correct']) {
quiz_correct = ' V ';
quiz_correct_class = 'correct ';
}
else quiz_correct = ' X ';
}
}
taal = app.survey.determine_language(work_array.options,key,taal);
string_fixed = value[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/ ' + string_fixed + quiz_correct + '
';
});
return return_html + '
';
},
editor_build: function (json) //antwoorden_json
{
option_count = 1;
parse_editor_json(json);
question_label_class_html = new_option_settings(true, true, false, '0.0', label, required, '', false, '', false, '', false, tag_value) + ' ' + ' ';
if (!('quiz_correct' in extra)) extra['quiz_correct'] = {};
options_html = new_option_settings(true, false, false, '0.1', options['0.1'], '', '', null, null, null, null, null, null, ('quiz_correct_1' in extra['quiz_correct']), false);
answers_options_inputs_button_html = ' Add new option ';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
options_html, //answers_options_inputs
answers_options_inputs_button_html, //answers_options_inputs_button
'' //extra
);
$.each(options, function (key, value) {
var res = key.toString().split(".")[0];
if (key != '0.1' && key != '0.0') { option_count++; create_new_radio_option(value); }
});
},
after_build: function (element,json) {
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
$(element).find(".radio").bootstrapMaterialDesign();
$(element).find(".bmd-radio").addClass("needsclick");
},
logica: function (json_array) {
var current_response=get_specific_response(get_survey_id() );
//[{"1609":{"id":"1609","tab_id":"0","type":"multi_radio","value":"1"},"not":false}]
console.log(json_array);
var tab_id = json_array.tab_id;
if ($('#vraagwrapper_' + json_array.id + ':visible').length == 0 && $('#vraagwrapper_' + json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if ($('[name=multi_radio-0-' + json_array.id + ']:checked').val() == json_array.value) return true; //eerst naar de actieve waarde kijken.
else if (!(tab_id in current_response)) return false;
else if (typeof current_response[tab_id] != 'undefined' && $('[name=multi_radio-0-' + json_array.id + ']:checked').length == 0) if (current_response[tab_id][json_array.id][0]['value'] == json_array.value) return true; //daarna naar opgeslagen waarden kijken ALS het item niet actief is op de tab
return false;
},
get_value: function (id) {
return {
'0': {
'value': $('[name=multi_radio-0-' + id + ']:checked').val(),
'type': 'multi_radio',
'correct': $('[name=multi_radio-0-' + id + '].correct:checked').length >> 0 ? 1 : 0,
'tags': $('[name=multi_radio-0-' + id + '].correct:checked').length >> 0 ? 'goed' : 'fout',
'required': ($('[name=multi_radio-0-' + id + ']').data('required') == '1'),
'hidden_by_logic': ($('[name=multi_radio-0-' + id + ']').parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
if (typeof current_response[tab_id][id][0]['value'] == 'undefined' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required' });
}
return error_array;
}
};
function multi_radio_editor(antwoorden_json) { return question_plugins.multi_radio.editor_build(antwoorden_json); }
function multi_radio_builder(json, taal) { return question_plugins.multi_radio.build(json, taal); }
function create_new_radio_option(label) {
if (typeof (label) == "undefined") label = '';
$(".answers_options_inputs").append(new_option_settings(true, false, false, '0.' + option_count, label, '', '', null, null, null, null, null, null, ('quiz_correct_' + option_count in extra['quiz_correct']), false));
$('.answers_options_inputs').append(' ');
}
/*
Green
*/
var question_plugins = question_plugins || {};
question_plugins.open_planogram =
{
build: function (json, taal) {
var work_array = load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var required_marked = '' + trans('required') + ' ';
var required_className = 'required';
var disabled_string=app.survey.is_disabled(app.survey.get_survey_id()) ? " disabled " : "";
var current_response = get_current_response();
if( typeof current_response[get_current_tab()] !== 'undefined' )
{
if(work_array['id'] in current_response[get_current_tab()])
{
work_array['default_value'] = current_response[get_current_tab()][ work_array['id'] ][0].value;
}
}
if((!app.get("checklists_index",'location.meta'))) return 'Select planogram Warning: No location selected. No planogram available.
';
var meta_raw = JSON.parse( app.get("checklists_index",'location.meta') );
var meta = {};
$.each(meta_raw, function (key, value) {
meta[value.id] = value;
});
var return_html = 'Select planogram' + required_marked + ' ';
return_html = return_html + '';
return_html = return_html + '
';
if(work_array['default_value'] =='') selected = "selected"; else selected = '';
return_html = return_html + 'select category ';
// if(work_array['default_value'] =='promo') selected = "selected"; else selected = '';
// return_html = return_html + 'Promotion ';
$.each(meta, function (key, value) {
if( value['input_type'] == 'planogram_id' ) {
if(work_array['default_value'] ==value['label']) selected = "selected"; else selected = '';
return_html = return_html + ''+value['label']+' ';
}
});
/*
if(28 in meta || 29 in meta|| 30 in meta|| 31 in meta) {
if(work_array['default_value'] =='zoetwaren_impuls') selected = "selected"; else selected = '';
return_html = return_html + 'zoetwaren impuls ';
}
if(32 in meta) {
if(work_array['default_value'] =='ijs') selected = "selected"; else selected = '';
return_html = return_html + 'ijs ';
}
if(33 in meta) {
if(work_array['default_value'] =='nab') selected = "selected"; else selected = '';
return_html = return_html + 'nab ';
}
if(34 in meta || 35 in meta) {
if(work_array['default_value'] =='flc') selected = "selected"; else selected = '';
return_html = return_html + 'flc ';
}
if(56 in meta || 57 in meta) {
if(work_array['default_value'] =='koek_banket') selected = "selected"; else selected = '';
return_html = return_html + 'koek banket ';
}
if(58 in meta) {
if(work_array['default_value'] =='zoetwaren_drop') selected = "selected"; else selected = '';
return_html = return_html + 'zoetwaren drop ';
}
if(59 in meta) {
if(work_array['default_value'] =='zoetwaren_snoep') selected = "selected"; else selected = '';
return_html = return_html + 'zoetwaren snoep ';
}
if(60 in meta) {
if(work_array['default_value'] =='zoetwaren_chocolade') selected = "selected"; else selected = '';
return_html = return_html + 'zoetwaren chocolade ';
}
if(61 in meta) {
if(work_array['default_value'] =='zoetwaren_gifting') selected = "selected"; else selected = '';
return_html = return_html + 'zoetwaren gifting ';
}
if(62 in meta) {
if(work_array['default_value'] =='freshkoelers') selected = "selected"; else selected = '';
return_html = return_html + 'freshkoelers ';
}
if(63 in meta) {
if(work_array['default_value'] =='incaps_bakery') selected = "selected"; else selected = '';
return_html = return_html + 'incaps bakery ';
}
if(64 in meta) {
if(work_array['default_value'] =='manden') selected = "selected"; else selected = '';
return_html = return_html + 'manden ';
}
if(65 in meta || 66 in meta) {
if(work_array['default_value'] =='bunkers') selected = "selected"; else selected = '';
return_html = return_html + 'bunkers ';
}
if(67 in meta) {
if(work_array['default_value'] =='incap_kassa') selected = "selected"; else selected = '';
return_html = return_html + 'incap kassa ';
}
if(74 in meta) {
if(work_array['default_value'] =='nab_koeler_combi') selected = "selected"; else selected = '';
return_html = return_html + 'nab koeler combi ';
}
if(75 in meta) {
if(work_array['default_value'] =='zoetwaren_dropsnoep') selected = "selected"; else selected = '';
return_html = return_html + 'zoetwaren dropsnoep ';
}
if(76 in meta) {
if(work_array['default_value'] =='zoetwaren_overig') selected = "selected"; else selected = '';
return_html = return_html + 'zoetwaren overig ';
}
*/
return_html = return_html + ' ';
return_html = return_html + '
';
return_html = return_html + '
';
$.each(meta, function (key, value) {
if( value['input_type'] == 'planogram_id' ) {
return_html = return_html + '
Planogram '+ value.label+'
';
}
});/*
//zoetwarenhttps://reporting.hamiltonbright.com/uploaded-files/planogram/'+meta[34].value+'.pdf
if(28 in meta) return_html = return_html + '
Planogram 1
';
if(29 in meta) return_html = return_html + '
Planogram 2
';
if(30 in meta) return_html = return_html + '
Planogram 3
';
if(31 in meta) return_html = return_html + '
Planogram 4
';
//ijs
if(32 in meta) return_html = return_html + '
Planogram 1
';
//nab
if(33 in meta) return_html = return_html + '
Planogram 1
';
//promo
/// if(43 in meta) return_html = return_html + '
Promotion 1
';
//flc
if(34 in meta) return_html = return_html + '
Planogram 1
';
if(35 in meta) return_html = return_html + '
Planogram 2
';
//nieuwe
//koek_banket
if(56 in meta) return_html = return_html + '
Planogram 1
';
if(57 in meta) return_html = return_html + '
Planogram 2
';
//andere
if(58 in meta) return_html = return_html + '
Planogram 1
';
if(59 in meta) return_html = return_html + '
Planogram 1
';
if(60 in meta) return_html = return_html + '
Planogram 1
';
if(61 in meta) return_html = return_html + '
Planogram 1
';
if(62 in meta) return_html = return_html + '
Planogram 1
';
if(63 in meta) return_html = return_html + '
Planogram 1
';
if(64 in meta) return_html = return_html + '
Planogram 1
';
//bunkers
if(65 in meta) return_html = return_html + '
Planogram 1
';
if(66 in meta) return_html = return_html + '
Planogram 2
';
//iets
if(67 in meta) return_html = return_html + '
Planogram 1
';
if(74 in meta) return_html = return_html + '
Planogram 1
';
if(75 in meta) return_html = return_html + '
Planogram 1
';
//iets
if(76 in meta) return_html = return_html + '
Planogram 1
';
*/
return return_html + '
';
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json); //parse antwoorden in 4 jsons:
load_editor_fields
(
'', //question_label_class
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
'' //extra
);
},
after_build: function (element,json) {
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
var val = $(element).find(".open_planogram").val();
if(val)
{
$('.planogram_btn').hide();
$('.' + val ).show();
}
},
logica: function (json_array) {
return true;
},
get_value: function (id) {
return {
'0': {
'value': $('#open_planogram-0-' + id).val(),
'type': 'open_planogram',
'raw_value': $('#open_planogram-' + $('#open_planogram-0-' + id).val() + '-' + id).html(),
'required': ($('#open_planogram-0-' + id).data('required') == '1'),
'hidden_by_logic': ($('#open_planogram-0-' + id).parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
return '';
}
};
function open_planogram_editor(antwoorden_json) { return question_plugins.open_planogram.editor_build(antwoorden_json); }
function open_planogram_builder(json, taal) { return question_plugins.open_planogram.build(json, taal); }
var question_plugins = question_plugins || {};
question_plugins.open_promotion =
{
build: function (json, taal) {
var work_array = app.survey.load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var required_marked = '' + trans('required') + ' ';
var required_className = 'required';
var disabled_string=app.survey.is_disabled(app.survey.get_survey_id()) ? " disabled " : "";
var current_response = app.survey.get_current_response();
if( typeof current_response[app.survey.get_current_tab()] !== 'undefined' )
{
if(work_array['id'] in current_response[app.survey.get_current_tab()])
{
work_array['default_value'] = current_response[app.survey.get_current_tab()][ work_array['id'] ][0].value;
}
}
if((!app.get("checklists_index",'location.meta'))) return 'Select planogram Warning: No location selected. No planogram available.
';
var meta_raw = JSON.parse( app.get("checklists_index",'location.meta') );
var meta = {};
$.each(meta_raw, function (key, value) {
meta[value.id] = value;
});
var return_html = 'Select planogram' + required_marked + ' ';
return_html = return_html + '';
return_html = return_html + '
';
// if(work_array['default_value'] =='') selected = "selected"; else selected = '';
// return_html = return_html + 'select categort ';
//if(work_array['default_value'] =='promo') selected = "selected"; else selected = '';
// selected = "selected";
$.each(meta, function (key, value) {
if( value['input_type'] == 'promotion_id' ) {
if(work_array['default_value'] ==value['label']) selected = "selected"; else selected = '';
return_html = return_html + ''+value['label']+' ';
}
});
// return_html = return_html + 'Promotion ';
// if(work_array['default_value'] =='zoetwaren_impuls') selected = "selected"; else selected = '';
// return_html = return_html + 'zoetwaren impuls ';
// if(work_array['default_value'] =='ijs') selected = "selected"; else selected = '';
// return_html = return_html + 'ijs ';
//if(work_array['default_value'] =='nab') selected = "selected"; else selected = '';
// return_html = return_html + 'nab ';
//// if(work_array['default_value'] =='flc') selected = "selected"; else selected = '';
// return_html = return_html + 'flc ';
return_html = return_html + ' ';
return_html = return_html + '
';
return_html = return_html + '
';
//zoetwarenhttps://reporting.hamiltonbright.com/uploaded-files/planogram/'+meta[34].value+'.pdf
// if(28 in meta) return_html = return_html + '
Planogram 1
';
// if(29 in meta) return_html = return_html + '
Planogram 2
';
// if(30 in meta) return_html = return_html + '
Planogram 3
';
// if(31 in meta) return_html = return_html + '
Planogram 4
';
//ijs
// if(32 in meta) return_html = return_html + '
Planogram 1
';
//nab
// if(33 in meta) return_html = return_html + '
Planogram 1
';
//promo
// if(43 in meta) return_html = return_html + '
Promotion 1
';
$.each(meta, function (key, value) {
if( value['input_type'] == 'promotion_id' ) {
return_html = return_html + '
Planogram '+ value.label+'
';
}
});
//flc
//if(34 in meta) return_html = return_html + '
Planogram 1
';
// if(35 in meta) return_html = return_html + '
Planogram 2
';
return return_html + '
';
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json); //parse antwoorden in 4 jsons:
load_editor_fields
(
'', //question_label_class
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
'' //extra
);
},
after_build: function (element,json) {
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
var val = $(element).find(".open_planogram").val();
if(val)
{
$('.planogram_btn').hide();
$('.' + val ).show();
}
},
logica: function (json_array) {
return true;
},
get_value: function (id) {
return {
'0': {
'value': $('#open_planogram-0-' + id).val(),
'type': 'open_planogram',
'raw_value': $('#open_planogram-' + $('#open_planogram-0-' + id).val() + '-' + id).html(),
'required': ($('#open_planogram-0-' + id).data('required') == '1'),
'hidden_by_logic': ($('#open_planogram-0-' + id).parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
return '';
}
};
function open_planogram_editor(antwoorden_json) { return question_plugins.open_planogram.editor_build(antwoorden_json); }
function open_planogram_builder(json, taal) { return question_plugins.open_planogram.build(json, taal); }
var question_plugins = question_plugins || {};
question_plugins.photo_with_timestamp = {
build: function(json, taal) {
var is_electron = window && window.process && window.process.type;
var work_array = load_question_json(json);
taal = app.survey.determine_language(work_array, "label", taal);
//prepare html strings
var string_fixed = work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + '';
var current_response = get_current_response();
var disabled_string = app.survey.is_disabled(app.survey.get_survey_id()) ? " disabled " : "";
if (typeof current_response[app.survey.get_current_tab()] !== 'undefined') {
if (work_array['id'] in current_response[app.survey.get_current_tab()] && current_response[get_current_tab()][work_array.id].length>0) {
work_array['default_value'] = current_response[app.survey.get_current_tab()][work_array['id']][0].value;
}
}
var storage_html = ' ';
if (!(work_array.extra == "")) {
if (!('no_storage' in work_array.extra) || is_electron)
storage_html = ' ';
}
var return_html = string_fixed + required_marked + storage_html + ' ';
if (work_array.extra['photo_tags'] == 'on') {
var dropdown_tags = 'Select a tag: Select a tag ';
$.each(work_array.extra, function(i, v) {
if (i == 'photo_tags') return false;
if (i == 'photo_clients_tags') return false;
dropdown_tags = dropdown_tags + '' + v + ' ';
});
dropdown_tags = dropdown_tags + '
';
return_html = return_html + dropdown_tags;
} else if (work_array.extra['photo_clients_tags'] == 'on') {
var dropdown_tags = 'Select a client ';
tag_id = work_array.id;
api_request('client_users', "get", {}, function(data) {
$.each(data, function(i, v) {
dropdown_tags = dropdown_tags + '' + v['full_name'] + ' ';
});
$('#vraagveld_' + tag_id + ' select[name=foto_tag-0-' + tag_id + ']').html(dropdown_tags);
});
var client_select = 'Select a client: Select a client ';
$.each(work_array.extra, function(i, v) {
if (i == 'photo_tags') return false;
if (i == 'photo_clients_tags') return false;
client_select = client_select + '' + v + ' ';
});
client_select = client_select + '
';
return_html = return_html + client_select;
}
return return_html;
},
editor_build: function(json) //antwoorden_json
{
parse_editor_json(json);
question_label_class_html = new_option_settings(true, true, false, '0.0', label, required, '') + ' ';
no_storage_checked = "";
if ('no_storage' in extra) no_storage_checked = "checked";
extra_html = 'Do not allow photo\'s from storage ';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
extra_html //extra
);
$('.tags_option').hide();
if (extra) {
if (extra['photo_tags'] == 'on') {
$('.tags_option').show();
$('[name=photo_tags]').prop('checked', true);
$.each(extra, function(key, value) {
if (key == 'photo_tags') return false;
else if (key == 1) $('[name=' + key + ']').val(value);
else {
add_more_tags(value);
}
});
}
if (extra['photo_clients_tags'] == 'on') {
$('[name=photo_clients_tags]').prop('checked', true);
}
}
},
after_build: function(element, json) {
if (element.find(".photo-value").val() !== "") {
element.find(".photo-button").addClass("photo_taken");
element.find("i.camera-icon").removeClass("mdi-camera").addClass("mdi-check");
}
$(element).find(".gallery-button").on("click", function() {
question_plugins.photo_with_timestamp.browse_picture($(this).data("id"));
});
$(element).find(".photo-button").on("click", function() {
question_plugins.photo_with_timestamp.take_picture($(this).data("id"));
});
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
} else $(element).addClass('hidden_by_logic');
} else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
var id = $(element).find(".foto_tag").data('question_id');
var tab_id = app.survey.get_current_tab();
var current_response = app.survey.get_current_response();
if (tab_id in current_response) {
if ($(element).find(".foto_tag").length) $(element).find(".foto_tag").val(current_response[tab_id][id][0].tags);
}
var work_array = load_question_json(json);
app.survey.enable_select2($(element).find("select"));
},
logica: function(json_array) {
return true;
},
get_value: function(id) {
return {
'0': {
'value': $("#foto-0-" + id).val(),
'type': 'foto',
'required': ($('#foto-0-' + id).data('required') == '1'),
'tags': moment().format("YYYY-MM-DD HH:mm:ss"),//Math.floor(Date.now() / 1000),
'tag': $("[name='foto_tag-0-" + id + "']").val(),
'hidden_by_logic': ($('#foto-0-' + id).parents('.hidden_by_logic').length == 1)
}
};
},
validate: function(id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response = get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({
'error': 'ignored tab'
});
} else {
if (current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({
'error': 'required'
});
}
return error_array;
}
};
question_plugins.photo_with_timestamp.take_picture = function(id) {
if (app.electron.is_electron()) {
app.electron.upload_photo(function(file) {
var mime = "image/'png'";
$("[name='foto-0-" + id + "']").val(mime + "#" + file.link);
$("#btn_foto_vraag-" + id + ",#btn_gallery_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon,#btn_gallery_vraag-" + id + " i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
});
return;
}
if (typeof(navigator.camera) == "undefined") {
question_plugins.photo_with_timestamp.simulate_take_picture(id);
return;
}
app.loader.show(trans("loading"));
setTimeout(function() {
app.loader.hide();
}, 1000);
setTimeout(function() {
console.warn("taking picture");
navigator.camera.getPicture(function(fileuri) {
var original_filename = fileuri.replace(/^.*[\\\/]/, '');
app.sender.insertFile(fileuri, function(file) {
navigator.camera.cleanup(); //cleanup temp file.
if (typeof(cordova) !== "undefined" && typeof(StatusBar) !== "undefined") {
StatusBar.hide();
StatusBar.show();
}
var mime = "";
if (file.extension == "jpg") mime = "image/jpeg";
if (file.extension == "png") mime = "image/png";
$("[name='foto-0-" + id + "']").val(mime + "#" + file.link);
$("#btn_foto_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon").removeClass("mdi-camera").addClass("mdi-check");
}, function(err) {
console.warn(err);
}, original_filename);
}, function(err) {
console.error(err);
}, {
quality: 40,
correctOrientation: true,
destinationType: Camera.DestinationType.FILE_URI,
targetWidth: 2048,
targetHeight: 1536
});
}, 100);
}
question_plugins.photo_with_timestamp.simulate_take_picture = function(id) {
$("#btn_foto_vraag-" + id + ",#btn_gallery_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon,#btn_gallery_vraag-" + id + " i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
var data_url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
var blob = app.sender.dataurl_to_blob(data_url);
var filename = (new Date).getTime() + ".png";
filesystem.storeFile(filename, "", blob, function() {
app.sender.insertFile(filename, function(file) {
var mime = data_url.split(";")[0].substring(5);
var mime = "image/jpeg";
$("#foto-0-" + id).val(mime + "#" + file.link);
}, function() {}, filename);
});
}
question_plugins.photo_with_timestamp.browse_picture = function(id) {
if (app.electron.is_electron()) {
app.electron.upload_photo(function(file) {
var mime = "image/'png'";
$("[name='foto-0-" + id + "']").val(mime + "#" + file.link);
$("#btn_foto_vraag-" + id + ",#btn_gallery_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon,#btn_gallery_vraag-" + id + " i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
});
return;
}
if (typeof(navigator.camera) == "undefined") {
question_plugins.photo_with_timestamp.simulate_take_picture(id);
return;
}
navigator.camera.getPicture(function(fileuri) {
var original_filename = fileuri.replace(/^.*[\\\/]/, '');
app.sender.insertFile(fileuri, function(file) {
navigator.camera.cleanup();
var mime = "";
if (file.extension == "jpg") mime = "image/jpeg";
if (file.extension == "png") mime = "image/png";
$("[name='foto-0-" + id + "']").val(mime + "#" + file.link);
$("#btn_foto_vraag-" + id + ",#btn_gallery_vraag-" + id).addClass("photo_taken");
$("#btn_foto_vraag-" + id + " i.camera-icon,#btn_gallery_vraag-" + id + " i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
}, function() {}, original_filename);
}, function() {}, {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
targetWidth: 2048,
targetHeight: 1536,
quality: 40,
correctOrientation: true
});
}
function photo_with_timestamp_editor(antwoorden_json) {
return question_plugins.photo_with_timestamp.editor_build(antwoorden_json);
}
function photo_with_timestamp_builder(json, taal) {
return question_plugins.photo_with_timestamp.build(json, taal);
}
var question_plugins = question_plugins || {};
question_plugins.plannings_information =
{
build: function (json, taal) {
var work_array = load_question_json(json);
console.warn(work_array);
taal = app.survey.determine_language(work_array, "label", taal);
console.warn("extra_description");
console.warn(work_array);
var string_fixed = work_array.label !== "" ? work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + string_fixed + "";
return qtext;
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json);
question_label_class_html = new_option_settings(true, false, false, '0.0', label, '', '');
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
'' //extra
);
},
after_build: function (element, json) {
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
var plannings_id = app.get("checklists_index", "visit.plannings_id");
database.query("SELECT * FROM planning WHERE id = ?", [plannings_id], function (result) {
var plan_item = result.rows.item(0);
try {
var extra_description = JSON.parse(plan_item.extra_description);
$.each(extra_description, function (variable, value) {
$(element).find(".question-plannings_information-body").append("" + variable + " " + value + "");
});
} catch (e) {
}
});
},
logica: function (json_array) {
return true;
},
get_value: function (id) {
return false;
},
validate: function (id, tab_id) //test required
{
return '';
}
};
function plannings_information_editor(antwoorden_json) { return question_plugins.plannings_information.editor_build(antwoorden_json); }
function plannings_information_builder(json, taal) { return question_plugins.plannings_information.build(json, taal); }
var question_plugins = question_plugins || {};
var product_grid = {};
question_plugins.product_grid =
{
build: function (json, taal) {
console.log('product_grid start');
console.log(json);
var work_array = load_question_json(json);
taal = app.survey.determine_language(work_array, "label", taal);
var string_fixed = work_array['label'][taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + '';
var required_className = 'required';
}
bounded = "";
bounded_value = "";
default_value = '';
product_grid[work_array['id']] = JSON.parse(work_array['extra']['extra_data']);
console.log('product_grid');
console.log(product_grid);
return '' + string_fixed + bounded + required_marked + ' ';
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json);
console.log('json');
console.log(json);
question_label_class_html = question_options({
'label': true,
'label_value': label,
'required': true,
'required_value': required,
'input_type': false,
'sub_id': '0.0'
});
var extra_data = '';
if (typeof extra['extra_data'] !== 'undefined') extra_data = extra['extra_data'];
var button_productlist = 'edit productlist ';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
'edit grid ' + button_productlist// extra_html //extra
);
//$('body').append('');
// $('.the_final_grid_fullscreen').html('save & exit ');
},
after_build: function (element, json) {
var question_id = element.attr('id').split("_")[1];
var current_response = get_current_response();
//$(element).find('label').addClass('active');
console.log('element');
console.log(element);
console.log($(element).find('[data-logica_array]').data('logica_array'));
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
start_the_final_grid(question_id);
console.log('current_response');
console.log(current_response);
if (typeof current_response[app.survey.get_current_tab()] !== 'undefined') {
$.each(current_response[app.survey.get_current_tab()][question_id], function (key, sub_question_array) {
console.log('sub_question_array');
console.log(sub_question_array);
var cc = $('#vraagwrapper_' + question_id + ' td[data-sub_question_id="' + key + '"] ');
var newval = sub_question_array.value;
var question_type = sub_question_array.type.split('|')[1];
if (question_type == 'boolean' || question_type == 'canon_boolean') {
// var newval = $( "#modaltext [name=gridinput]:checked" ).val();
if (newval == '1') cc.find('span.val').html('Yes');
else if (newval == '0') cc.find('span.val').html('No');
else if (newval == '' && question_type == 'canon_boolean') cc.find('span.val').html('n/a');
}
else cc.find('span.val').html(newval);
cc.find('input.the_final_grid_input').val(newval);
});
}
// Add min-width to the Grid question th's so the columns are not cramped up
var tableHead = $('.the_final_grid_return_wrapper table tr:first-child th');
$.each(tableHead, function(index ,value) {
if ($(this).text().length > 20) {
$(this).css('min-width', '150px');
}
});
grid_logica(question_id);
},
logica: function (json_array) {
return true;
// console.warn(json_array);
var id = json_array.id;
var tab_id = json_array.tab_id;
var operator_type = json_array.operator_type ? json_array.operator_type : json_array.operators;
var value = json_array.value;
},
get_value: function (id) {
var return_array = {};
$('input.the_final_grid_input_' + id).each(function (index, obj) {
var sub_question_id = $(obj).parent().data('sub_question_id');
var type = 'the_final_grid|' + $(obj).parent().data('question_type');
var required = $(obj).parent().hasClass('required') ? 1 : 0;
var value = $('.the_final_grid_' + id + '_' + sub_question_id).val();
//var value ='';//$('[name="grid_handsontable-'+i+'-'+id+'"]').val()
if (sub_question_id) {
return_array[sub_question_id] = {
'value': value ? value : null,
'type': type,
'bounded_value': false,
'required': required,
'hidden_by_logic': ($('#grid_handsontable-0-' + id).parents('.hidden_by_logic').length == 1)
};
}
});
return return_array;
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response = get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
//var sub_questions = $('.the_final_grid_input_'+id);
// console.log('sub_questions=>'+sub_questions);
$.each(current_response[tab_id][id], function (index, sub_question) {
if ((sub_question['value'] == '' || sub_question['value'] == null) && sub_question['required'] == 1 && !sub_question['hidden_by_logic']) {
error_array.push({ 'error': 'required' });
return false;
}
});
}
console.log(id);
console.log(error_array);
return error_array;
}
};
function product_grid_editor(antwoorden_json) { return question_plugins.product_grid.editor_build(antwoorden_json); }
function product_grid_builder(json, taal) { return question_plugins.product_grid.build(json, taal); }
var question_plugins = question_plugins || {};
question_plugins.product_switch =
{
dropdown_regel: function (id,product,product_advice)
{
console.log('dropdown_regel->'+id);
if(product) selected=''; else selected='selected';
list = 'Search in product ';
brand = {};
$.each(products,function(index,item)
{
if(item['id'] == product) selected='selected'; else selected='';
list = list +'' + item['label'] + ' ';
brand[item['products_group_id']] = item['products_group_label'];
});
list = list + ' ';
if(product_advice) selected=''; else selected='selected';
list_2 = 'Search in products ';
$.each(products,function(index,item)
{
if(item['id'] == product_advice) selected='selected'; else selected='';
list_2 = list_2 +'' + item['label'] + ' ';
});
list_2 = list_2 + ' ';
brand_list = 'Search in brands ';
$.each(brand,function(index,item)
{
brand_list = brand_list +'' +item + ' ';
});
brand_list = brand_list + ' ';
return ''+brand_list+list+' suggest product '+brand_list+list_2+' X ';
},
dropdown_regel_app: function (id,product,product_advice,work_array)
{
brand = {};
var list = '';
list = list + question_plugins.product_switch.dropdown_regel_app_from_list(id,product,product_advice,work_array,'') + ' ';
if(product_advice) selected=''; else selected='selected';
var list_2 = 'Search in products ';
$.each(products,function(index,item)
{
if(item['id'] == product) selected='selected'; else selected='';
list_2 = list_2 +'' + item['products_group_label']+' '+ item['label'] + ' ';
});
list_2 = list_2 + ' ';
var brand_list = 'Search in brands ';
// brand = {};
$.each(brand,function(index,item)
{
brand_list = brand_list +'' +item + ' ';
});
brand_list = brand_list + ' ';
return ''+brand_list+list+' Advice: Took: '+list_2+' ';
},
product_group_fitler: function(id)
{
console.log('product filter');
$('select[name=product_' + id + '_from]').html( question_plugins.product_switch.dropdown_regel_app_from_list(id,$('[name=product_' + id + '_from]').val(),null,null,$('[name="product_'+id+'_brand"]').val() ) ).trigger('change');
},
dropdown_regel_app_from_list: function(id,product,product_advice,work_array,products_group_id)
{
if(product) selected=''; else selected='selected';
list = 'Search in products ';
$.each(products,function(index,item)
{ if(item['id'] in product_switch_list)
{
if(item['products_group_id'] == products_group_id || products_group_id =="" )
{
if(item['id'] == product) selected='selected'; else selected='';
list = list +'' +item['products_group_label']+' '+ item['label'] + ' ';
brand[item['products_group_id']] = item['products_group_label'];
}
}
});
return list;
},
filter_next_element: function(el)
{
console.log('filter poging');
id = $(el).val();
use_me = el;
$(el).next().children('option').hide();
$(el).next().children('option[data-group_id="'+id+'"]').show();
$(el).next().children('option:selected').attr('selected',false).prop('selected',false);
$(el).next().children('option:first').attr('selected',true).prop('selected',true);
},
add: function(el)
{
},
build: function(json,taal)
{
var work_array=load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var string_fixed = work_array['label'][taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + '';
bounded="";
product_switch_list = {};
$.each(work_array.extra,function(index,item)
{
id = index.split('_')[1];
if(index.split('_')[2] == 'from')
{
console.log(item);
product_switch_list[ item ] = work_array.extra['product_'+id+'_to'];
}
});
work_array['default_value'] = {};
work_array['default_value']['from'] = '';
work_array['default_value']['to'] = '';
if( typeof current_response[app.survey.view.get('active_tab')] !== 'undefined' )
{
if(work_array['id'] in current_response[app.survey.view.get('active_tab')])
{
work_array['default_value']['from'] = current_response[app.survey.view.get('active_tab')][ work_array['id'] ][1].value;
work_array['default_value']['to'] = current_response[app.survey.view.get('active_tab')][ work_array['id'] ][2].value;
}
}
change_to = work_array['default_value']['to'];
//logica_check_current_tab
html ='';
html = html + question_plugins.product_switch.dropdown_regel_app(work_array['id'],work_array['default_value']['from'],work_array['default_value']['to'],work_array);
return string_fixed +required_marked + ''+html+'
';
},
editor_build: function(json) //antwoorden_json
{
parse_editor_json(json);
question_label_class_html =new_option_settings(true,false,false,'0.0',label,required,input_type,false,default_value,false,placeholder['0.1'],false,tag_value)+' '+' '+' ';
// extra_html = 'Make searchable ';
extra_html ='Import options from CSV file ';
// extra_html = extra_html+'Options import templateDownload ';
var answers_options_inputs = 'From: ' + new_option_settings(true,false,false,'0.1','From',required,input_type,false,default_value,false,'',false,tag_value)+
'To: ' + new_option_settings(true,false,false,'0.2','To',required,input_type,false,default_value,false,'',false,tag_value)+
'Took Advice?: ' + new_option_settings(true,false,false,'0.3','Took Advice?',required,input_type,false,default_value,false,'',false,tag_value);
load_editor_fields
(
question_label_class_html, //question_label_class_html
answers_options_inputs, //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button$(\'.product_suggestion\').length +1
'Add ' +extra_html// extra_html //extra
);
$.each(extra,function(index,item)
{
id = index.split('_')[1];
if(index.split('_')[2] == 'from')
{
console.log(item);
$('.add_list').before( question_plugins.product_switch.dropdown_regel(id,item,extra['product_'+id+'_to']) );
}
});
},
check_next: function(event,el){
if(event.which==13){
event.preventDefault();
var all_inputs = $(el).closest(".tabform").find('.vraaglijst_type_vraag:visible');
var my_index = all_inputs.index($(el).closest(".vraaglijst_type_vraag"));
if(my_index + 1 < all_inputs.length){
var next=all_inputs.get(my_index+1);
$(next).find("input:visible").focus();
} else {
$(el).closest(".tabform").find('.vraaglijst_type_vraag input').blur();
}
}
},
after_build: function(element,json)
{
var id = $(element).attr('id').split("_")[1];
app.survey.enable_select2($('#product_'+id+'_readl_advice'));
app.survey.enable_select2($('[name=product_'+id+'_to]'));
app.survey.enable_select2($('[name=product_'+id+'_brand]'));
app.survey.enable_select2($('[name=product_'+id+'_from]'));
$('[name=product_'+id+'_from]').trigger('change');
// $('[name=product_' + id + '_to]').val( change_to ).trigger('change'); // DIT MOET WEL WEER GAAN WERKEN WANT HET IS VAST BELANGRIJK MAAR NU ER UIT DOOR REX3
console.log('element');
console.log(element);
console.log($(element).find('[data-logica_array]').data('logica_array'));
if($(element).find('[data-logica_array]').data('logica_array') !='""')
{
if( app.survey.check_question_logic( $(element).find('[data-logica_array]').data('logica_array') ) )
{
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
},
logica: function(json_array)
{
// console.warn(json_array);
return true;
/*
var id =json_array.id;
var tab_id =json_array.tab_id;
var operator_type =json_array.operator_type;
var value =json_array.value;
var saved_value = '';
if( $('#vraagwrapper_'+json_array.id+':visible').length == 0 && $('#vraagwrapper_'+json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if (typeof current_response[tab_id] != 'undefined' && $('#vraag-0-'+json_array.id).length == 0) saved_value = current_response[tab_id][id][0]['value']; //only check if the question is NOT active on the page.
if (operator_type == '<' && ($('#vraag-0-'+id).val() < value || saved_value < value)) return true;
else if (operator_type == '>' && ($('#vraag-0-'+id).val() > value || saved_value > value)) return true;
else if (operator_type == '==' && ($('#vraag-0-'+id).val() == value || saved_value == value)) return true;
else return false;
*/
//logica_array = $(element).data('logica_array');
},
get_value: function(id)
{
//if($('#vraag-0-'+id).val() == $('#vraag-0-'+id).data('bounded_value') && $('#vraag-0-'+id).val() != '')
return { '1' : {
'value' : $('[name="product_'+id+'_from"]').val(),
'type' : 'product_switch',
'required' : ( $('[name="product_'+id+'_from"]').data('required') =='1' ),
'hidden_by_logic' : ( $('[name="product_'+id+'_from"]').parents('.hidden_by_logic').length == 1 )
}
,'2' : {
'value' : $('[name="product_'+id+'_to"]').val(),
'type' : 'product_switch',
'required' : ( $('[name="product_'+id+'_from"]').data('required') =='1' ),
'hidden_by_logic' : ( $('[name="product_'+id+'_from"]').parents('.hidden_by_logic').length == 1 )
}
,'3' : {
'value' : ($('[name=product_' + id + '_from] option:selected').data('to') == $('[name="product_'+id+'_to"]').val() && $('[name="product_'+id+'_to"]').val() != null) ? 1 : 0, //iets met of het advbice was of niet
'type' : 'product_switch',
'required' : ( $('[name="product_'+id+'_from"]').data('required') =='1' ),
'hidden_by_logic' : ( $('[name="product_'+id+'_from"]').parents('.hidden_by_logic').length == 1 )
}
};
},
validate: function(id,tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if( typeof current_response[tab_id] === 'undefined' )
{
error_array.push( { 'error' : 'ignored tab' } );
}
else
{
if( current_response[tab_id][id][1]['value'] == '' && current_response[tab_id][id][1]['required'] && !current_response[tab_id][id][1]['hidden_by_logic']) error_array.push( { 'error' : 'required' } );
// if( current_response[tab_id][id][2]['value'] == '' && current_response[tab_id][id][2]['required'] && !current_response[tab_id][id][2]['hidden_by_logic']) error_array.push( { 'error' : 'required' } );
}
return error_array;
}
};
function product_switch_editor(antwoorden_json) { return question_plugins.product_switch.editor_build(antwoorden_json); }
function product_switch_builder(json,taal) { return question_plugins.product_switch.build(json,taal); }
function product_switch_add_drop_item_with_import(id, product_from,product_to) //well answers_options_well
{
$('.add_list').before( question_plugins.product_switch.dropdown_regel(id,product_from,product_to) );
/* if(typeof(label)=="undefined")label='';
$('.answers_options_inputs').append(new_option_settings(true,false,false,'0.'+dropdown_wortel,label,'',''));
$('.answers_options_inputs').append(' ');
*/
}
function create_advice(id)
{
console.log(id);
$('[name=product_' + id + '_to]').val($('[name=product_' + id + '_from] option:selected').data('to')).trigger('change');
console.log($('[name=product_' + id + '_from] option:selected').data('to'));
$('#product_'+id+'_readl_advice').html(''+$('select[name=product_' + id + '_to] option:selected').html()+' ').trigger('change');
}
function product_switch_fileheader_test(header_String)
{
if (true)//header_String=="Label" )
{
$("#btn-import").removeClass('disabled');
$(".file_check").removeClass('glyphicon-remove').removeClass('glyphicon-minus').addClass('glyphicon-ok');
return true;
}
else
{
$("#btn-import").addClass('disabled');
$(".file_check").removeClass('glyphicon-ok').removeClass('glyphicon-minus').addClass('glyphicon-remove');
return false;
}
}
$(document.body).on("change","#product_switch_import_file",function()
{
var file = document.getElementById("product_switch_import_file").files;
var reader = new FileReader();
product_switch_handleFiles(file);
});
function product_switch_handleFiles(files) {
// Check for the various File API support.
if(confirm('Are you sure you want to import this file? This will replace all existing options in the asdsad.'))
{
if (window.FileReader) {
// FileReader are supported.
product_switch_getAsText(files[0]);
} else {
alert('FileReader are not supported in this browser.');
}
}
else
{
$('#product_switch_import_file').val('');
}
}
function product_switch_getAsText(fileToRead) {
var reader = new FileReader();
// Read file into memory as UTF-8
reader.readAsText(fileToRead);
// Handle errors load
reader.onload = product_switch_loadHandler;
reader.onerror = product_switch_errorHandler;
}
function product_switch_loadHandler(event) {
var csv = event.target.result;
product_switch_processData(csv);
}
function product_switch_processData(csv) {
var allTextLines = csv.split(/\r\n|\n|\r/);
// lines = [];
dropdown_wortel=0;
$('.answers_options_inputs').html('');
for (var i=0; i /g, ">").replace(/' +
' ' +
' ' +
' ' +
' ';
return string_fixed;
},
editor_build: function(json) //antwoorden_json //geslaagd, 2 aantal goed, 3 target, 4 totaal, 5 percentage (edited)
{
parse_editor_json(json);
question_label_class_html =new_option_settings(true,false,false,'0.0',label,required,input_type,false,default_value,false,placeholder['0.1'],false,tag_value,'no_show')
question_options_inputs = 'The next labels are needed for dashboard use only. They won\'t be shown in the app ' +
new_option_settings(true,false,false,'0.1','Passed',required,input_type,false,default_value,false,'',false,tag_value,'no_show') +
new_option_settings(true,false,false,'0.2','Correct answers',required,input_type,false,default_value,false,'',false,tag_value,'no_show') +
new_option_settings(true,false,false,'0.3','Correct answers needed to pass',required,input_type,false,default_value,false,'',false,tag_value,'no_show') +
new_option_settings(true,false,false,'0.4','Total question count',required,input_type,false,default_value,false,'',false,tag_value,'no_show') +
new_option_settings(true,false,false,'0.5','Correct answers in %',required,input_type,false,default_value,false,'',false,tag_value,'no_show');
load_editor_fields
(
question_label_class_html, //question_label_class_html
question_options_inputs, //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
''// extra_html //extra
);
},
check_next: function(event,el){
if(event.which==13){
event.preventDefault();
var all_inputs = $(el).closest(".tabform").find('.vraaglijst_type_vraag:visible');
var my_index = all_inputs.index($(el).closest(".vraaglijst_type_vraag"));
if(my_index + 1 < all_inputs.length){
var next=all_inputs.get(my_index+1);
$(next).find("input:visible").focus();
} else {
$(el).closest(".tabform").find('.vraaglijst_type_vraag input').blur();
}
}
},
after_build: function(element,json)
{
$(element).addClass('hidden_by_logic')
},
logica: function(json_array)
{
// console.warn(json_array);
var id =json_array.id;
var tab_id =json_array.tab_id;
var operator_type =json_array.operator_type;
var value =json_array.value;
/* [{
"1548":{"id":"1548","tab_id":"0","type":"radio_yesno","value":"1"},
"1547":{"id":"1547","tab_id":"0","type":"vraag","value":"123","operator_type":"=="},
"1544":{"id":"1544","tab_id":"0","type":"vraag","value":"234","operator_type":"=="},
"not":false
}]*/
//current_response[tab_id][id][0]['value']
var saved_value = '';
if( $('#vraagwrapper_'+json_array.id+':visible').length == 0 && $('#vraagwrapper_'+json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if (typeof current_response[tab_id] != 'undefined' && $('#vraag-0-'+json_array.id).length == 0) saved_value = current_response[tab_id][id][0]['value']; //only check if the question is NOT active on the page.
if (operator_type == '<' && ($('#vraag-0-'+id).val() < value || saved_value < value)) return true;
else if (operator_type == '>' && ($('#vraag-0-'+id).val() > value || saved_value > value)) return true;
else if (operator_type == '==' && ($('#vraag-0-'+id).val() == value || saved_value == value)) return true;
else return false;
//logica_array = $(element).data('logica_array');
//return true;
},
get_value: function(id)
{
return { '1' : { //geslaagd
'value' : $('#quiz-1-'+id).val(),
'type' : 'quiz',
'required' : 1,
'hidden_by_logic' : 0
},
'2' : { //aantal goed
'value' : $('#quiz-2-'+id).val(),
'type' : 'quiz',
'required' : 1,
'hidden_by_logic' : 0
},
'3' : { //aantal nodig
'value' : $('#quiz-3-'+id).val(),
'type' : 'quiz',
'required' : 1,
'hidden_by_logic' : 0
},
'4' : { //aantal totaal
'value' : $('#quiz-4-'+id).val(),
'type' : 'quiz',
'required' : 1,
'hidden_by_logic' : 0
},
'5' : { //aantal goed in %
'value' : $('#quiz-5-'+id).val(),
'type' : 'quiz',
'required' : 1,
'hidden_by_logic' : 0
}
};
},
validate: function(id,tab_id, survey_id) //test required
{
var error_array = [];
/*
if( typeof current_response[tab_id] === 'undefined' )
{
error_array.push( { 'error' : 'ignored tab' } );
}
else
{
if( current_response[tab_id][id][1]['value'] == '' && current_response[tab_id][id][1]['required'] && !current_response[tab_id][id][1]['hidden_by_logic']) error_array.push( { 'error' : 'required' } );
}
*/
return [];
}
};
function quiz_result_editor(antwoorden_json) { return question_plugins.quiz_result.editor_build(antwoorden_json); }
function quiz_result_builder(json,taal) { return question_plugins.quiz_result.build(json,taal); }
/*
var question_plugins = question_plugins || {};
question_plugins.vraag =
{
build: function(json,taal)
{
},
editor_build: function(json) //antwoorden_json
{
},
after_build: function(element)
{
},
logica: function(json_array)
{
return true;
},
get_value: function(id)
{
return { '0' : { 'value' : $('#vraag-0-'+id).val(),
'type' : 'vraag',
'bounded_value' : ($('#vraag-0-'+id).val() == $('#vraag-0-'+id).data('bounded_value') && $('#vraag-0-'+id).val() != '') }
};
},
validate: function(id,tab_id) //test required
{
var error_array = [];
if( typeof current_response[tab_id] === 'undefined' )
{
error_array.push( { 'error' : 'ignored tab' } );
}
else
{
// if( current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required']) error_array.push( { 'error' : 'required' } );
}
return error_array;
}
};*/
var question_plugins = question_plugins || {};
question_plugins.radio_yesno =
{
build: function (json, taal) {
var work_array = load_question_json(json);
// load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var required_marked = '';
if (work_array['required'] == 1) {
required_marked = '' + trans('required') + ' ';
var required_className = 'required';
}
work_array['default_value'] = { 1: '', 2: '' }
/*
if( typeof current_response[app.survey.view.get('active_tab')] !== 'undefined' )
{
if(work_array['id'] in current_response[app.survey.view.get('active_tab')])
{
work_array['default_value'][current_response[app.survey.view.get('active_tab')][ work_array['id'] ][0].value]='checked';
}
}*/
var disabled_string=app.survey.is_disabled(app.survey.get_survey_id()) ? " disabled " : "";
var current_response = get_current_response();
//get_current_tab()
if (typeof current_response[get_current_tab()] !== 'undefined') {
if (work_array['id'] in current_response[get_current_tab()] && Object.keys(current_response[get_current_tab()][work_array.id]).length>0){//} && JSON.stringify(current_response[get_current_tab()][work_array.id])!=="[]") {
work_array['default_value'][current_response[get_current_tab()][work_array['id']][0].value] = 'checked';
}
}
/*
return work_array.label[taal] + required_marked +
''+
''+ work_array.options['0.1'][taal] +' '+
''+ work_array.options['0.2'][taal] +' '+
' ';*/
//nog een keer, voor de options, want sommige vragen staan niet goed ingesteld.
taal = app.survey.determine_language(work_array.options,"0.1",taal);
var return_html = '' + work_array.label[taal] + required_marked + ' ';
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json); //parse antwoorden in 4 jsons:
//window.options
//window.input_type
//window.required
//window.extra
if (options['0.1'] === "") options['0.1'] = { 'NL': 'Yes' };
if (options['0.2'] === "") options['0.2'] = { 'NL': 'No' };
question_label_class_html = new_option_settings(true, true, false, '0.0', label, required, '', false, '', false, '', true, tag_value) + ' ';
options_html = new_option_settings(true, false, false, '0.1', options['0.1'], '', '') + new_option_settings(true, false, false, '0.2', options['0.2'], '', '');
load_editor_fields
(
question_label_class_html, //question_label_class
'', //question_options_inputs
'', //question_options_inputs_button
options_html, //answers_options_inputs
'', //answers_options_inputs_button
'' //extra
);
},
after_build: function (element,json) {
console.warn("EL");
console.warn(element);
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
$(element).find(".radio").bootstrapMaterialDesign();
$(element).find(".bmd-radio").addClass("needsclick");
},
logica: function (json_array) {
var current_response=get_specific_response(get_survey_id() );
// console.log(json_array);
//console.log(!(tab_id in current_response));
var tab_id = json_array.tab_id;
if ($('#vraagwrapper_' + json_array.id + ':visible').length == 0 && $('#vraagwrapper_' + json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if ($('[name=radio_yesno-0-' + json_array.id + ']:checked').val() == json_array.value) return true; //eerst naar de actieve waarde kijken.
else if (!(tab_id in current_response)) return false;
else if ($('[name=radio_yesno-0-' + json_array.id + ']:checked').length == 0) // if (current_response[tab_id][json_array.id][0]['value'] == json_array.value) return true;
{
//console.log('radio_yesno','here');return false;
if(0 in current_response[tab_id][json_array.id]) if (current_response[tab_id][json_array.id][0]['value'] == json_array.value) return true; //daarna naar opgeslagen waarden kijken ALS het item niet actief is op de tab
else return false;
}
return false;
},
get_value: function (id) {
var value = '';
if ($('[name=radio_yesno-0-' + id + ']:checked').length == 1) value = $('[name=radio_yesno-0-' + id + ']:checked').val();
return {
'0': {
'value': value,
'type': 'radio_yesno',
'required': ($('[name=radio_yesno-0-' + id + ']').data('required') == '1'),
'hidden_by_logic': ($('[name=radio_yesno-0-' + id + ']').parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
if (current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required' });
}
return error_array;
}
};
function radio_yesno_editor(antwoorden_json) { return question_plugins.radio_yesno.editor_build(antwoorden_json); }
function radio_yesno_builder(json, taal) { return question_plugins.radio_yesno.build(json, taal); }
var question_plugins = question_plugins || {};
question_plugins.selfie =
{
build: function (json, taal) {
var is_electron = window && window.process && window.process.type;
var work_array = load_question_json(json);
console.warn(work_array);
taal = app.survey.determine_language(work_array,"label",taal);
var string_fixed = work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + '';
var required_className = 'required';
}
var current_response = get_current_response();
var disabled_string=app.survey.is_disabled(app.survey.get_survey_id()) ? " disabled " : "";
var return_html = '';
if( typeof current_response[get_current_tab()] !== 'undefined' )
{
if(work_array['id'] in current_response[get_current_tab()])
{
work_array['default_value'] = current_response[get_current_tab()][ work_array['id'] ][0].value;
}
}
storage = ' ';
console.log(work_array.extra);
test_dump = work_array;
if (!(work_array.extra == "")) {
if (!('no_storage' in work_array.extra) || is_electron) storage = '' + dropdown_tags;
}
else if (work_array.extra['photo_clients_tags'] == 'on') {
var client_select = 'Select a client: ' + required_tags_warning + ' Select a client ';
$.each(work_array.extra, function (i, v) {
if (i == 'photo_tags') return false;
if (i == 'photo_clients_tags') return false;
client_select = client_select + '' + v + ' ';
});
client_select = client_select + '
';
return '' + string_fixed + required_marked + ' ' + storage + ' ' + client_select;
}
else {
return '' + string_fixed + required_marked + ' ' + storage + ' ';
}
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json);
question_label_class_html = new_option_settings(true, true, false, '0.0', label, required, '') + ' ';
//tag_check = ' ';
//console.log(extra);
no_storage_checked = "";
if ('no_storage' in extra) no_storage_checked = "checked";
extra_html = 'Do not allow photo\'s from storage ';
extra_html = extra_html + 'Photo tag option (clients list) ';
extra_html = extra_html + 'Photo tag option (custom list) Tag options: Add more ';
extra_html = extra_html + 'Tag is required ';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
extra_html //extra
);
$('.tags_option').hide();
// $('#theForm').after(tag_check);
if (extra) {
if (extra['photo_tags'] == 'on') {
$('.tags_option').show();
$('[name=photo_tags]').prop('checked', true);
$.each(extra, function (key, value) {
// console.log(key +' => '+value)
if (key == 'photo_tags') return false;
else if (key == 1) $('[name=' + key + ']').val(value);
else {
add_more_tags(value);
//$('[name='+key+']').val(value);
}
});
}
if (extra['photo_clients_tags'] == 'on') {
$('[name=photo_clients_tags]').prop('checked', true);
}
if (extra['required_tags'] == 'on') {
$('[name=required_tags]').prop('checked', true);
}
}
},
after_build: function (element, json) {
/* var is_electron = window && window.process && window.process.type;
if (is_electron) {
element.find(".photo-button").hide();
}
*/
if (element.find(".photo-value").val() !== "") {
element.find(".photo-button,.gallery-button").addClass("photo_taken");
element.find("i.camera-icon,i.gallery-icon").removeClass("mdi-camera mdi-image").addClass("mdi-check");
}
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
var id = $(element).find(".foto_tag").data('question_id');
var tab_id = get_current_tab();//app.survey.view.get('active_tab');
var current_response = get_current_response();
$(element).find(".photo-button").on("click",function(){
question_plugins.foto.take_picture($(this).data("id"));
});
$(element).find(".gallery-button").on("click",function(){
question_plugins.foto.browse_picture($(this).data("id"));
});
if (tab_id in current_response) {
if ($(element).find(".foto_tag").length) $(element).find(".foto_tag").val(current_response[tab_id][id][0].tags);
}
var work_array = load_question_json(json);
if(work_array.extra['photo_clients_tags'] == 'on') {
console.error("loadage of photo clients tags");
var return_html = 'Select a client ';
var id = $(element).find(".foto_tag").data('question_id');
api_request('client_users', "get", {}, function (data) {
console.error("data get");
console.error(data);
$.each(data, function (i, v) {
return_html = return_html + '' + v['full_name'] + ' ';
});
$(element).find('select[name=foto_tag-0-' + id + ']').html(return_html);
});
}
app.survey.enable_select2($(element).find("select"));
},
logica: function (json_array) {
return true;
},
get_value: function (id) {
return {
'0': {
'value': $("#foto-0-" + id).val(),
'type': 'foto',
'required': ($('#foto-0-' + id).data('required') == '1'),
'required_tag': ($('#foto-0-' + id).data('required_tag') == '1'),
'tags': $("[name='foto_tag-0-" + id + "'] option:selected").text(),
'tag' : $("[name='foto_tag-0-" + id + "']").val(),
'hidden_by_logic': ($('#foto-0-' + id).parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
if (current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required' });
if (current_response[tab_id][id][0]['tags'] == null && current_response[tab_id][id][0]['required_tag'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required_tag' });
}
return error_array;
}
};
function selfie_editor(antwoorden_json) { return question_plugins.selfie.editor_build(antwoorden_json); }
function selfie_builder(json, taal) { return question_plugins.selfie.build(json, taal); }
var question_plugins = question_plugins || {};
question_plugins.slider =
{
build: function (json, taal) {
var work_array = load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var string_fixed = work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/Ratings:
// -
//
/*
*/
var disabled_string=app.survey.is_disabled(app.survey.get_survey_id()) ? " disabled " : "";
var required_marked = '';
if (work_array.default_value == '') work_array.default_value = work_array.extra['min'];
/* if( typeof current_response[app.survey.view.get('active_tab')] !== 'undefined' )
{
if(work_array['id'] in current_response[app.survey.view.get('active_tab')])
{
work_array['default_value'] = current_response[app.survey.view.get('active_tab')][ work_array['id'] ][0].value;
}
}*/
var current_response = get_current_response();
//get_current_tab()
if (typeof current_response[get_current_tab()] !== 'undefined') {
if (work_array['id'] in current_response[get_current_tab()]) {
try {
work_array['default_value'] = current_response[get_current_tab()][work_array['id']][0].value;
} catch(e){}
}
}
if (work_array.required == 1) {
required_marked = '' + trans("required") + ' ';
var required_className = 'required';
}
// return ''+ string_fixed +required_marked +'
';
return '' + string_fixed + required_marked + ' Value ';
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json);
question_label_class_html = new_option_settings(true, true, false, '0.0', label, required, '', false, '', false, '', true, tag_value) + ' ';;
console.log(extra);
if (!extra['min']) extra['min'] = '1';
options_html = ' min: ';
if (!extra['max']) extra['max'] = '5';
options_html = options_html + ' max: ';
if (!extra['step']) extra['step'] = '1';
options_html = options_html + ' step:
';
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
options_html //extra
);
},
after_build: function (element,json) {
var value_el = element.find(".slider-value");
var slider_el = element.find(".slider")[0];
noUiSlider.create(slider_el, {
start: parseInt(value_el.val()),
connect: "lower",
step: parseInt(value_el.data("step")),
range: {
min: parseInt(value_el.data("min")),
max: parseInt(value_el.data("max"))
}
});
if(app.survey.is_disabled(app.survey.get_survey_id())){
slider_el.setAttribute('disabled', true);
}
slider_el.noUiSlider.on('update', function (values, handle) {
value_el.val(values[handle]);
});
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
},
logica: function (json_array) {
var current_response=get_specific_response(get_survey_id() );
var id = json_array.id;
var tab_id = json_array.tab_id;
var operator_type = json_array.operator_type;
var value = json_array.value;
/* [{
"1548":{"id":"1548","tab_id":"0","type":"radio_yesno","value":"1"},
"1547":{"id":"1547","tab_id":"0","type":"vraag","value":"123","operator_type":"=="},
"1544":{"id":"1544","tab_id":"0","type":"vraag","value":"234","operator_type":"=="},
"not":false
}]*/
//current_response[tab_id][id][0]['value']
var saved_value = '';
if ($('#vraagwrapper_' + json_array.id + ':visible').length == 0 && $('#vraagwrapper_' + json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if (typeof current_response[tab_id] != 'undefined' && $('#slider-0-' + json_array.id).length == 0) saved_value = current_response[tab_id][id][0]['value']; //only check if the question is NOT active on the page.
if (operator_type == '<' && ($('#slider-0-' + id).val() < value || saved_value < value)) return true;
else if (operator_type == '>' && ($('#slider-0-' + id).val() > value || saved_value > value)) return true;
else if (operator_type == '==' && ($('#slider-0-' + id).val() == value || saved_value == value)) return true;
else return false;
},
get_value: function (id) {
return {
'0': {
'value': $('#slider-0-' + id).val().replace(".00", ""),
'type': 'slider',
'required': ($('#slider-0-' + id).data('required') == '1'),
'hidden_by_logic': ($('#slider-0-' + id).parents('.hidden_by_logic').length == 1)
}
};
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
if (current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push({ 'error': 'required' });
}
return error_array;
}
};
function slider_editor(antwoorden_json) { return question_plugins.slider.editor_build(antwoorden_json); }
function slider_builder(json, taal) { return question_plugins.slider.build(json, taal); }
var question_plugins = question_plugins || {};
question_plugins.tekst_vlak =
{
build: function(json,taal)
{
var work_array=load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var string_fixed = work_array.label[taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + '';
var required_className = 'required';
}
var current_response = get_current_response();
if( app.survey.get_current_tab() in current_response){
if(work_array['id'] in current_response[app.survey.get_current_tab()]){
if(0 in current_response[ app.survey.get_current_tab()][ work_array['id'] ]){
work_array['default_value'] = current_response[ app.survey.get_current_tab()][ work_array['id'] ][0].value;
}
}
}
console.log("work_array['default_value']",work_array['default_value']);
return '' + string_fixed + required_marked + '
';
//return string_fixed + ' ';
},
editor_build: function(json) //antwoorden_json
{
parse_editor_json(json);
question_label_class_html =new_option_settings(true,true,false,'0.0',label,required,input_type,true,default_value,true,placeholder['0.1'],true,tag_value);
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
'' //extra
);
},
after_build: function(element,json)
{
$(element).find('label').addClass('active');
if($(element).find('[data-logica_array]').data('logica_array') !='""')
{
if( app.survey.check_question_logic( $(element).find('[data-logica_array]').data('logica_array') ) )
{
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
$('.vraaglijst_type_tekst_vlak textarea').autosize({append: "\n"});
},
logica: function(json_array)
{
var current_response=get_specific_response(get_survey_id() );
//if empty false, else true
if( $('#vraagwrapper_'+json_array.id+':visible').length == 0 && $('#vraagwrapper_'+json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if( $('#tekst_vlak-0-'+json_array.id).val() != '' ) return true; //eerst naar de actieve waarde kijken.
if( typeof current_response[json_array.tab_id] != 'undefined' && $('#tekst_vlak-0-'+json_array.id) == 0 ) if( current_response[json_array.tab_id][json_array.id][0]['value'] != '' ) return true; //daarna naar opgeslagen waarden kijken ALS het item niet actief is op de tab
return false;
},
get_value: function(id)
{
return { '0' : { 'value' : $('#tekst_vlak-0-'+id).val(),
'type' : 'tekst_vlak',
'required' : ( $('#tekst_vlak-0-'+id).data('required') =='1' ),
'hidden_by_logic' : ( $('#tekst_vlak-0-'+id).parents('.hidden_by_logic').length == 1 )
}
};
},
validate: function(id,tab_id,survey_id) //test required
{
var error_array = [];
var current_response=get_specific_response(survey_id);
if( typeof current_response[tab_id] === 'undefined' )
{
error_array.push( { 'error' : 'ignored tab' } );
}
else
{
if( current_response[tab_id][id][0]['value'] == '' && current_response[tab_id][id][0]['required'] && !current_response[tab_id][id][0]['hidden_by_logic']) error_array.push( { 'error' : 'required' } );
}
return error_array;
}
};
function tekst_vlak_editor(antwoorden_json) { return question_plugins.tekst_vlak.editor_build(antwoorden_json); }
function tekst_vlak_builder(json,taal) { return question_plugins.tekst_vlak.build(json,taal); }
var question_plugins = question_plugins || {};
var the_final_grid = {};
question_plugins.the_final_grid =
{
build: function (json, taal) {
console.log('the_final_grid start');
console.log(json);
var work_array = app.survey.load_question_json(json);
taal = app.survey.determine_language(work_array, "label", taal);
var string_fixed = work_array['label'][taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + '';
var required_className = 'required';
}
bounded = "";
bounded_value = "";
default_value = '';
/* if( typeof current_response[app.survey.view.get('active_tab')] !== 'undefined' )
{
if(work_array['id'] in current_response[app.survey.view.get('active_tab')])
{
work_array['default_value'] = current_response[app.survey.view.get('active_tab')][ work_array['id'] ];
}
}*/
the_final_grid[work_array['id']] = JSON.parse(work_array['extra']['extra_data']);
console.log('the_final_grid');
console.log(the_final_grid);
return '' + string_fixed + bounded + required_marked + ' ';
},
editor_build: function (json) //antwoorden_json
{
parse_editor_json(json);
console.log('json');
console.log(json);
question_label_class_html = question_options({
'label': true,
'label_value': label,
'required': true,
'required_value': required,
'input_type': false,
'sub_id': '0.0'
});
var extra_data = '';
if (typeof extra['extra_data'] !== 'undefined') extra_data = extra['extra_data'];
load_editor_fields
(
question_label_class_html, //question_label_class_html
'', //question_options_inputs
'', //question_options_inputs_button
'', //answers_options_inputs
'', //answers_options_inputs_button
'edit grid '// extra_html //extra
);
//$('body').append('');
// $('.the_final_grid_fullscreen').html('save & exit ');
},
after_build: function (element, json) {
var question_id = element.attr('id').split("_")[1];
var current_response = app.survey.get_current_response();
//$(element).find('label').addClass('active');
console.log('element');
console.log(element);
console.log($(element).find('[data-logica_array]').data('logica_array'));
if ($(element).find('[data-logica_array]').data('logica_array') != '""') {
if (app.survey.check_question_logic($(element).find('[data-logica_array]').data('logica_array'))) {
$(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
}
else $(element).addClass('hidden_by_logic');
}
else $(element).removeClass('hidden_by_logic').removeClass('ignore_logic');
start_the_final_grid(question_id);
console.log('current_response');
console.log(current_response);
if (typeof current_response[app.survey.get_current_tab()] !== 'undefined') {
$.each(current_response[app.survey.get_current_tab()][question_id], function (key, sub_question_array) {
console.log('sub_question_array');
console.log(sub_question_array);
var cc = $('#vraagwrapper_' + question_id + ' td[data-sub_question_id="' + key + '"] ');
var newval = sub_question_array.value;
var question_type = sub_question_array.type.split('|')[1];
if (question_type == 'boolean' || question_type == 'canon_boolean') {
// var newval = $( "#modaltext [name=gridinput]:checked" ).val();
if (newval == '1') cc.find('span.val').html('Yes');
else if (newval == '0') cc.find('span.val').html('No');
else if (newval == '' && question_type == 'canon_boolean') cc.find('span.val').html('n/a');
}
else cc.find('span.val').html(newval);
cc.find('input.the_final_grid_input').val(newval);
});
}
// Add min-width to the Grid question th's so the columns are not cramped up
var tableHead = $('.the_final_grid_return_wrapper table tr:first-child th');
$.each(tableHead, function(index ,value) {
if ($(this).text().length > 20) {
$(this).css('min-width', '150px');
}
});
grid_logica(question_id);
},
logica: function (json_array) {
return true;
// console.warn(json_array);
var id = json_array.id;
var tab_id = json_array.tab_id;
var operator_type = json_array.operator_type ? json_array.operator_type : json_array.operators;
var value = json_array.value;
/* [{
"1548":{"id":"1548","tab_id":"0","type":"radio_yesno","value":"1"},
"1547":{"id":"1547","tab_id":"0","type":"vraag","value":"123","operator_type":"=="},
"1544":{"id":"1544","tab_id":"0","type":"vraag","value":"234","operator_type":"=="},
"not":false
}]*/
//current_response[tab_id][id][0]['value']
/* var saved_value = '';
if( $('#vraagwrapper_'+json_array.id+':visible').length == 0 && $('#vraagwrapper_'+json_array.id).length) return false; //hij is wel op de tab aanwezig maar NIET zichtbaar, altijd false
else if (typeof current_response[tab_id] != 'undefined' && $('#vraag-0-'+json_array.id).length == 0) saved_value = current_response[tab_id][id][0]['value']; //only check if the question is NOT active on the page.
if (operator_type == '<' && ($('#vraag-0-'+id).val() < value || saved_value < value)) return true;
else if (operator_type == '>' && ($('#vraag-0-'+id).val() > value || saved_value > value)) return true;
else if (operator_type == '==' && ($('#vraag-0-'+id).val() == value || saved_value == value)) return true;
else return false;
*/
//logica_array = $(element).data('logica_array');
},
get_value: function (id) {
var return_array = {};
//if($('#vraag-0-'+id).val() == $('#vraag-0-'+id).data('bounded_value') && $('#vraag-0-'+id).val() != '')
//the_final_grid_input_'+question_id+'
$('input.the_final_grid_input_' + id).each(function (index, obj) {
var sub_question_id = $(obj).parent().data('sub_question_id');
var type = 'the_final_grid|' + $(obj).parent().data('question_type');
var required = $(obj).parent().hasClass('required') ? 1 : 0;
var value = $('.the_final_grid_' + id + '_' + sub_question_id).val();
//var value ='';//$('[name="grid_handsontable-'+i+'-'+id+'"]').val()
if (sub_question_id) {
return_array[sub_question_id] = {
'value': value ? value : null,
'type': type,
'bounded_value': false,
'required': required,
'hidden_by_logic': $('#vraagwrapper_' + id).hasClass('hidden_by_logic')
};
}
//'hidden_by_logic' : ( $('#grid_handsontable-0-'+id).parents('.hidden_by_logic').length == 1 )
});
return return_array;
},
validate: function (id, tab_id, survey_id) //test required
{
var error_array = [];
var current_response = app.survey.get_current_response(survey_id);
if (typeof current_response[tab_id] === 'undefined') {
error_array.push({ 'error': 'ignored tab' });
}
else {
//var sub_questions = $('.the_final_grid_input_'+id);
// console.log('sub_questions=>'+sub_questions);
$.each(current_response[tab_id][id], function (index, sub_question) {
var hidden_by_logic = $('#vraagwrapper_' + id).hasClass('hidden_by_logic') ? $('#vraagwrapper_' + id).hasClass('hidden_by_logic') : sub_question['hidden_by_logic'];
if ((sub_question['value'] == '' || sub_question['value'] == null) && sub_question['required'] == 1 && !hidden_by_logic) {
error_array.push({ 'error': 'required' });
return false;
}
});
}
console.log(id);
console.log(error_array);
return error_array;
}
};
function the_final_grid_editor(antwoorden_json) { return question_plugins.the_final_grid.editor_build(antwoorden_json); }
function the_final_grid_builder(json, taal) { return question_plugins.the_final_grid.build(json, taal); }
//4":{"is":"is_full","cell_id":"3","when":"only_require"} do_not_require
function grid_logica(question_id) {
$('.vraagveld_class_' + question_id + ' .cell').each(function (key, obj) {
var logica = $(obj).data('logica');
console.log(logica);
if (logica['when']) {
$(obj).removeClass('required');
console.log('when');
if (logica['when'] == 'only_require') {
console.log('only_require');
if (logica['is'] == 'is_full') {
console.log('is_full');
if ($('.the_final_grid_' + question_id + '_' + logica['cell_id']).val() != '') $(obj).addClass('required');
}
else if (logica['is'] == 'is_empty') {
console.log('is_empty');
if (!($('.the_final_grid_' + question_id + '_' + logica['cell_id']).val() != '')) $(obj).addClass('required');
}
}
if (logica['when'] == 'do_not_require') {
console.log('do_not_require');
if (logica['is'] == 'is_empty') {
console.log('is_full');
if ($('.the_final_grid_' + question_id + '_' + logica['cell_id']).val() != '') $(obj).addClass('required');
}
else if (logica['is'] == 'is_full') {
console.log('is_empty');
if (!($('.the_final_grid_' + question_id + '_' + logica['cell_id']).val() != '')) $(obj).addClass('required');
}
}
}
});
$('.vraagveld_class_' + question_id + ' .cell small').hide();
// $('.vraagveld_class_' + question_id + ' .required.cell small').show();
// Only show required text if span.val does not contain any text
$($('.vraagveld_class_' + question_id + ' .required.cell')).each(function() {
if ($(this).find('span.val').text() != '') {
$(this).find('small').hide();
} else {
$(this).find('small').show();
}
});
}
function getheader(question_id) {
var preferred_locale = window.locale.toUpperCase();
var s = '';
s += ' ';
actual_col = 0;
$.each(the_final_grid[question_id]['column_count'], function (index, column_id) {
actual_col++;
var columnheader = "undefined";
if(the_final_grid[question_id]['column_labels'][preferred_locale][column_id]!=='' && the_final_grid[question_id]['column_labels'][preferred_locale][column_id]!==null && typeof the_final_grid[question_id]['column_labels'][preferred_locale][column_id]!=='undefined'){
columnheader = the_final_grid[question_id]['column_labels'][preferred_locale][column_id];
} else {
$.each(the_final_grid[question_id]['column_labels'],function(lcl,transl){
if(transl[column_id]!==null && transl[column_id]!=='' && typeof transl[column_id]!=="undefined"){
columnheader = transl[column_id];
}
})
}
s += '' + columnheader + ' ';
});
/* for (i = 0; i < ncols; i++) {
s += '' + questions[i] + ' ';
}*/
s += ' ';
return s;
}
function getrow(rownr, actual_row, question_id) {
var s = '';
var preferred_locale = window.locale.toUpperCase();
var rowheader = "undefined";
if(the_final_grid[question_id]['row_labels'][preferred_locale][rownr]!=='' && the_final_grid[question_id]['row_labels'][preferred_locale][rownr]!==null && typeof the_final_grid[question_id]['row_labels'][preferred_locale][rownr]!=='undefined'){
rowheader = the_final_grid[question_id]['row_labels'][preferred_locale][rownr];
} else {
$.each(the_final_grid[question_id]['row_labels'],function(lcl,transl){
if(transl[rownr]!==null && transl[rownr]!=='' && typeof transl[rownr]!=="undefined"){
rowheader = transl[rownr];
}
})
}
s += '' + rowheader + ' ';
/* for (i = 1; i < ncols; i++) {
//var id = rownr.toString() + (i).toString();
var question_type = '';
var required = '';
if(rownr in the_final_grid[3687]['grid_content'][i] )
{
question_type = the_final_grid[3687]['grid_content'][i][rownr]['question_type'];
required = the_final_grid[3687]['grid_content'][i][rownr]['required'];
}
s += '' +
//s += ' ' + id +
' ';
}*/
var actual_col = 0;
$.each(the_final_grid[question_id]['column_count'], function (index, column_id) {
var id = '';//rownr.toString() + (i).toString();
var question_type = '';
var sub_question_id = '';
var logica = '';
var required = '';
var required_class = '';
actual_col++;
if (rownr in the_final_grid[question_id]['grid_content'][column_id]) {
question_type = the_final_grid[question_id]['grid_content'][column_id][rownr]['question_type'];
required = parseInt(the_final_grid[question_id]['grid_content'][column_id][rownr]['required']);
//required = the_final_grid[question_id]['grid_content'][column_id][rownr]['required'];
if (required) required_class = 'required';
sub_question_id = the_final_grid[question_id]['grid_content'][column_id][rownr]['question_id'];
if ('grid_logica' in the_final_grid[question_id]) logica = the_final_grid[question_id]['grid_logica'][sub_question_id];
}
s += '' + ' ' + 'Required '
//s += ' ' + id +
' ';
});
s += ' ';
return s;
}
//4":{"is":"is_full","cell_id":"3","when":"only_allow"}
question_plugins.the_final_grid.move = function (newrow, newcol) {
var cc = floating_cc;
var question_id = floating_question_id;
// nieuwe invoer wordt automatisch opgeslagen
var newval = $("#final-grid-modal .modal-text [name=gridinput]").val();
var question_type = cc.data('question_type');
//var question_id = cc.data('question_id');
if (question_type == 'boolean' || question_type == 'canon_boolean') {
var newval = $("#final-grid-modal .modal-text [name=gridinput]:checked").val();
if (newval == '1') cc.find('span.val').html('Yes');
else if (newval == '0') cc.find('span.val').html('No');
else if (newval == '' && question_type == 'canon_boolean') cc.find('span.val').html('n/a');
}
else cc.find('span.val').html(newval);
cc.find('input.the_final_grid_input').val(newval);
grid_logica(question_id);
if (newrow <= 0) return;
if (newrow >= (the_final_grid[question_id]['row_count'].length + 1)) return;
if (newcol <= 0) return;
if (newcol >= (the_final_grid[question_id]['column_count'].length + 1)) return;
// oude highlight wordt opgeheven
var newcc = $('table.the_final_grid_table_' + question_id + ' [data-row=' + newrow + '][data-col= ' + newcol + ']');
var cc = newcc;
question_plugins.the_final_grid.highlight(newrow, newcol, question_id);
updatemodal(cc, question_id);
togglebuttons(newrow, newcol, question_id);
};
question_plugins.the_final_grid.highlight = function (row, col, question_id) {
// highlight current row and column
$('table.the_final_grid_table_' + question_id + ' tr td').css('background', '#fff');
$('table.the_final_grid_table_' + question_id + ' th').css('background', '#fff');
// $('table.the_final_grid_table_'+question_id+' th').css('background-image', '/img/stripes.png'); //background-image: url(/img/stripes.png);
$('table.the_final_grid_table_' + question_id + ' tr:nth-child(' + (row + 1) + ') td').css('background', '#f3f3f3');
$('table.the_final_grid_table_' + question_id + ' tr td:nth-child(' + (col + 1) + ')').css('background', '#f3f3f3');
$('table.the_final_grid_table_' + question_id + ' td[data-row=' + (row) + '][data-col= ' + (col) + ']').css('background', '#c3c3c3');
$('table.the_final_grid_table_' + question_id + ' th[data-row=' + (row) + ']').css('background', '#e0dede');
$('table.the_final_grid_table_' + question_id + ' th[data-col= ' + (col) + ']').css('background', '#e0dede');
};
function togglebuttons(row, col, question_id) {
console.log('row');
console.log(row);
console.log('col');
console.log(col);
$('#btnUp').prop('disabled', row <= 1);
$('#btnDown').prop('disabled', row == (the_final_grid[question_id]['row_count'].length));
$('#btnLeft').prop('disabled', col <= 1);
$('#btnRight').prop('disabled', col == (the_final_grid[question_id]['column_count'].length));
}
function updatemodal(cc, question_id) {
floating_cc = cc;
floating_question_id = question_id;
var actual_row = cc.data('row');
var row_id = cc.data('row_id');
var actual_col = cc.data('col');
var column_id = cc.data('column_id');
var question_type = cc.data('question_type');
// id = question_id = 3687;
// var question_id = $(cc).parents('.the_final_grid_return_wrapper').data('question_id');
id = question_id;
console.log('updatemodal question_id');
console.log(question_id);
var model_title = the_final_grid[question_id]['column_labels'][ languages[user.language_id-1].short_label ][column_id] + ' - ' + the_final_grid[question_id]['row_labels'][ languages[user.language_id-1].short_label ][row_id];
$('#final-grid-modal .modal-title').html(model_title);
var oldval = cc.find('input.the_final_grid_input').val();
var s = '';
//s += ' ';
//s += ' ';
//s += ' ';
/*
Philips dropdown 1:
- Cashback
- Free product
- 60 day on trial
Philips dropdown 2:
- No POS-material available
- Shop has removed the POS
- Not allowed to place the POS
- Other
*/
///////////////////
sub_question_id = 1;
placeholder_tekst = '';
var antwoord = oldval;
t = ''
if (question_type == 'number') {
var buttons=[10,5,1,0,-1,-5,-10];
t = t + '';
$.each(buttons,function(i,button){
t = t + '' + (button>0 ? "+" : (button<0 ? "" : "")) + button + ' ';
});
t = t + '
';
}
s += t;
/////////////
$('input.grid-input ').off();
$('input.grid-input ').trigger("unmask");
$('#final-grid-modal .modal-text').html(s);
if (question_type == "canon_dropdown") {
app.survey.enable_select2($('#final-grid-modal .modal-text').find("select"));
} else if (question_type == "number" || question_type == "decimal") {
$.mask.definitions['h'] = "[,0-9]";
$('#final-grid-modal .modal-text .number').mask("?999999999", { placeholder: "" });
$('#final-grid-modal .modal-text .decimal').mask("?hhhhhhhhhh", { placeholder: "" });
} else if (question_type == "canon_boolean" || question_type == "boolean_old" || question_type == "boolean") {
$('#final-grid-modal .modal-text').find(".radio").bootstrapMaterialDesign();
//$("final-grid-modal .radio .bmd-radio").addClass("needsclick");
$("#final-grid-modal .radio .bmd-radio").addClass("needsclick");
}
}
function change_number_grid(id,change)
{
console.log('change_number',id,change);
var current=$('#' + id).val() ? $('#' + id).val() : 0;
if(change == 0) current = 0;
else current = parseInt(current) + change;
$('#' + id).val(current);
}
function start_the_final_grid(question_id) {
console.log('start_the_final_grid => ' + question_id);
// console.log('start_the_final_grid')
//"{"column_count":[1,2],"column_labels":{"FR":[],"EN":[],"NL":[null,"column 1","column 2"]},"row_labels":{"FR":[],"EN":[],"NL":[null,"row 1","row 2"]},"row_count":[1,2],"active_tab":".tab_grid_content","active_taal":"NL","grid_content":{"1":{"1":{"required":"0","question_type":"boolean"},"2":{"required":"0","question_type":"boolean"}},"2":{"1":{"required":"0","question_type":"text"},"2":{"required":"0","question_type":"text"}},"3":{}}}"
//if(!(question_id in the_final_grid)) return;
questions = the_final_grid[question_id]['column_labels'][ languages[user.language_id-1].short_label ]; //['Number of facing Philips?', 'How many Philips Sku are not in stock?', 'How many Philips Sku do not have a price tag?', 'How many Philips Sku do not have a specification tag?']
products = the_final_grid[question_id]['row_labels'][languages[user.language_id-1].short_label];//['DiamondClean', 'FlexCare', 'HealthyWhite', 'GumHealth', 'PlaqueDefense', 'Sonicare For Kids', 'Other'];
cc = null; // jq object
// var nrows = products.length;
// var ncols = questions.length;
var s = '';
s = getheader(question_id);
var actual_row = 0;
$.each(the_final_grid[question_id]['row_count'], function (index, row_id) {
actual_row++;
s += getrow(row_id, actual_row, question_id);
});
$("table.the_final_grid_table_" + question_id).html(s);
$('table.the_final_grid_table_' + question_id + ' .cell').click(function () {
if (app.survey.is_disabled(app.survey.get_survey_id())) return;
var question_id = $(this).parents('.the_final_grid_return_wrapper').data('question_id');
console.log('question id from cell click');
console.log(question_id);
var id = $(this).attr('id');
var row = $(this).data('row');
var col = $(this).data('col');
var s = '';
var cc = $(this);
question_plugins.the_final_grid.highlight(row, col, question_id);
updatemodal(cc, question_id);
$('#final-grid-modal').modal('toggle');
togglebuttons(row, col, question_id);
// setTimeout(function(){ $("#gridinput").focus(); }, 200);
});
$('#final-grid-modal').off().on('hidden.bs.modal', function () {
if (cc) {
$('table.the_final_grid_table_' + question_id + ' th ,table.the_final_grid_table_' + question_id + ' tr, table.the_final_grid_table_' + question_id + ' tr td').css('background', '#fff');
cc.css('background', '#eee'); // laatst geselecteerde cell kan nog herkend worden
}
})
//werkt in chrome for android
$("#final-grid-modal").keydown(function (e) {
//alert('keydown ' + e.which);
if ((e.which == 190) || // punt, bij chrome
(e.which == 229)) // punt, bij chrome for android
{
e.preventDefault(); // werkt niet bij chrome for android
return;
}
});
/*
// werkt niet in chrome for android
$(document).keypress(function(e) {
if (e.which == 46) // punt
{
e.preventDefault();
return;
}
});
*/
// nb: keypress werkt niet in chrome for android (keyup wel)
// 13: enter
// 9: volgende (sp)
// 8: backspace
// 46: . (punt)
/* $(document).keyup(function(e) {
if (e.which == 46)
{
e.preventDefault();
return;
}
if(e.which == 13 || e.which == 9) {
if (cc)
{
move(cc.data('row') + 1, cc.data('col')); // move down is hier de default actie
}
}
});*/
question_plugins.the_final_grid.alignModal = function () {
var modalDialog = $(this).find(".modal-dialog");
// Applying the top margin on modal dialog to align it vertically center
modalDialog.css("margin-top", Math.max(0, ($(window).height() - modalDialog.height()) / 2));
}
// Align modal when it is displayed
$(".modal").on("shown.bs.modal", question_plugins.the_final_grid.alignModal);
// Align modal when user resize the window
/* $(window).on("resize", function(){
$(".modal:visible").each(alignModal);
}); */
$('#final-grid-modal .save').off().click(function () {
var newval = $("#final-grid-modal .modal-text #gridinput").val();
floating_cc.html(newval);
});
$('#final-grid-modal .up').off().click(function () {
question_plugins.the_final_grid.move(floating_cc.data('row') - 1, floating_cc.data('col'));
});
$('#final-grid-modal .down').off().click(function () {
question_plugins.the_final_grid.move(floating_cc.data('row') + 1, floating_cc.data('col'));
});
$('#final-grid-modal .left').off().click(function () {
question_plugins.the_final_grid.move(floating_cc.data('row'), floating_cc.data('col') - 1);
});
$('#final-grid-modal .right').off().click(function () {
question_plugins.the_final_grid.move(floating_cc.data('row'), floating_cc.data('col') + 1);
});
};
var question_plugins = question_plugins || {};
question_plugins.ticket_settings =
{
build: function(json,taal)
{
var work_array=load_question_json(json);
taal = app.survey.determine_language(work_array,"label",taal);
var string_fixed = work_array['label'][taal].replace(/&/g, "&").replace(/>/g, ">").replace(/' + trans('required') + ''; //altijd required. duh
var custom_client_list = work_array.default_value.split("#");
var return_html=''
//** title
//return_html = return_html+ 'Title
';
var title = '