diff --git a/core/fileManager.php b/core/fileManager.php index 3f911cd..ed92a73 100644 --- a/core/fileManager.php +++ b/core/fileManager.php @@ -171,14 +171,14 @@ function writeoutput($output) } else { $errors = ""; - // template name is set, has only alphanumeric characters, and is < 30 characters + // template name is set and is < 30 characters if(!isset($form["template-name"]) || - strlen($form["template-name"]) > 30 || - $form["template-name"] != preg_replace('/[^A-Za-z0-9]+/','',$form["template-name"])) + strlen($form["template-name"]) > 30 /*|| + $form["template-name"] != preg_replace('/[^A-Za-z0-9]+/','',$form["template-name"])*/) { $errors .= "
  • "; - $errors .= "Please input a valid template name (less than 30 alphanumeric characters only) "; - $errors .= "
  • "; + $errors .= "Please input a valid template name (less than 30 characters)"; + $errors .= ""; } else { @@ -358,10 +358,10 @@ function writeoutput($output) // else if template name has changed else if ($_REQUEST['oldname'] != $form["template-name"]) { - // check for template-name conflict happened earlier, so this is safe + // checked for template-name conflict happened earlier, so this is safe rename("../templates/".$_REQUEST['oldname'],"../templates/".$form["template-name"]); - // check if old name is currently active, if so, change? + // check if old name is currently active, if so, change // also need to rename in active.txt $optArr = array('oldName' => $_REQUEST['oldname'], 'newName' => $form['template-name'], diff --git a/core/js/experimenter.js b/core/js/experimenter.js index 9567720..dfc6a29 100644 --- a/core/js/experimenter.js +++ b/core/js/experimenter.js @@ -1,980 +1,981 @@ -var templates = {}; -var catlistnames = ["catA","catB","cat1","cat2"]; -var catfullnames = ["Category A","Category B","Category 1","Category 2"]; - -$.fn.hookToInput = function(selector) -{ - if(typeof selector == "string") - { - selector = $(selector); - } - - this.each(function(i) - { - var $this = $(this); - var assocInput = $($.isFunction(selector) ? selector($this) - : selector.get(i)); - - assocInput.keyup(function() - { - $this.html(assocInput.val() || "[Untitled]"); - }); - }); -} - -$.fn.toSerializedJSON = function() -{ - var $this = $(this); - var params = $this.serialize().split("&"); - var json = "{"; - - for(var i = 0, l = params.length; i 0; - - /* If current template has unsaved changes, prompt user to - * save before closing. - * - * Store unsaved data in cookies to prompt user with on - * return to experimenter - */ - if(hasUnsavedTemplate) - { - var templateId = $(".template-selected").data("templateid"); - $.cookie("unsaved_templateid",templateId); - $.cookie("unsaved_data",$("#template-form").toSerializedJSON()); - - return "Note: You have unsaved changes to " + templateId + "."; - } -} - -function showUnsavedChangesFromPrevious() -{ - var templateId = $.cookie("unsaved_templateid"); - var templateData = $.cookie("unsaved_data"); - if(templateId && templateData) - { - /*$("#alert-window").html("Do you want to recover unsaved changes to " + templateId + "?"); - $("#alert-window").dialog({ - title: "

    Unsaved Changes:" + templateId + "

    ", - modal: true, - buttons: { - Yes: function() - { - $(this).dialog("close"); - }, - No: function() - { - $(this).dialog("close"); - } - } - });*/ - - clearUnsavedChangesFromPrevious(); - } -} - -function clearUnsavedChangesFromPrevious() -{ - // Clear unsaved changes from previous visit - $.removeCookie("unsaved_templateid"); - $.removeCookie("unsaved_data"); -} - -function clearUnsavedTemplate() -{ - var unsavedTemplate = $(".template-unsaved"); - - unsavedTemplate.find(".save-item").remove(); - unsavedTemplate.data("ischanged", false) - .removeClass("template-unsaved"); -} - -function renderTemplateViewerItem(templateId) -{ - // Update :: added data-templateid attribute to avoid - // errors resulting from selecting .template-item elements - // with illegal characters in ID attribute - - $(".active-selector").append("
    " + templateId + "
    "); -} - -function showTemplates(input) -{ - // Save currently selected template (if any) - var currTemplateId = $("#template-name").val(); - - // Removes previously created DOM for templates - // before updating with new content - $(".user-template").remove(); - - var numTemplates = input.available.length; - var numTemplatesLoaded = 0; - - // Generate DOM elements for each template in - // .selector-frame and populate templates object - for (var template in input.available) - { - if(input.available[template] != "Empty") - { - renderTemplateViewerItem(input.available[template]); - } - - // Retrieve current template configuration from external resource - FileMgr.getJSON(FileMgr.getInputPath(input.available[template]), function(data) - { - templates[data["name"]] = data; - - numTemplatesLoaded++; - if(numTemplatesLoaded == numTemplates) - { - readyTemplates(input); - } - }); - } - - // Re-attach .template-selected class to current template - var currTemplateObj = $(".template-item[data-templateid='" + currTemplateId + "']"); - if(currTemplateObj.length > 0) - { - currTemplateObj.addClass("template-selected"); - } - - // Attach event handler for changing templates - $(".template-item").unbind("click").click(selectTemplate); -} - - -function verifyDelete(templateId) -{ - if($(".exp-header-active").html() == templateId) - { - $( "#alert-window" ).html(templateId+" is currently active. Please make another template active before deleting this template."); - $( "#alert-window" ).dialog({ - title: "

    Template Currently Active

    ", - modal: true, - buttons: { - Ok: function() { - $( this ).dialog( "close" ); - } - } - }); - } - else - { - $( "#alert-window" ).html("
    Are you sure you want to delete template '"+templateId+"'? This will delete all associated files, including existing data!!
    "); - $( "#alert-window" ).dialog({ - title: "

    Confirm Delete

    ", - modal: true, - buttons: { - Delete: function() { - FileMgr.post(FileMgr.getFileMgrPath(), {"op":"deleteTemplate", "template":templateId}, function(data) { - if (data.slice(0,5) == "Error") - { - alert(data); - } - else - { - $("#exp-content").empty(); - FileMgr.getJSON(FileMgr.getActivePath(),showTemplates); - } - }); - $(this).dialog("close"); - }, - Cancel: function() { - $(this).dialog("close"); - } - } - }); - } -} - -function selectTemplate() -{ - var $this = $(this); - - // Prevent reloading of current template so - // altered data not overwritted - if($this.hasClass("template-selected")) { - return false; - } - - // Prompt user to save changes to active template - // before changing to selected template - var currTemplateObj = $(".template-selected"); - var currTemplate = currTemplateObj.text(); - - // If new, unsaved template, adjust its title - if(currTemplateObj.attr("id") == "create-new") - { - currTemplate = ($("#template-name").val() != "Empty") ? $("#template-name").val() - : "Untitled"; - } - - if(currTemplateObj.hasClass("template-unsaved")) - { - $("#alert-window").html("Do you want to save changes to \"" + currTemplate +"\"?") - .dialog({ - title: "

    Unsaved Changes

    ", - modal: true, - close: clearUnsavedTemplate, - buttons: { - Save: function() - { - saveTemplate(function(data) - { - repaintTemplates(data); - changeTemplate({ - templateObj: $this, - isReloadActive: true - }); - $("#alert-window").dialog("close"); // Note the closure :: $(this) != $("#alert-window") - },showSaveError); - }, - Discard: function() - { - currTemplateObj.find(".template-item-label").html(currTemplateObj.data("templateid")); // Restore original template name - changeTemplate({ - templateObj: $this, - isReloadActive: false - }); - $(this).dialog("close"); - } - } - }); - } - else - { - changeTemplate({ - templateObj: $this, - isReloadActive: false - }); - } - - -} - -function changeTemplate(options) -{ - // isReloadActive indicates whether template inputs should - // be redownloaded with updates - isReloadActive = options.isReloadActive || false; - var $this = options.templateObj; - - // Change selected template - $(".template-selected").removeClass("template-selected"); - $this.addClass("template-selected"); - - if($this.attr("id") != "create-new") - { - $("#set-active").button("option","disabled", false); - } - - // Put form html into exp-content frame - FileMgr.get(FileMgr.getTemplateFormPath(), function(data) { - - renderTemplateForm(data); - attachTemplateFormEventHandlers(); - - if(isReloadActive) - { - // Update templates object with new data (so oldname is fixed on next run) - FileMgr.getJSON(FileMgr.getActivePath(),showTemplates); - } - - }); -} - -function renderTemplateForm(data) -{ - var templateId; - if($(".template-selected").attr("id") == "create-new") - { - templateId = "Empty"; - } - else - { - templateId = $(".template-selected").attr("id"); - } - - $("#exp-content").html(data); - $("#template-name").val(templateId); - $("#category-selector").tabs(); - - // Enable buttons to select between 2-cat and 1-cat IAT - $( "#IAT-type" ).buttonset(); - // set initial value from template - if(templates[templateId].IATtype == "two") - { - $("#IAT-standard").attr("checked",true); - $("#IAT-type").buttonset('refresh'); - } - else - { - $("#IAT-single").attr("checked",true); - $("#IAT-type").buttonset('refresh'); - } - // Change on click - $( "#IAT-type :radio" ).click(function(e) { - $( "#IAT-type :radio" ).attr("checked",false); - $(this).attr("checked",true); - }); - // Hide IAT type until IAT is ready for it - $( "#IAT-type").hide(); - - // Enable buttons for showing results at end or not - $( "#show-results" ).buttonset(); - if(templates[templateId].showResult == "show") - { - $("#show").attr("checked",true); - $("#show-results").buttonset('refresh'); - } - else - { - $("#noshow").attr("checked",true); - $("#show-results").buttonset('refresh'); - } - // Change on click - $( "#show-results :radio" ).click(function(e) { - $( "#show-results :radio" ).attr("checked",false); - $(this).attr("checked",true); - }); - - var categoryTabs = $("#category-list a"); - for(var j=1; j<5; j++) - { - // create references - tabname = "tabs" + j; - catname = catlistnames[j-1]; - - // Update category tab with name - $(categoryTabs.get(j - 1)).html(templates[templateId][catname].label); - - // Set up Category Tab - $( "#"+tabname+"-toi-selector" ).buttonset(); - - // Change from img to text on click - $( "#"+tabname+"-toi-selector :radio" ).click(function(e) { - idx = parseInt($(this).attr("id").slice(-5,-4)); - tabname = "tabs" + idx; - catname = catlistnames[idx-1]; - $( "#"+tabname+"-toi-selector :radio" ).attr("checked",false); - - if($(this).attr("id").slice(-3) == "txt") - { - $(this).attr("checked",true); - $(".img-item-"+catname).hide(); - } - else - { - $(this).attr("checked",true); - $(".img-item-"+catname).show(); - updateImages(idx); - } - $('#'+tabname+'-toi-selector').buttonset('refresh') - }); - - // add category label name - $("#"+tabname+"-catlabel-input").val(templates[templateId][catname].label); - - // add data label name - $("#"+tabname+"-datalabel-input").val(templates[templateId][catname].datalabel); - - // Show options for each tab - for (var i=0; i"; - // preview - if(templates[templateId][catname].itemtype == "txt") - { - itemstring += ""; - } - else - { - itemstring += ""; - } - // input for filename - itemstring += ""; - itemstring += ""; - $("#"+tabname+"-catitems").append(itemstring); - } - itemstring = ""; - $("#"+tabname+"-catitems").append(itemstring); - - itemstring = "
    "; - $("#"+tabname+"-catitems").append(itemstring); - - // update images button - itemstring = ""; - $("#"+tabname+"-catitems").append(itemstring); - - // decide if showing or not - if(templates[templateId][catname].itemtype == "txt") - { - // Set text / image selection - $("#"+tabname+"-txt").attr('checked', "checked"); - $("#"+tabname+"-toi-selector").buttonset('refresh'); - $(".img-item-"+catname).hide(); - } - else - { - // Set text / image selection - $("#"+tabname+"-img").attr('checked', "checked"); - $("#"+tabname+"-toi-selector").buttonset('refresh'); - $(".img-item-"+catname).show(); - } - - } - - if($(".template-selected").attr("id") == "create-new") - { - $("#template-name").val("").focus(); - } -} - -function attachTemplateFormEventHandlers() -{ - $("input[type=button]").button(); - - // Listen for changes to template to update templates object - $("#template-form input").unbind("change").on("change",updateTemplateState); - - // Event handler for save icon in template viewer - $("#save-template").unbind("click").click(function() { - saveTemplate(repaintTemplates,showSaveError) - }); - - // Event hook to update category tab labels with category - $("#category-list a").hookToInput(".catlabel-input"); - - // Event hook to update template viewer labels when template name changes - $(".template-selected .template-item-label").hookToInput(function(x) { - return "#template-name"; - }); -} - -function repaintTemplates() -{ - var templateName = $("#template-name").val(); - - - if($(".template-selected").attr("id") == "create-new") - { - $(".template-selected").removeClass("template-selected"); - $("#exp-content").empty(); - } - else - { - $(".template-selected").attr("id",templateName) - .data("templateid",templateName); - } - - //update images - for(var j=1; j<5; j++) - { - tabname = "tabs" + j; - // clear errors - $("#"+tabname + "-catitems > div.catitem").removeClass("erroritem"); - - if ($("#tabs"+j+"-toi-selector :radio:checked").attr("id") == "tabs"+j+"-img") - { - // update images - catitemimgs = $("#"+tabname + "-catitems > div.catitem > img"); - catitemtxts = $("#"+tabname + "-catitems > div.catitem > input:text"); - for (var imgidx=0; imgidxTemplate saved", - modal: true, - buttons: { - Ok: function() { - $( this ).dialog( "close" ); - } - } - }); - });*/ -} - -function showSaveError(data) -{console.log(data); - /*res = eval('('+data+')'); - $("#alert-window").html("
      "+res['errors']+"
    "); - for(var j=1; j<5; j++) - { - tabname = "tabs" + j; - if ($("#tabs"+j+"-toi-selector :radio:checked").attr("id") == "tabs"+j+"-img") - { - // update images - catitemimgs = $("#"+tabname + "-catitems > div.catitem > img"); - filesrcs = res['images'][tabname].split(","); - numitems = filesrcs.length; - // put image sources in files - for (var imgidx=0; imgidxProblems with template", - modal: true, - buttons: { - Ok: function() { - $( this ).dialog( "close" ); - } - } - }); - });*/ -} - -function updateTemplateState(e) -{ - var currTemplateObj = $(".template-selected"); - - if(!currTemplateObj.hasClass("template-unsaved")) - { - // Subtle hint: CSS (.template-unsaved .template-item-label:after) appends "*" to template name - currTemplateObj.data("ischanged", true) - .addClass("template-unsaved"); - - // Subtle hint: add save icon to template viewer item - var baseHtml = currTemplateObj.html(); - currTemplateObj.html(baseHtml + ""); - } -} - -function addItem(catnum) -{ - if($(".template-selected").attr("id") == "create-new") - { - var templateId = "Empty"; - } - else - { - var templateId = $(".template-selected").attr("id"); - } - tabname = "tabs" + catnum; - catname = catlistnames[catnum-1]; - var lastitem = $("#max-"+catname).prev(); - var lasttext = lastitem.children("input:text").attr("id"); - var idx = parseInt(lasttext.slice(-5,-4)) + 1; - - itemstring = "
    "; - // delete button - itemstring += ""; - // preview - itemstring += ""; - // input for filename - itemstring += ""; - itemstring += "
    "; - $("#max-"+catname).before(itemstring); - // check currently selected option - if($("#"+tabname+"-toi-selector :radio:checked").attr("id") == tabname+"-txt") - { - $(".img-item-"+catname).hide() - } - // update maximum number of items - $("#max-"+catname).val(idx); -} - -function updateImages(catidx) -{ - if($(".template-selected").attr("id") == "create-new") - { - var templateId = "Empty"; - } - else - { - var templateId = $(".template-selected").attr("id"); - } - tabname = "tabs" + catidx; - catname = catlistnames[catidx-1]; - - // clear errors - $("#"+tabname + "-catitems > div.catitem").removeClass("erroritem"); - - // get file sources from input fields - catitemtxts = $("#"+tabname + "-catitems > div.catitem > input:text"); - imgsources = [] - for (var imgidx=0; imgidx div.catitem > img"); - filesrcs = data.split(","); - if (filesrcs.length == catitemimgs.length - 1) - { - // put image sources in files - for (var imgidx=0; imgidxActive Template Updated", - modal: true, - buttons: { - Ok: function() { - $( this ).dialog( "close" ); - } - } - }); - } - else if(data.slice(0,5) == "Error") - { - alert(data); - } - }); - -} - -function saveTemplate(successCallback, errorCallback) -{ - var templateId, oldName; - if($(".template-selected").attr("id") == "create-new") - { - templateId = $("#template-name").val(); - oldName = "Empty"; - } - else - { - templateId = $("#template-name").val(); - oldName = templates[$(".template-selected").data("templateid")].name; - } - var formString = $("form").serialize(); - // console.log(formString); - - FileMgr.post(FileMgr.getFileMgrPath(), - { "op": "saveTemplate", "template": templateId, "oldname": oldName, "form": formString}, - function(saveData) { - if (saveData == "success") - { - // Remove save icon from unsaved template viewer item - clearUnsavedTemplate(); - - clearUnsavedChangesFromPrevious(); - - $(".template-selected") - .data("templateid",templateId) - .attr("id",templateId); - - // Update template object with saved data - FileMgr.getJSON(FileMgr.getInputPath(templateId), function(templateData) - { - templates[templateId] = templateData; - successCallback(saveData); - }); - } - else if (saveData.slice(0,5) == "Error") - { - alert(saveData); // Should call errorCallback as well? (Probably) - } - else - { - errorCallback(saveData); - } - }); - -} - -function loadCreateForm() { - // $(".template-selected").removeClass("template-selected"); - $("#set-active").button("option","disabled",true); - // $("#view-stats").attr("disabled","disabled"); - - // selectTemplate(); - - // Make edits to group name live - // $("#group-name-field").ready(function() { - // $("#group-name-field").keyup(changeGroupName); - // }); -} - -function loadActiveStats(input) -{ - $(".exp-header-active").html(input.active); - - // Get completed output - // $.getJSON("core/fileManager.php", - // {"op":"getstats","root":input.root,"output":input.output}, - // buildStatsPage); -} - -function viewStats() { - // Get selected template - - // Verify data for template exists - - // Build stats page -} - - -function buildStatsPage(input) -{ - - // Number completed - - // Bar chart - - // Aggregate & Save button - - // Change active IAT +var templates = {}; +var catlistnames = ["catA","catB","cat1","cat2"]; +var catfullnames = ["Category A","Category B","Category 1","Category 2"]; + +$.fn.hookToInput = function(selector) +{ + if(typeof selector == "string") + { + selector = $(selector); + } + + this.each(function(i) + { + var $this = $(this); + var assocInput = $($.isFunction(selector) ? selector($this) + : selector.get(i)); + + assocInput.keyup(function() + { + $this.html(assocInput.val() || "[Untitled]"); + }); + }); +} + +$.fn.toSerializedJSON = function() +{ + var $this = $(this); + var params = $this.serialize().split("&"); + var json = "{"; + + for(var i = 0, l = params.length; i 0; + + /* If current template has unsaved changes, prompt user to + * save before closing. + * + * Store unsaved data in cookies to prompt user with on + * return to experimenter + */ + if(hasUnsavedTemplate) + { + var templateId = $(".template-selected").data("templateid"); + $.cookie("unsaved_templateid",templateId); + $.cookie("unsaved_data",$("#template-form").toSerializedJSON()); + + return "Note: You have unsaved changes to " + templateId + "."; + } +} + +function showUnsavedChangesFromPrevious() +{ + var templateId = $.cookie("unsaved_templateid"); + var templateData = $.cookie("unsaved_data"); + if(templateId && templateData) + { + /*$("#alert-window").html("Do you want to recover unsaved changes to " + templateId + "?"); + $("#alert-window").dialog({ + title: "

    Unsaved Changes:" + templateId + "

    ", + modal: true, + buttons: { + Yes: function() + { + $(this).dialog("close"); + }, + No: function() + { + $(this).dialog("close"); + } + } + });*/ + + clearUnsavedChangesFromPrevious(); + } +} + +function clearUnsavedChangesFromPrevious() +{ + // Clear unsaved changes from previous visit + $.removeCookie("unsaved_templateid"); + $.removeCookie("unsaved_data"); +} + +function clearUnsavedTemplate() +{ + var unsavedTemplate = $(".template-unsaved"); + + unsavedTemplate.find(".save-item").remove(); + unsavedTemplate.data("ischanged", false) + .removeClass("template-unsaved"); +} + +function renderTemplateViewerItem(templateId) +{ + // Update :: added data-templateid attribute to avoid + // errors resulting from selecting .template-item elements + // with illegal characters in ID attribute + + $(".active-selector").append("
    " + templateId + "
    "); +} + +function showTemplates(input) +{ + // Save currently selected template (if any) + var currTemplateId = $("#template-name").val(); + + // Removes previously created DOM for templates + // before updating with new content + $(".user-template").remove(); + + var numTemplates = input.available.length; + var numTemplatesLoaded = 0; + + // Generate DOM elements for each template in + // .selector-frame and populate templates object + for (var template in input.available) + { + if(input.available[template] != "Empty") + { + renderTemplateViewerItem(input.available[template]); + } + + // Retrieve current template configuration from external resource + FileMgr.getJSON(FileMgr.getInputPath(input.available[template]), function(data) + { + templates[data["name"]] = data; + + numTemplatesLoaded++; + if(numTemplatesLoaded == numTemplates) + { + readyTemplates(input); + } + }); + } + + // Re-attach .template-selected class to current template + var currTemplateObj = $(".template-item[data-templateid='" + currTemplateId + "']"); + if(currTemplateObj.length > 0) + { + currTemplateObj.addClass("template-selected"); + } + + // Attach event handler for changing templates + $(".template-item").unbind("click").click(selectTemplate); +} + + +function verifyDelete(templateId) +{ + if($(".exp-header-active").html() == templateId) + { + $( "#alert-window" ).html(templateId+" is currently active. Please make another template active before deleting this template."); + $( "#alert-window" ).dialog({ + title: "

    Template Currently Active

    ", + modal: true, + buttons: { + Ok: function() { + $( this ).dialog( "close" ); + } + } + }); + } + else + { + $( "#alert-window" ).html("
    Are you sure you want to delete template '"+templateId+"'? This will delete all associated files, including existing data!!
    "); + $( "#alert-window" ).dialog({ + title: "

    Confirm Delete

    ", + modal: true, + buttons: { + Delete: function() { + FileMgr.post(FileMgr.getFileMgrPath(), {"op":"deleteTemplate", "template":templateId}, function(data) { + if (data.slice(0,5) == "Error") + { + alert(data); + } + else + { + $("#exp-content").empty(); + FileMgr.getJSON(FileMgr.getActivePath(),showTemplates); + } + }); + $(this).dialog("close"); + }, + Cancel: function() { + $(this).dialog("close"); + } + } + }); + } +} + +function selectTemplate(e) +{ + var $this = $(this); + + // Prevent reloading of current template so + // altered data not overwritted + if(!$this.hasClass("template-selected")) { + // Prompt user to save changes to active template + // before changing to selected template + var currTemplateObj = $(".template-selected"); + var currTemplate = currTemplateObj.text(); + + // If new, unsaved template, adjust its title + if(currTemplateObj.attr("id") == "create-new") + { + currTemplate = ($("#template-name").val() != "Empty") ? $("#template-name").val() + : "Untitled"; + } + + if(currTemplateObj.hasClass("template-unsaved")) + { + $("#alert-window").html("Do you want to save changes to \"" + currTemplate +"\"?") + .dialog({ + title: "

    Unsaved Changes

    ", + modal: true, + close: clearUnsavedTemplate, + buttons: { + Save: function() + { + saveTemplate(function(data) + { + repaintTemplates(data); + changeTemplate({ + templateObj: $this, + isReloadActive: true + }); + $("#alert-window").dialog("close"); // Note the closure :: $(this) != $("#alert-window") + },showSaveError); + }, + Discard: function() + { + currTemplateObj.find(".template-item-label").html(currTemplateObj.data("templateid")); // Restore original template name + changeTemplate({ + templateObj: $this, + isReloadActive: false + }); + $(this).dialog("close"); + } + } + }); + } + else + { + changeTemplate({ + templateObj: $this, + isReloadActive: false + }); + } + } +} + +function changeTemplate(options) +{ + // isReloadActive indicates whether template inputs should + // be redownloaded with updates + isReloadActive = options.isReloadActive || false; + var $this = options.templateObj; + + // Change selected template + $(".template-selected").removeClass("template-selected"); + $this.addClass("template-selected"); + + if($this.attr("id") != "create-new") + { + $("#set-active").button("option","disabled", false); + } + + // Put form html into exp-content frame + FileMgr.get(FileMgr.getTemplateFormPath(), function(data) { + + renderTemplateForm(data); + attachTemplateFormEventHandlers(); + + if(isReloadActive) + { + // Update templates object with new data (so oldname is fixed on next run) + FileMgr.getJSON(FileMgr.getActivePath(),showTemplates); + } + + }); +} + +function renderTemplateForm(data) +{ + var templateId; + if($(".template-selected").attr("id") == "create-new") + { + templateId = "Empty"; + } + else + { + templateId = $(".template-selected").attr("id"); + } + + $("#exp-content").html(data); + $("#template-name").val(templateId); + $("#category-selector").tabs(); + + // Enable buttons to select between 2-cat and 1-cat IAT + $( "#IAT-type" ).buttonset(); + // set initial value from template + if(templates[templateId].IATtype == "two") + { + $("#IAT-standard").attr("checked",true); + $("#IAT-type").buttonset('refresh'); + } + else + { + $("#IAT-single").attr("checked",true); + $("#IAT-type").buttonset('refresh'); + } + // Change on click + $( "#IAT-type :radio" ).click(function(e) { + $( "#IAT-type :radio" ).attr("checked",false); + $(this).attr("checked",true); + }); + // Hide IAT type until IAT is ready for it + $( "#IAT-type").hide(); + + // Enable buttons for showing results at end or not + $( "#show-results" ).buttonset(); + if(templates[templateId].showResult == "show") + { + $("#show").attr("checked",true); + $("#show-results").buttonset('refresh'); + } + else + { + $("#noshow").attr("checked",true); + $("#show-results").buttonset('refresh'); + } + // Change on click + $( "#show-results :radio" ).click(function(e) { + $( "#show-results :radio" ).attr("checked",false); + $(this).attr("checked",true); + }); + + var categoryTabs = $("#category-list a"); + for(var j=1; j<5; j++) + { + // create references + tabname = "tabs" + j; + catname = catlistnames[j-1]; + + // Update category tab with name + $(categoryTabs.get(j - 1)).html(templates[templateId][catname].label); + + // Set up Category Tab + $( "#"+tabname+"-toi-selector" ).buttonset(); + + // Change from img to text on click + $( "#"+tabname+"-toi-selector :radio" ).click(function(e) { + idx = parseInt($(this).attr("id").slice(-5,-4)); + tabname = "tabs" + idx; + catname = catlistnames[idx-1]; + $( "#"+tabname+"-toi-selector :radio" ).attr("checked",false); + + if($(this).attr("id").slice(-3) == "txt") + { + $(this).attr("checked",true); + $(".img-item-"+catname).hide(); + } + else + { + $(this).attr("checked",true); + $(".img-item-"+catname).show(); + updateImages(idx); + } + $('#'+tabname+'-toi-selector').buttonset('refresh') + }); + + // add category label name + $("#"+tabname+"-catlabel-input").val(templates[templateId][catname].label); + + // add data label name + $("#"+tabname+"-datalabel-input").val(templates[templateId][catname].datalabel); + + // Show options for each tab + for (var i=0; i"; + // preview + if(templates[templateId][catname].itemtype == "txt") + { + itemstring += ""; + } + else + { + itemstring += ""; + } + // input for filename + itemstring += ""; + itemstring += ""; + $("#"+tabname+"-catitems").append(itemstring); + } + itemstring = ""; + $("#"+tabname+"-catitems").append(itemstring); + + itemstring = "
    "; + $("#"+tabname+"-catitems").append(itemstring); + + // update images button + itemstring = ""; + $("#"+tabname+"-catitems").append(itemstring); + + // decide if showing or not + if(templates[templateId][catname].itemtype == "txt") + { + // Set text / image selection + $("#"+tabname+"-txt").attr('checked', "checked"); + $("#"+tabname+"-toi-selector").buttonset('refresh'); + $(".img-item-"+catname).hide(); + } + else + { + // Set text / image selection + $("#"+tabname+"-img").attr('checked', "checked"); + $("#"+tabname+"-toi-selector").buttonset('refresh'); + $(".img-item-"+catname).show(); + } + + } + + if($(".template-selected").attr("id") == "create-new") + { + $("#template-name").val("").focus(); + } +} + +function attachTemplateFormEventHandlers() +{ + $("input[type=button]").button(); + + // Listen for changes to template to update templates object + $("#template-form input").unbind("change").on("change",updateTemplateState); + + // Event handler for save icon in template viewer + $("#save-template").unbind("click").click(function() { + saveTemplate(repaintTemplates,showSaveError) + }); + + // Event hook to update category tab labels with category + $("#category-list a").hookToInput(".catlabel-input"); + + // Event hook to update template viewer labels when template name changes + $(".template-selected .template-item-label").hookToInput(function(x) { + return "#template-name"; + }); +} + +function repaintTemplates() +{ + var templateName = $("#template-name").val(); + + + if($(".template-selected").attr("id") == "create-new") + { + $(".template-selected").removeClass("template-selected"); + $("#exp-content").empty(); + } + else + { + $(".template-selected").attr("id",templateName) + .data("templateid",templateName); + } + + //update images + for(var j=1; j<5; j++) + { + tabname = "tabs" + j; + // clear errors + $("#"+tabname + "-catitems > div.catitem").removeClass("erroritem"); + + if ($("#tabs"+j+"-toi-selector :radio:checked").attr("id") == "tabs"+j+"-img") + { + // update images + catitemimgs = $("#"+tabname + "-catitems > div.catitem > img"); + catitemtxts = $("#"+tabname + "-catitems > div.catitem > input:text"); + for (var imgidx=0; imgidxTemplate saved", + modal: true, + buttons: { + Ok: function() { + $( this ).dialog( "close" ); + } + } + }); + });*/ +} + +function showSaveError(data) +{console.log(data); + /*res = eval('('+data+')'); + $("#alert-window").html("
      "+res['errors']+"
    "); + for(var j=1; j<5; j++) + { + tabname = "tabs" + j; + if ($("#tabs"+j+"-toi-selector :radio:checked").attr("id") == "tabs"+j+"-img") + { + // update images + catitemimgs = $("#"+tabname + "-catitems > div.catitem > img"); + filesrcs = res['images'][tabname].split(","); + numitems = filesrcs.length; + // put image sources in files + for (var imgidx=0; imgidxProblems with template", + modal: true, + buttons: { + Ok: function() { + $( this ).dialog( "close" ); + } + } + }); + });*/ +} + +function updateTemplateState(e) +{ + var currTemplateObj = $(".template-selected"); + + if(!currTemplateObj.hasClass("template-unsaved")) + { + // Subtle hint: CSS (.template-unsaved .template-item-label:after) appends "*" to template name + currTemplateObj.data("ischanged", true) + .addClass("template-unsaved"); + + // Subtle hint: add save icon to template viewer item + var baseHtml = currTemplateObj.html(); + currTemplateObj.html(baseHtml + ""); + } +} + +function addItem(catnum) +{ + if($(".template-selected").attr("id") == "create-new") + { + var templateId = "Empty"; + } + else + { + var templateId = $(".template-selected").attr("id"); + } + tabname = "tabs" + catnum; + catname = catlistnames[catnum-1]; + var lastitem = $("#max-"+catname).prev(); + var lasttext = lastitem.children("input:text").attr("id"); + var idx = parseInt(lasttext.slice(-5,-4)) + 1; + + itemstring = "
    "; + // delete button + itemstring += ""; + // preview + itemstring += ""; + // input for filename + itemstring += ""; + itemstring += "
    "; + $("#max-"+catname).before(itemstring); + // check currently selected option + if($("#"+tabname+"-toi-selector :radio:checked").attr("id") == tabname+"-txt") + { + $(".img-item-"+catname).hide() + } + // update maximum number of items + $("#max-"+catname).val(idx); +} + +function updateImages(catidx) +{ + if($(".template-selected").attr("id") == "create-new") + { + var templateId = "Empty"; + } + else + { + var templateId = $(".template-selected").attr("id"); + } + tabname = "tabs" + catidx; + catname = catlistnames[catidx-1]; + + // clear errors + $("#"+tabname + "-catitems > div.catitem").removeClass("erroritem"); + + // get file sources from input fields + catitemtxts = $("#"+tabname + "-catitems > div.catitem > input:text"); + imgsources = [] + for (var imgidx=0; imgidx div.catitem > img"); + filesrcs = data.split(","); + if (filesrcs.length == catitemimgs.length - 1) + { + // put image sources in files + for (var imgidx=0; imgidxActive Template Updated", + modal: true, + buttons: { + Ok: function() { + $( this ).dialog( "close" ); + } + } + }); + } + else if(data.slice(0,5) == "Error") + { + alert(data); + } + }); + +} + +function saveTemplate(successCallback, errorCallback) +{ + var templateId, oldName; + if($(".template-selected").attr("id") == "create-new") + { + templateId = $("#template-name").val(); + oldName = "Empty"; + } + else + { + templateId = $("#template-name").val(); + oldName = templates[$(".template-selected").data("templateid")].name; + } + var formString = $("form").serialize(); + // console.log(formString); + + FileMgr.post(FileMgr.getFileMgrPath(), + { "op": "saveTemplate", "template": templateId, "oldname": oldName, "form": formString}, + function(saveData) { + if (saveData == "success") + { + // Remove save icon from unsaved template viewer item + clearUnsavedTemplate(); + + clearUnsavedChangesFromPrevious(); + + $(".template-selected") + .data("templateid",templateId) + .attr("id",templateId); + + // Update template object with saved data + FileMgr.getJSON(FileMgr.getInputPath(templateId), function(templateData) + { + templates[templateId] = templateData; + successCallback(saveData); + }); + } + else if (saveData.slice(0,5) == "Error") + { + alert(saveData); // Should call errorCallback as well? (Probably) + } + else + { + errorCallback(saveData); + } + }); + +} + +function loadCreateForm() { + // $(".template-selected").removeClass("template-selected"); + $("#set-active").button("option","disabled",true); + // $("#view-stats").attr("disabled","disabled"); + + // selectTemplate(); + + // Make edits to group name live + // $("#group-name-field").ready(function() { + // $("#group-name-field").keyup(changeGroupName); + // }); +} + +function loadActiveStats(input) +{ + $(".exp-header-active").html(input.active); + + // Get completed output + // $.getJSON("core/fileManager.php", + // {"op":"getstats","root":input.root,"output":input.output}, + // buildStatsPage); +} + +function viewStats() { + // Get selected template + + // Verify data for template exists + + // Build stats page +} + + +function buildStatsPage(input) +{ + + // Number completed + + // Bar chart + + // Aggregate & Save button + + // Change active IAT } \ No newline at end of file diff --git a/experimenter.php b/experimenter.php index ce35548..20366c9 100644 --- a/experimenter.php +++ b/experimenter.php @@ -1,36 +1,37 @@ - - -IAT Experimenter Page - - - - - - - - - - - -
    -
    -
    Active:
    -
    None
    -
    -
    -
    Templates
    -
    -
    - [New Template] -
    -
    -
    - - -
    -
    -
    -
    + + + +IAT Experimenter Page + + + + + + + + + + + +
    +
    +
    Active:
    +
    None
    +
    +
    +
    Templates
    +
    +
    + [New Template] +
    +
    +
    + + +
    +
    +
    +
    \ No newline at end of file