Changeset 185


Ignore:
Timestamp:
12/15/11 17:09:49 (13 years ago)
Author:
fpvanagthoven
Message:
 
Location:
Dev/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/Toolbox.php

    r177 r185  
    1616
    1717        <br />
    18        
     18
    1919        <div id="toolbox" class="largeFrame">
    2020            <div class="largeTitle">Toolbox</div>
    2121            <div class="content">
    2222                <p style="float: left; clear:both; margin-bottom: 1em;">Add new:</p>
    23                 <div class="bigButton vert" onClick="SubmitToolbox('Survey');"><img src="images/icons/survey.png" class="buttonIcon" /><p>Survey</p></div>
    24                 <div class="bigButton vert" onClick="SubmitToolbox('Application');"><img src="images/icons/application.png" class="buttonIcon" /><p>Application</p></div>
    25                 <div class="bigButton vert" onClick="SubmitToolbox('Dashboard');"><img src="images/icons/dashboard.png" class="buttonIcon" /><p>Dashboard</p></div>
     23                <div class="bigButton toolbox" onClick="submitToolbox('Survey');"><img src="images/icons/survey.png" class="buttonIcon" /><p>Survey</p></div>
     24                <div class="bigButton toolbox" onClick="submitToolbox('Application');"><img src="images/icons/application.png" class="buttonIcon" /><p>Application</p></div>
     25                <div class="bigButton toolbox" onClick="submitToolbox('Dashboard');"><img src="images/icons/dashboard.png" class="buttonIcon" /><p>Dashboard</p></div>
    2626            </div>
    2727        </div>
    28        
    29        
    30         <!--
    31         <form name="toolbox" action="pipelineEditor.php" method="POST">
    32             <fieldset id="toolbox">
    33                 <div class="fieldsetTitle">Toolbox</div>
    34                 <p>Add new: </p>
    35                 <div class="creationButton" onClick="SubmitToolbox('Survey');"><img src="images/icons/survey.png" class="buttonIcon"/><p>Survey</p></div>
    36                 <div class="creationButton" onClick="SubmitToolbox('Application');"><img src="images/icons/application.png" class="buttonIcon"/><p>Application</p></div>
    37                 <div class="creationButton" onClick="SubmitToolbox('Dashboard');"><img src="images/icons/dashboard.png" class="buttonIcon"/><p>Dashboard</p></div>
    38             </fieldset>
    39         </form>
    40        
    41         -->
    4228        <?php
    4329    }
  • Dev/trunk/classes/pipelineSequencer.php

    r181 r185  
    8181        <script type="text/javascript">
    8282            $(document).ready(function() {
    83                 loadSequencer();      // true means it is the first refresh of the page.
     83                loadSequencer();
    8484            });
    8585        </script>
     
    8787    }
    8888
    89     public function LoadSession($currentSession) {   // Initialize variables on page load.
    90         if (!isset($currentSession)) {
     89    public function LoadSession() {   // Initialize variables on page load.
     90        // Redirect if no session is set
     91        if (!isset($_SESSION['currentSession'])) {
    9192            redirect("selectSession.php");
    9293        }
    93         if (isset($_SESSION['updateNeeded'])) {    // user has performed an operation that flags session to be reloaded from DB, or is first load of page for that session
    94             $sessionResults = $this->dbi->get("Session", array("uid" => $currentSession));
    95 
    96             if (count($sessionResults) > 0) {
    97                 $_SESSION['localSessionCopy'] = $sessionResults[0];
    98                 unset($_SESSION['updateNeeded']);
    99             } else {
    100                 die("No session with that UID found!");
    101             }
     94        // Store the current session in internal variable
     95        $results = $this->dbi->get("Session", array("uid"=> $_SESSION['currentSession']));
     96        if (!empty($results)) {
     97            (is_array($results)) ? $this->loadedSession = $results[0] : $this->loadedSession = $results;
    10298        }
    103 
    104         if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) {
    105 
    106             $this->loadedSession = $_SESSION['localSessionCopy'];
    107             unset($_SESSION['updateNeeded']);
     99        else {
     100            // Throw error and quit if no results found
     101            die("No session with that UID found!");
    108102        }
    109103    }
    110104
    111105    public function HandlePostData() {
    112         if (isset($_POST['editSelected'])) {
    113             if (isset($_POST['selectedStep']) && !empty($_POST['selectedStep'])) {
    114                 redirect("editredirect.php");
    115             }
    116         }
    117 
    118         if (isset($_POST['moveSelectedLeft'])) {
    119             if (isset($_POST['selectedStep']) && !empty($_POST['selectedStep'])) {
    120                 $this->MoveStep($_POST['selectedStep'], -1);
    121             }
    122         }
    123 
    124         if (isset($_POST['moveSelectedRight'])) {
    125             if (isset($_POST['selectedStep']) && !empty($_POST['selectedStep'])) {
    126                 $this->MoveStep($_POST['selectedStep'], 1);
    127             }
    128         }
    129 
    130         if (isset($_POST['objectToCreate']) && !empty($_POST['objectToCreate'])) {
    131             switch (strtolower($_POST['objectToCreate'])) {
    132                 case "survey":
    133                     redirect("createsurvey.php");
    134                     break;
    135                 case "application":
    136                     redirect("createapplication.php");
    137                     break;
    138                 case "dashboard":
    139                     redirect("createdashboard.php");
    140                     break;
    141                 default:
    142                     // Er is iets fout gegaan, want er is geen valid type meegegeven!
    143                     break;
    144             }
    145         }
     106               
    146107    }
    147108
  • Dev/trunk/classes/surveyEditorWidget.php

    r182 r185  
    1212class surveyEditorWidget {
    1313
    14     private $loadedSession;
     14    private $loadedSurvey;
     15    private $dbi;
    1516
    1617    public function __construct() {
    1718        // Set basic variables
    1819        // Should probably include a default empty survey for the sake of safety
     20        $dbi = new DatabaseInterface();
    1921    }
    2022
    2123    public function handlePost() {
    2224        // Get POSTed data and store variables to class instance properties
    23         // Most important: loadedSession!
    24 
    25         //var_dump($_POST);
    26 
    2725        $dbi = new DatabaseInterface();
    2826        if (isset($_POST['objectUid']) && !empty($_POST['objectUid'])) {
    2927            $surveyResults = $dbi->get("Survey", array("uid" => $_POST['objectUid']));
    30             if (count($surveyResults) > 0) {
    31                 $this->loadedSurvey = $surveyResults[0];
     28            if (!empty($surveyResults)) {
     29                (is_array($surveyResults)) ? $this->loadedSurvey = $surveyResults[0] : $this->loadedSurvey = $surveyResults;
    3230            } else {
    33                 var_dump("No surveys found!");
     31                die("No surveys found!");
    3432            }
    3533        } else {
    36             var_dump("Incorrect or null uid passed!");
     34            die("Incorrect or null uid passed!");
    3735        }
    3836    }
    3937
    4038    public function init() {
     39        $questionString = "";
     40        foreach ($this->loadedSurvey->questions as $question) {
     41            $questionString .= $question->uid . ",";
     42        }
    4143        // echo the HTML markup to display the editor on the screen
    4244        ?>
    4345
    4446        <div id="surveyEditor" class="largeFrame">
    45             <div class="largeTitle">
    46                 Survey name
     47            <div class="largeTitle" id="surveyTitle">
     48                <?php echo $this->loadedSurvey->title; ?>
    4749            </div>
    48             <div id="surveyEditorContent" class="innerLargeFrame">
     50            <div id="seqContent" class="innerLargeFrame">
     51                <div id="seqContentWrapper">
    4952
    50                 <!--
    51                 <div id="questionUID" class="smallFrame">
    52                     <div class="smallTitle"><div class="listNumber">1</div>#QUESTION-IDENT-NO</div>
    53                     <div class="content">
    54                         <p class="questionBody">
    55                             This is the question body text. This is what the user will read when he is answering the survey.This is the question body text. This is what the user will read when he is answering the survey.This is the question body text. This is what the user will read when he is answering the survey.
    56                         </p>
    57                         <div class="questionParamsView">
    58                             PARAMETERS GO HERE, probably in one line (Only answer type and identifier?) Tags?
    59                         </div>
    60                     </div>
    61                     <div id="questionDisplayControls" class="controls">
    62                         <input type="button" value="Edit" onClick="javascript:alert('editing not yet supported');" class =" smallButton"/>
    63                         <input type="button" value="Remove" onClick="javascript:alert('removing not yet supported');" class =" smallButton"/>
    64                     </div>
    6553                </div>
    66                 -->
    67 
     54            </div>
     55            <div id="surveyEditorVertControls" class="vertControls">
     56                <div class="segment">
     57                    <label>Move</label>
     58                    <input type="button" id="vertControls_MoveUp" class="bigButton vertical" value="˄" />
     59                    <input type="button" id="vertControls_MoveDown" class="bigButton vertical" value="Ë
     60" />
     61                </div>
     62                <input type="button" id="vertControls_Add" class="bigButton vertical" value="+" onClick="addQuestion_Click();" />
    6863            </div>
    6964            <div id="surveyEditorControls" class="controls">
     65                <div id="pageControls">
     66                    <input type="button" value="<<" id="pageControls_first" onClick="" />
     67                    <input type="button" value="<" id="pageControls_previous" onClick="" />
     68                    Page <input type="text" value="1" id="pageControls_current" onChange="" class="smallTextField" /> of 5
     69                    <input type="button" value=">" id="pageControls_next" onClick="" />
     70                    <input type="button" value=">>" id="pageControls_last" onClick="" />
     71                </div>
     72
    7073                <input type="button" value="Discard survey" onClick="javascript:alert('discard not yet supported');" class="smallButton" />
    7174                <input type="button" value="Save survey" onClick="javascript:alert('save not yet supported');" class="smallButton" />
     
    7578
    7679
    77         <form name="hiddenFields">
    78             <input type="hidden" id="surveyUid" value="<?php echo $this->loadedSurvey->uid; ?>" />
    79             <input type="hidden" id="questionUids" value="<?php echo $this->loadedSurvey->questions; ?>" />
    80             <input type="hidden" id="surveyTitle" value="<?php echo $this->loadedSurvey->title; ?>" />
    81             <input type="hidden" id="numQuestions" value="<?php echo count($this->loadedSurvey->questions); ?>" />
    82             <input type="hidden" id="surveyDescription" value="<?php echo $this->loadedSurvey->description; ?>" />
     80        <form id="hiddenInputs">
     81            <input type="hidden" id="surveyUidField" value="<?php echo $this->loadedSurvey->uid; ?>" />
     82            <input type="hidden" id="questionUidsField" value="<?php echo $questionString ?>" />
     83            <input type="hidden" id="surveyTitleField" value="<?php echo $this->loadedSurvey->title; ?>" />
     84            <input type="hidden" id="numQuestionsField" value="<?php echo count($this->loadedSurvey->questions); ?>" />
     85            <input type="hidden" id="surveyDescriptionField" value="<?php echo $this->loadedSurvey->description; ?>" />
    8386        </form>
    8487
     
    9093        // output the javascript tags and needed functions in the head of the page
    9194        ?>
    92         <script type="text/javascript" src="js/surveyEditorScripts.js"></script>
     95        <script type="text/javascript" src="js/sequencerScripts.js"></script>
     96        <script type="text/javascript" src="js/generalscripts.js"></script>
    9397        <script type="text/javascript" src="js/jquery.js"></script>
    9498        <script type="text/javascript">
    9599            $(document).ready(function() {
    96                 loadSurvey();
     100                loadSequencer();
    97101            });
    98102        </script>
  • Dev/trunk/createObject.php

    r166 r185  
    66    if (!empty($_POST['objectToCreate'])) {
    77        $otc = $_POST['objectToCreate'];
    8     }
    9     else {
     8    } else {
    109        //die ("Invalid arguments passed!");
    1110    }
    12 }
    13 else {
     11} else {
    1412    //die ("No arguments passed!");
    1513}
    1614
    1715$dbi = new DatabaseInterface();
    18 $creator_results = $dbi->get("User", array("name"=>$_SESSION['username']));
     16$creator_results = $dbi->get("User", array("name" => $_SESSION['username']));
    1917if (count($creator_results) > 0) {
    2018    $creator = $creator_results[0];
    21 }
    22 else {
    23     //die ("Invalid creator, make sur0e you are logged in!");
     19} else {
     20    //die ("Invalid creator, make sure you are logged in!");
    2421}
    2522
     
    3936        //TODO
    4037        break;
     38    case "question":
     39        $newQuestion = new Question(null, "new Question", "int", "Default description", "Standard category", array());
     40        $dbi->set($newQuestion);
     41        $uid = $newQuestion->uid;
     42        break;
    4143    default:
    4244        //die ("Variable \$otc: $otc does not match a compatible object type!");
     
    4547
    4648echo $uid;
    47 
    4849?>
  • Dev/trunk/css/visualeditors.css

    r184 r185  
    141141}
    142142
     143.smallFrame.selected .smallTitle {
     144    background-color: #FF0000;
     145}
     146
    143147.largeTitle {
    144148    width: auto;
     
    151155
    152156.smallTitle {
     157    background-color: transparent;
    153158    width: auto;
    154159    min-height: 1.5em;
     
    170175    float: right;
    171176    min-height: 2.5em;
    172 }
    173 
    174 .questionBody {
    175     float: left;
    176     clear: left;
    177     margin: 1em 0;
    178     font-style: italic;
    179 }
    180 
    181 .questionParamsView {
    182     float: left;
    183     clear: left;
    184     border: 1px solid #555;
    185     padding: 0.5em;
    186     font-weight: bold;
    187177}
    188178
     
    201191}
    202192
     193.bigButton.vertical {
     194    width: 2em;
     195    height: 2em;
     196    font-size: 20px;
     197    font-weight: bold;
     198    color: #555;
     199    float: left;
     200    clear: both;
     201    border: 1px solid #555;
     202    border-radius: 0.25em;
     203    -moz-border-radius: 0.25em;
     204    background-color: transparent;
     205    -webkit-user-select: none;
     206    -khtml-user-select: none;
     207    -moz-user-select: none;
     208    -o-user-select: none;
     209    user-select: none;
     210    cursor: default;
     211}
     212
    203213.bigButton:hover {
    204214    border-color: #1c94c4;
     
    208218.bigButton .buttonIcon {
    209219
    210 }
    211 
    212 .bigButton.vert {
    213     clear:both;
    214220}
    215221
     
    254260}
    255261
    256 #seqContentWrapper .divider {
     262#seqContentWrapper .divider.horizontal {
    257263    width: 10px;
    258264    height: 50px;
     
    313319}
    314320
     321.bigButton.toolbox {
     322    clear: both;
     323}
     324
    315325#infoPanel {
    316326    margin-top: 2em;
     
    344354    background-color: #0000FF;
    345355}
     356
     357#seqContentWrapper .divider.vertical {
     358    height: 1px;
     359    width: 200px;
     360    background-color: #FF00FF; /* VIES MAGENTA! */
     361    margin: 1em auto;
     362}
     363
     364.questionBody {
     365    float: left;
     366    clear: left;
     367    margin: 1em 0;
     368    font-style: italic;
     369}
     370
     371.questionParamsView {
     372    float: left;
     373    clear: left;
     374    border: 1px solid #555;
     375    padding: 0.5em;
     376    font-weight: bold;
     377}
     378
     379#pageControls {
     380    float: left;
     381    margin: 5px 200px 0 0;
     382}
     383
     384#pageControls .smallTextField {
     385    width: 1.5em;
     386}
     387
     388.vertControls {
     389    text-align: center;
     390    display:block;
     391    float: left;
     392    clear: right;
     393    margin: 0 0 0 1em;
     394}
     395
     396.vertControls .segment {
     397    margin: 1.25em -1px 0.25em -1px;
     398    border: 1px solid #555;
     399    clear: both;
     400    padding: 1px;
     401    float: left;
     402    border-radius: 5px;
     403}
     404
     405.vertControls label {
     406    width: 100%;
     407    float: left;
     408    clear: both;
     409    font-size: 12px;
     410    text-align: center;
     411    margin: -1.25em 0 0;
     412    color: #555;
     413    font-weight: bold;
     414}
     415
  • Dev/trunk/getInfo.php

    r178 r185  
    2828} else
    2929    return;
     30
     31// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     32// Note: the next part needs to be converted to JSON operation, so that the javascript can easily handle any style changes to the information retrieved. This implementation is just silly.
     33// Basic idea: return a JSON array of property: value pairs, then let javascript loop through these properties and format them suitably. This is both more flexible and easier to adjust, as well as resulting in smaller packets.
     34// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    3035
    3136switch ($type) {
  • Dev/trunk/js/sequencerScripts.js

    r184 r185  
    22 * You can change the type of sequencer by including a hidden input field with id "contentTypeField" in your document.
    33 * The initEditor() method will then adjust internal variables in the sequencer object to match that type of content.
     4 *
     5 * Note: code makes heavy use of shorthand functions:
     6 * ce(var) = document.createElement(var);
     7 * ge(var) = document.getElementById(var);
     8 * Defined in generalscripts.js
    49 */
    510
    611var sequencer = createVarArray();
    712
    8 function SubmitToolbox(type) {
    9     if (sequencer.state.updating == true) return;
    10     sequencer.state.updating = true;
    11     deselectStep();   
    12     var c = "objectToCreate="+type;
    13     var u = "createObject.php";
    14        
    15     newAjaxRequest(c, u, function(result) {
    16         sequencer.session.pipeline.uids.push(removeNL(result.responseText));
    17         sequencer.session.pipeline.types.push(type);
    18         sequencer.session.pipeline.upToDate.push(false);
    19         updateSequencer();
    20     }, true);
    21 }
    22 
    23 function clickStep(uid) {
    24     if (uid == sequencer.state.selectedStep.uid) {  // user deselected a currently selected step.
    25         deselectStep();
    26     }
    27     else {
    28         if (sequencer.state.selectedStep.uid != undefined && sequencer.state.selectedStep.uid != "") {
    29             deselectStep();
    30             selectStep(uid);
    31         }
    32         else {
    33             selectStep(uid);
    34         }       
    35     }
    36 }
    37 
    38 function selectStep(uid) {
    39     var element = document.getElementById(uid);
    40     if (element) {
    41         addClass(element, "selected");
    42         var type = sequencer.session.pipeline.types[sequencer.session.pipeline.uids.indexOf(uid)];
    43         ajaxInfoRequest(uid, document.getElementById("infoPanelContent"), type);
    44         sequencer.state.selectedStep.uid = uid;
    45         sequencer.state.selectedStep.index = null;  //Don't know how to do this yet.
    46     }
    47 }
    48 
    49 function deleteStep() {
    50     // check if a step is selected
    51     if (sequencer.state.selectedStep.uid == null) {
    52         return;
    53     }
    54     var uid = sequencer.state.selectedStep.uid;
    55     // deselect the step to reset the info panel and selection code
    56     deselectStep();
    57     // splice the step's data from the pipeline
    58     var index = sequencer.session.pipeline.uids.indexOf(uid);
    59     if (index >= 0 && index < sequencer.session.pipeline.uids.length) {
    60         sequencer.session.pipeline.uids.splice(index, 1);
    61         sequencer.session.pipeline.types.splice(index, 1);
    62         sequencer.session.pipeline.upToDate.splice(index, 1);
    63         // Then delete the step visually
    64         var element = document.getElementById(uid);
    65         var divider;
    66         if (!element.nextSibling) {
    67             // the element is at the end of the pipeline
    68             // therefore we remove the previous divider.
    69             // Note: it could also be the only element left in the pipeline!
    70             divider = (element.previousSibling) ? element.previousSibling : false;
    71             if (divider != false) {
    72                 divider.parentNode.removeChild(divider);
    73             }
    74         }
    75         else {
    76             // the element is at any position except the last, therefore we remove the next divider
    77             divider = (element.nextSibling) ? element.nextSibling : false;
    78             if (divider != false) {
    79                 divider.parentNode.removeChild(divider);
    80             }
    81         }
    82        
    83         // Finally, remove the element itself.
    84         element.parentNode.removeChild(element);
    85         sequencer.state.numSteps--;
    86        
    87     }
    88 }
    89 
    90 function deselectStep() {
    91     if (!sequencer.state.selectedStep.uid) return;
    92     var element = document.getElementById(sequencer.state.selectedStep.uid);
    93     removeClass(element, "selected");
    94     sequencer.state.selectedStep.uid = null;
    95     sequencer.state.selectedStep.index = null;
    96     var infoPanel = document.getElementById("infoPanelContent");
    97     while (infoPanel.firstChild) infoPanel.removeChild(infoPanel.firstChild);
    98 }
    99 
    100 function ajaxInfoRequest(uid, el, type) {
    101     var c = "uid="+uid;
    102     c += "&type="+type;
    103     var u = "getInfo.php";
    104     newAjaxRequest(c, u, function(result) {
    105         el.innerHTML = result.responseText;
    106     }, true);
    107 }
     13// Basic functions, intialization, updating
     14
     15function createVarArray(){
     16    // Function that returns creates the global variable object, the sequencer's variable storage.
     17   
     18    if (sequencer) delete window.sequencer;
     19    return {   // GLOBAL VAR TO STORE SEQUENCER SETTINGS!
     20        uid: "",                // The unique id of this sequencer (not DB related!). This will help to avoid global var conflicts. Assign this randomly! (STRING)
     21        session: {              // Properties of the currently loaded session
     22            title: "",              // Title or name (STRING)
     23            uid: "",                // Database UID of the current session (STRING)
     24            pipeline: {             // Pipeline
     25                uids: [],               // Uids of objects in pipeline (STRING)
     26                types: [],              // Types of objects in pipeline (STRING)
     27                upToDate: []            // Whether or not object displays are up to date (BOOL)
     28            }
     29        },
     30        survey: {               // Properties of the loaded survey, if applicable (either this or the session tree above is filled in!) [THIS IS NOT CURRENTLY USED AND I SHOULD DELIBERATE ON WHAT VARIABLES TO PUT IN THIS TREE TO MAKE A FUNCTIONAL EDITOR THAT ALSO MATCHES THE DB FORMAT!]
     31            title: "",              // Title or the name of the survey (STRING)
     32            uid: "",                // Uid of the survey (STRING)
     33            description: "",        // Description of the survey (STRING)
     34            questions: {            // Properties of the questions contained within this survey
     35                uids: [],               // An array of uids of the questions, in the order that they appear in the survey (STRING)
     36                upToDate: []            // Whether or not a certain question needs an update (BOOL)
     37            }
     38        },
     39        state: {                // Operating state of the sequencer
     40            editing: false,         // Whether or not one of the contained child objects is currently being edited or in edit mode. Which one can be determined from the selectedObject property. (BOOL)
     41            updating: false,        // Whether or not new steps are currently being queried (to disable any further actions) (BOOL)
     42            numSteps: 0,            // Number of objects currently drawn in the editor (not necessarily same as number of objects in pipeline/survey!) (INTEGER)
     43            loaded: false,          // Whether or not the sequencer content has been updated for the first time (BOOL)
     44            selectedObject: {       // Properties of the currently selected step
     45                uid: "",                // UID of this step (STRING)
     46                index: null             // The 'index' of this step in the current sequencer view (NOT the pipeline!) (INTEGER)
     47            },
     48            pages: {                // State regarding page division of content objects
     49                total: null,            // The number of pages the content is divided across
     50                currentPage: null       // The page that is currently displayed in the sequencer           
     51            }
     52        },
     53        settings: {             // Various settings to determine the workings of the sequencer
     54            content: {              // Properties related to the content view of the sequencer
     55                contentType: null,      // Type of the loaded parent object (STRING)
     56                width: null,            // Width of the viewing area (INTEGER)
     57                height: null,           // Height of the viewing area (INTEGER)
     58                maxObjects: null,       // The maximum number of content elements to be displayed at once time (INTEGER)
     59                orientation: null,      // Whether the editor should be a vertical or horizontal editor (STRING)
     60                pages: false            // Whether or not to divide content across pages
     61            },
     62            efficientUpdating: true // Whether or not to use selective querying of the database for new step objects. True will only refresh out-of-date steps, False will refresh the whole pipeline (BOOL)
     63        }
     64    };
     65
     66}
     67
     68function loadSequencer() {
     69    // Reads hidden fields created by PHP, copies the values into the global var then deletes them.
     70   
     71    // Load hidden fields and set required properties in global object var.
     72    try {
     73        // settings fields first
     74        initSequencer();
     75       
     76        switch (sequencer.settings.content.contentType.toLowerCase()) {
     77            case "session":
     78                // Content-related fields next
     79                var fPipelineString = ge("pipelineStringField");
     80                var fPipelineTypes = ge("pipelineTypeField");
     81                var fSessionUid = ge("sessionField");
     82                var fSessionTitle = ge("sessionTitleField");
     83                sequencer.session.title = fSessionTitle.value;
     84                sequencer.session.uid = fSessionUid.value;
     85                sequencer.session.pipeline.uids = stringToArray(fPipelineString.value, ",");
     86                sequencer.session.pipeline.types = stringToArray(fPipelineTypes.value, ",");
     87                sequencer.session.pipeline.upToDate = new Array();
     88       
     89                for (var i = 0; i < sequencer.session.pipeline.uids.length; i++) {
     90                    sequencer.session.pipeline.upToDate.push(true);
     91                }
     92                break;
     93            case "survey":
     94                var fSurveyUid = ge("surveyUidField");
     95                var fQuestionUids = ge("questionUidsField");
     96                var fSurveyTitle = ge("surveyTitleField");
     97                var fnumQuestions = ge("numQuestionsField");
     98                var fSurveyDescription = ge("surveyDescriptionField");
     99                sequencer.survey.title = fSurveyTitle.value;
     100                sequencer.survey.uid = fSurveyUid.value;
     101                sequencer.survey.description = fSurveyDescription.value;
     102                sequencer.survey.questions.uids = stringToArray(fQuestionUids.value, ",");
     103                break;
     104            default:
     105                break;
     106        }
     107       
     108       
     109        sequencer.state.numSteps = 0;
     110        sequencer.state.loaded = false;
     111        sequencer.settings.efficientUpdating = true;
     112    }
     113    catch (e) {
     114        // Alert developer of any errors while setting these variables
     115        for (error in e) alert(error.message);
     116    }
     117    // Then remove the hidden fields from the HTML document
     118    var hiddenInputs = ge("hiddenInputs");
     119    hiddenInputs.parentNode.removeChild(hiddenInputs);
     120   
     121    // finally, run updateSequencer to refresh the visual display of the pipeline
     122    updateSequencer();
     123}
     124
     125function initSequencer() {
     126    // Called from loadSequencer(). Sets sequencer.settings properties depending on content type and values passed by PHP in hidden fields (currently only one), then removes these fields.
     127    // Example: stuff like editor orientation, width/height, content type, maxObjects contained, etc...
     128   
     129    // load settings fields first
     130    var fContentType = ge("sContentTypeField");
     131    var content = ge("seqContent");
     132    //sequencer.settings.content.contentType = fContentType.value.toLowerCase();
     133    sequencer.settings.content.contentType = fContentType.value;
     134    //Then select settings from a few presets
     135   
     136    switch (sequencer.settings.content.contentType.toLowerCase()) {
     137        case "session":
     138            sequencer.settings.content.orientation = "horizontal";
     139            sequencer.settings.content.width = 800;
     140            sequencer.settings.content.height = 125;
     141            content.style.width = sequencer.settings.content.width+"px";
     142            content.style.height = sequencer.settings.content.height+"px";
     143            addClass(content, "horizontal");
     144            break;
     145        case "survey":
     146            sequencer.settings.content.orientation = "vertical";
     147            sequencer.settings.content.width = 800;
     148            sequencer.settings.content.height = "auto";
     149            content.style.width = sequencer.settings.content.width+"px";
     150            content.style.height = sequencer.settings.content.height+"px";
     151            addClass(content, "vertical");
     152            break;
     153        default:
     154            break;
     155    }
     156    fContentType.parentNode.parentNode.removeChild(fContentType.parentNode);
     157}
     158
     159// Updating, drawing, formatting
    108160
    109161function updateSequencer() {
     162    // Code that manages drawing and adding of new visual representations of objects in the sequencer.
    110163
    111164    /*
    112      * Description:
    113      * This function updates the visual elements in the sequencer content view to match the current state of the sequencer.session.pipeline property.
    114      * It queries the database for object properties via AJAX (returnStep/Display/.php), then inserts divider div's in between where needed.
    115      */
    116     var content = document.getElementById("seqContentWrapper");
     165         * Description:
     166         * This function updates the visual elements in the sequencer content view to match the current state of the sequencer.session.pipeline property.
     167         * It queries the database for object properties via AJAX (returnStep/Display/.php), then inserts divider div's in between where needed.
     168         */
     169       
     170    switch (sequencer.settings.content.contentType.toLowerCase()) {
     171        case "session":
     172            updateSequencer_Session();
     173            break;
     174        case "survey":
     175            updateSequencer_Survey();
     176            break;
     177        default:
     178            // Why would this even be called?
     179            break;
     180    }
     181   
     182   
     183   
     184   
     185    //console.log(sequencer);
     186    sequencer.state.updating = false;   // Re-enable new actions
     187}
     188
     189function updateSequencer_Session() {
     190    var content = ge("seqContentWrapper");
    117191    var requestString, needsUpdating;
    118192    var args;
     193   
    119194    if (sequencer.state.loaded == false || sequencer.settings.efficientUpdating == false) {  // This is the first update of the sequencer since page load, therefore it contains no previous steps
    120195        // Stop running this function if the pipeline does not contain any elements to draw
     
    140215        }, true);
    141216        sequencer.state.loaded = true;
    142         var loadingGif = document.createElement("div");
     217        var loadingGif = ce("div");
    143218        loadingGif.innerHTML = "<img src='images/ui/ajax-loader-round.gif' style='float: left; margin:auto auto;' />";
    144219        content.appendChild(loadingGif);
     
    165240        // Optional bit with the loading GIF
    166241        for (var i = 0; i < needsUpdating.length; i++) {
    167             var loadingDiv = document.createElement("div");
     242            var loadingDiv = ce("div");
    168243            loadingDiv.className = "displayStep loading";
    169244            loadingDiv.innerHTML = "<img src='images/ui/ajax-loader-round.gif' />";
     
    179254    // End optional
    180255    }
    181     console.log(sequencer);
    182     sequencer.state.updating = false;   // Re-enable new actions
    183 }
    184 
    185 function loadSequencer() {
    186     /*
    187      * Description:
    188      * Load data from hidden fields (put there by PHP), store them in the global var "sequencer" (as well as several initialization properties),
    189      * then remove the hidden fields from the HTML document tree.
    190      */
    191    
    192     // Load hidden fields and set required properties in global object var.
    193    
    194     try {
    195         // settings fields first
    196         initEditor();
    197        
    198         // Content-related fields next
    199         var fPipelineString = document.getElementById("pipelineStringField");
    200         var fPipelineTypes = document.getElementById("pipelineTypeField");
    201         var fSessionUid = document.getElementById("sessionField");
    202         var fSessionTitle = document.getElementById("sessionTitleField");
    203         debugger;
    204         sequencer.session.title = fSessionTitle.value;
    205         sequencer.session.uid = fSessionUid.value;
    206         sequencer.session.pipeline.uids = stringToArray(fPipelineString.value, ",");
    207         sequencer.session.pipeline.types = stringToArray(fPipelineTypes.value, ",");
    208         sequencer.session.pipeline.upToDate = new Array();
    209        
     256}
     257
     258// THIS NEEDS SOME WORK! A LOT OF IT ACTUALLY!
     259function updateSequencer_Survey() {
     260    //debugger;
     261    var content = ge("seqContentWrapper");
     262    var requestString, needsUpdating, args;
     263    // Create a reference to the correct field, this might not be needed if we do not generalize the updateSequencer function and instead keep two separate update functions for separate content types.
     264    var variables = sequencer.survey;
     265   
     266    if (sequencer.state.loaded == false || sequencer.settings.efficientUpdating == false) {  // This is the first update of the sequencer since page load, therefore it contains no previous steps
     267        // Stop running this function if the questions array does not contain any elements to draw
     268        if (sequencer.survey.questions.uids.length == 0 || !sequencer.survey.questions.uids.length) return;
     269        // First clear the entire content wrapper, just for safety and in case efficientUpdating is off
     270        while (content.firstChild) {
     271            content.removeChild(content.firstChild);
     272        }
     273        args = [];
     274        needsUpdating = [];
     275        for (var i = 0; i < sequencer.survey.questions.uids.length; i++) {
     276            args.push({
     277                uid: sequencer.survey.questions.uids[i],
     278                type: "Question"
     279            });
     280            needsUpdating.push(new Array(i, sequencer.survey.questions.uids[i], "Question"));
     281        }
     282       
     283        requestString = "args="+JSON.stringify(args);
     284        newAjaxRequest(requestString, "returnObjectDisplay.php", function(result){
     285            //debugger;
     286            content.removeChild(loadingGif);
     287            insertNewObjects(result.responseText, needsUpdating);
     288        }, true);
     289        sequencer.state.loaded = false;
     290        var loadingGif = ce("div");
     291        loadingGif.innerHTML = "<img src='images/ui/ajax-loader-round.gif' style='float: left; margin:auto auto;' />";
     292        content.appendChild(loadingGif);
     293    }
     294    else {
     295        // This means that one or more steps are being added, not an entire pipeline's worth of them
     296        needsUpdating = new Array();
     297        args = [];
     298        // Add steps that need updating to the needsUpdating array (index, uid, type).
    210299        for (var i = 0; i < sequencer.session.pipeline.uids.length; i++) {
    211             sequencer.session.pipeline.upToDate.push(true);
    212         }
    213         sequencer.state.numSteps = 0;
    214         sequencer.state.loaded = false;
    215         sequencer.settings.efficientUpdating = true;
    216     }
    217     catch (e) {
    218         // Alert developer of any errors while setting these variables
    219         for (error in e) alert(error.message);
    220     }
    221    
    222     // Then remove the hidden fields from the HTML document
    223     // First reset the values to prevent them from being cached.
    224     fPipelineString.value = "blaat";
    225     fPipelineTypes.value = "blaat2";
    226     fSessionUid.value = "blaat3";
    227     fSessionTitle.value = "blaat4";
    228    
    229     var hiddenInputs = document.getElementById("hiddenInputs");
    230     hiddenInputs.parentNode.removeChild(hiddenInputs);
    231    
    232     // finally, run updateSequencer to refresh the visual display of the pipeline
    233    
    234     updateSequencer();
     300            if (sequencer.session.pipeline.upToDate[i] == true) continue;
     301            needsUpdating.push(new Array(i, sequencer.session.pipeline.uids[i], sequencer.session.pipeline.types[i]));
     302            args.push({
     303                uid: sequencer.session.pipeline.uids[i],
     304                type: sequencer.session.pipeline.types[i]
     305            });       
     306        }
     307       
     308        requestString = "args="+JSON.stringify(args);
     309        newAjaxRequest(requestString, "returnObjectDisplay.php", function(result){
     310            insertNewObjects(result.responseText, needsUpdating);
     311        }, true);
     312       
     313        // Optional bit with the loading GIF
     314        for (var i = 0; i < needsUpdating.length; i++) {
     315            var loadingDiv = ce("div");
     316            loadingDiv.className = "displayStep loading";
     317            loadingDiv.innerHTML = "<img src='images/ui/ajax-loader-round.gif' />";
     318            if (needsUpdating[i][0] > sequencer.state.numSteps-1) {
     319                content.appendChild(loadingDiv);
     320                sequencer.state.numSteps++;
     321            }
     322            else {
     323                content.replaceChild(loadingDiv, content.childNodes[i][0]*2);
     324            }
     325        }
     326        updateDividers();
     327    // End optional
     328    }
     329}
     330
     331function updateDividers() {
     332    // Function that checks for correct number of dividers in the pipeline, adds or deletes as needed.
     333   
     334    var content = ge("seqContentWrapper");
     335    // Loop through all elements in seqContentWrapper
     336    for (var i = 0; i < content.childNodes.length; i++) {
     337        var element = content.childNodes[i];
     338        // If the element is not a displayStep, continue with the next childNode.
     339        if (!hasClass(element, "displayStep")) {
     340            continue;
     341        }
     342        // Get the two elements next to the current element, if they don't exist or are not displaySteps, store false.
     343        var lastElement = (element.previousSibling && element.previousSibling.nodeName == "DIV") ? element.previousSibling : false;
     344        var nextElement = (element.nextSibling && element.nextSibling.nodeName == "DIV") ? element.nextSibling : false;
     345        // If these elements exist, and they are not dividers, add an element in between.
     346        if (lastElement != false) {
     347            if (!hasClass(lastElement, "divider")){
     348                var newDivider = ce("div");
     349                addClass(newDivider, "divider");
     350                addClass(newDivider, sequencer.settings.content.orientation);
     351                content.insertBefore(newDivider, element);
     352                delete newDivider;
     353            }
     354        }
     355        if (nextElement != false) {
     356            if (!hasClass(nextElement, "divider")){
     357                var newDivider = ce("div");
     358                addClass(newDivider, "divider");
     359                addClass(newDivider, sequencer.settings.content.orientation);
     360                content.insertBefore(newDivider, nextElement);
     361                delete newDivider;
     362            }
     363        }
     364    }
     365}
     366
     367// Adding new objects
     368
     369function submitToolbox(type) {
     370    // Handles new object creation code when user clicks on a toolbox button
     371   
     372    // Do not accept new creation requests if the sequencer is still updating a previous object.
     373    if (sequencer.state.updating == true) return;
     374    sequencer.state.updating = true;
     375    deselectStep();   
     376    var c = "objectToCreate="+type;
     377    var u = "createObject.php";
     378       
     379    newAjaxRequest(c, u, function(result) {
     380        sequencer.session.pipeline.uids.push(removeNL(result.responseText));
     381        sequencer.session.pipeline.types.push(type);
     382        sequencer.session.pipeline.upToDate.push(false);
     383        updateSequencer();
     384    }, true);
    235385}
    236386
    237387function insertNewObjects(responseText, needsUpdating) {
     388    // Container function that calls different insertNewX() functions depending on content type. Called from updateSequencer().
     389    debugger;
    238390    var response = JSON.parse(responseText);
    239391    // For now I assume that only one type of element can be displayed in the editor at one time. Therefore, the type of response[0] is the type of all elements of response.
     
    251403}
    252404
     405function addQuestion_Click() {
     406    if (sequencer.state.updating == true) return;
     407    sequencer.state.updating = true;
     408    deselectStep();   
     409    var c = "objectToCreate=question";
     410    var u = "createObject.php";
     411       
     412    newAjaxRequest(c, u, function(result) {
     413        debugger;
     414        sequencer.survey.questions.uids.push(removeNL(result.responseText));
     415        sequencer.survey.questions.upToDate.push(false);
     416        updateSequencer();
     417    }, true);
     418}
     419
     420//> Session specific
     421
    253422function insertNewSteps(response, needsUpdating) {
    254423    /*
    255      * This is a test function displaying how to handle the visual object representation in solely javascript.
    256      * Communication of relevant variables between PHP and JS happens in JSON format.
    257      * PHP returns a JSON array of objects to be created by JS
    258      * JS then loops through this array and creates DIVS to be inserted into the sequencer.
    259      * These are inserted at the position needsUpdating gives us.
    260      */
    261     var content = document.getElementById("seqContentWrapper");
     424         * This is a function displaying how to handle the visual object representation in solely javascript.
     425         * Communication of relevant variables between PHP and JS happens in JSON format.
     426         * PHP returns a JSON array of objects to be created by JS
     427         * JS then loops through this array and creates DIVS to be inserted into the sequencer.
     428         * These are inserted at the position needsUpdating gives us.
     429         */
     430    var content = ge("seqContentWrapper");
    262431    // Remove optional loading images
    263432    for (var  i = 0; i < content.childNodes.length; i++) {
     
    269438   
    270439    for (var i = 0; i < response.length; i++) {
    271         var tempDiv = document.createElement("div");
     440        var tempDiv = ce("div");
    272441        tempDiv.id = response[i].uid;
    273442        tempDiv.className = "displayStep";
    274         var divImageContainer = document.createElement("div");
     443        var divImageContainer = ce("div");
    275444        divImageContainer.className = "displayStepIcon";
    276445        divImageContainer.addEventListener("click", function(){
    277446            clickStep(this.parentNode.id);
    278447        }, false);
    279         var divImage = document.createElement("img");
     448        var divImage = ce("img");
    280449        divImage.src = "images/icons/"+response[i].type.toLowerCase()+".png";
    281450        divImageContainer.appendChild(divImage);
    282451        tempDiv.appendChild(divImageContainer);
    283         var divLabel = document.createElement("p");
     452        var divLabel = ce("p");
    284453        divLabel.innerHTML = response[i].title;
    285454        tempDiv.appendChild(divLabel);
     
    301470}
    302471
     472function deleteStep() {
     473    // Delete a step from both the pipeline.uids variable and its visual representation from the sequencer. Does not actually delete object from database!
     474   
     475    // check if a step is selected
     476    if (sequencer.state.selectedObject.uid == null) {
     477        return;
     478    }
     479    var uid = sequencer.state.selectedObject.uid;
     480    // deselect the step to reset the info panel and selection code
     481    deselectStep();
     482    // splice the step's data from the pipeline
     483    var index = sequencer.session.pipeline.uids.indexOf(uid);
     484    if (index >= 0 && index < sequencer.session.pipeline.uids.length) {
     485        sequencer.session.pipeline.uids.splice(index, 1);
     486        sequencer.session.pipeline.types.splice(index, 1);
     487        sequencer.session.pipeline.upToDate.splice(index, 1);
     488        // Then delete the step visually
     489        var element = ge(uid);
     490        var divider;
     491        if (!element.nextSibling) {
     492            // the element is at the end of the pipeline
     493            // therefore we remove the previous divider.
     494            // Note: it could also be the only element left in the pipeline!
     495            divider = (element.previousSibling) ? element.previousSibling : false;
     496            if (divider != false) {
     497                divider.parentNode.removeChild(divider);
     498            }
     499        }
     500        else {
     501            // the element is at any position except the last, therefore we remove the next divider
     502            divider = (element.nextSibling) ? element.nextSibling : false;
     503            if (divider != false) {
     504                divider.parentNode.removeChild(divider);
     505            }
     506        }
     507       
     508        // Finally, remove the element itself.
     509        element.parentNode.removeChild(element);
     510        sequencer.state.numSteps--;
     511       
     512    }
     513}
     514
     515//> Survey specific
     516
    303517function insertNewQuestions(response, needsUpdating) {
    304     var content = document.getElementById("seqContentWrapper");
     518    //Code that inserts or replaces new object displays in the sequencer. Question version.
     519   
     520    var content = ge("seqContentWrapper");
    305521    // Loop through returned question objects
    306522    for (var i = 0; i < response.length; i++) {
    307523        // Define the outer frame
    308         var frameDiv = document.createElement("div");
     524        var frameDiv = ce("div");
    309525        frameDiv.className = "smallFrame question";
    310526        frameDiv.id = response[i].uid;
    311         var titleDiv = document.createElement("div");
     527        var titleDiv = ce("div");
    312528        titleDiv.className = "smallTitle";
    313         var numberDiv = document.createElement("div");
     529        var numberDiv = ce("div");
    314530        numberDiv.className = "listNumber";
    315531        numberDiv.innerHTML = i.toString();
     
    320536        // The frame now has a header bar
    321537        // On to the content frame
    322         // Will use new "ce();" function, shorthand for document.createElement
     538        // Will use new "ce();" function, shorthand for ce
    323539       
    324540        var contentDiv = ce("div");
     
    366582}
    367583
    368 function updateDividers() {
    369     var content = document.getElementById("seqContentWrapper");
    370     for (var i = 0; i < content.childNodes.length; i++) {
    371         var element = content.childNodes[i];
    372         if (!hasClass(element, "displayStep")) {
    373             continue;
    374         }
    375         var lastElement = (element.previousSibling && element.previousSibling.nodeName == "DIV") ? element.previousSibling : false;
    376         var nextElement = (element.nextSibling && element.nextSibling.nodeName == "DIV") ? element.nextSibling : false;
    377         if (lastElement != false) {
    378             if (!hasClass(lastElement, "divider")){
    379                 var newDivider = document.createElement("div");
    380                 addClass(newDivider, "divider");
    381                 addClass(newDivider, sequencer.settings.content.orientation);
    382                 content.insertBefore(newDivider, element);
    383                 delete newDivider;
    384             }
    385         }
    386         if (nextElement != false) {
    387             if (!hasClass(nextElement, "divider")){
    388                 var newDivider = document.createElement("div");
    389                 addClass(newDivider, "divider");
    390                 addClass(newDivider, sequencer.settings.content.orientation);
    391                 content.insertBefore(newDivider, nextElement);
    392                 delete newDivider;
    393             }
    394         }
    395     }
     584// general functions and user actions
     585
     586function clickStep(uid) {
     587    // Handles selection of steps
     588   
     589    if (uid == sequencer.state.selectedObject.uid) {  // user deselected a currently selected step.
     590        deselectStep();
     591    }
     592    else {
     593        if (sequencer.state.selectedObject.uid != undefined && sequencer.state.selectedObject.uid != "") {
     594            // Change selection if something is already selected
     595            deselectStep();
     596            selectStep(uid);
     597        }
     598        else {
     599            // Make new selection if nothing was selected
     600            selectStep(uid);
     601        }       
     602    }
     603}
     604
     605function selectStep(uid) {
     606    // Called from clickStep(), manages CSS class assignment and updating of state variables. Also calls for info panel update.
     607   
     608    var element = ge(uid);
     609    if (element) {
     610        addClass(element, "selected");
     611        var type = sequencer.session.pipeline.types[sequencer.session.pipeline.uids.indexOf(uid)];
     612        ajaxInfoRequest(uid, ge("infoPanelContent"), type);
     613        sequencer.state.selectedObject.uid = uid;
     614        sequencer.state.selectedObject.index = null;  //Don't know how to do this yet.
     615    }
     616}
     617
     618function deselectStep() {
     619    // Called from clickStep(). Handles unassignment and updating of state variables. Clears info panel.
     620   
     621    if (!sequencer.state.selectedObject.uid) return;
     622    var element = ge(sequencer.state.selectedObject.uid);
     623    removeClass(element, "selected");
     624    sequencer.state.selectedObject.uid = null;
     625    sequencer.state.selectedObject.index = null;
     626    var infoPanel = ge("infoPanelContent");
     627    if (infoPanel) {
     628        while (infoPanel.firstChild) infoPanel.removeChild(infoPanel.firstChild);
     629    }
     630}
     631
     632function ajaxInfoRequest(uid, el, type) {
     633    // Info panel update.
     634   
     635    var c = "uid="+uid;
     636    c += "&type="+type;
     637    var u = "getInfo.php";
     638    newAjaxRequest(c, u, function(result) {
     639        el.innerHTML = result.responseText;
     640    }, true);
    396641}
    397642
    398643function savePipeline (confirmSave) {
    399    
     644    // Sends an AJAX request to the PHP server that saves the current pipeline. Does not yet support surveys.
     645   
     646    // First check if user should confirm save action or not.
    400647    var answer;
    401648    if (confirmSave == true) {
     
    406653    }
    407654    if (answer == false) return;
    408    
     655    // Then compose requestString for savesession.php, containing pipeline uids, types and the session uid.
     656    // TODO: should eventually include stuff like session name as well!
    409657    var requestString = "uids=";
    410658    requestString += arrayToString(sequencer.session.pipeline.uids, ",");
     
    422670
    423671function editStep() {
     672    // Redirects the browser to the appropriate editor for the selected step type.
     673   
    424674    // first save
    425    
    426     //savePipeline(false);
    427    
    428     var postForm = document.createElement("form");
    429     var type = sequencer.session.pipeline.types[sequencer.session.pipeline.uids.indexOf(sequencer.state.selectedStep.uid)];
     675    savePipeline(false);
     676    // Then post relevant information so the next editor page knows what object it is supposed to be editing.
     677    var postForm = ce("form");
     678    var type = sequencer.session.pipeline.types[sequencer.session.pipeline.uids.indexOf(sequencer.state.selectedObject.uid)];
    430679    postForm.action = type.toLowerCase()+"Editor.php";
    431680    postForm.method = "POST";
    432     var objectUid = document.createElement("input");
     681    var objectUid = ce("input");
    433682    objectUid.type = "hidden";
    434683    objectUid.name = "objectUid";
    435     objectUid.value = sequencer.state.selectedStep.uid;
     684    objectUid.value = sequencer.state.selectedObject.uid;
    436685    postForm.appendChild(objectUid);
    437686    postForm.submit();
     
    439688
    440689function moveStep (direction) {
     690    // Moves the selected step up/down (left/right) in the pipeline.
     691   
    441692    // Check if a step is selected
    442     if (sequencer.state.selectedStep.uid == null || direction == null) return;
     693    if (sequencer.state.selectedObject.uid == null || direction == null) return;
    443694    // Check if the step is not at either end of the pipeline
    444     var index = sequencer.session.pipeline.uids.indexOf(sequencer.state.selectedStep.uid);
     695    var index = sequencer.session.pipeline.uids.indexOf(sequencer.state.selectedObject.uid);
    445696    if (index == -1) return;
    446697    if ((index < 0) || (index >= sequencer.session.pipeline.uids.length) || (index == 0 && direction == -1) || (index == sequencer.session.pipeline.uids.length - 1 && direction == 1)) {
     
    450701   
    451702    // Find the two elements in the editor content display
    452     var content = document.getElementById("seqContentWrapper");
    453     var element = document.getElementById(sequencer.session.pipeline.uids[index]);
    454     var otherElement = document.getElementById(sequencer.session.pipeline.uids[index+direction]);
     703    var content = ge("seqContentWrapper");
     704    var element = ge(sequencer.session.pipeline.uids[index]);
     705    var otherElement = ge(sequencer.session.pipeline.uids[index+direction]);
    455706    // First buffer the two elements
    456707    var tempElement = element.cloneNode(true);
    457708    var tempOtherElement = otherElement.cloneNode(true);
    458     var placeHolderElement = document.createElement("div");
     709    var placeHolderElement = ce("div");
    459710    placeHolderElement.id = "placeholder_element";
    460711    content.replaceChild(placeHolderElement, otherElement);
     
    501752}
    502753
    503 function initEditor() {
    504     // Reset the editor if the
    505    
    506     // load settings fields first
    507     var fContentType = document.getElementById("sContentTypeField");
    508     var content = document.getElementById("seqContent");
    509     //sequencer.settings.content.contentType = fContentType.value.toLowerCase();
    510     sequencer.settings.content.contentType = fContentType.value;
    511     //Then select settings from a few presets
    512    
    513     switch (sequencer.settings.content.contentType) {
    514         case "session":
    515             sequencer.settings.content.orientation = "horizontal";
    516             sequencer.settings.content.width = 800;
    517             sequencer.settings.content.height = 125;
    518             content.style.width = sequencer.settings.content.width+"px";
    519             content.style.height = sequencer.settings.content.height+"px";
    520             addClass(content, "horizontal");
    521             break;
    522         case "survey":
    523             sequencer.settings.content.orientation = "vertical";
    524             sequencer.settings.content.width = 800;
    525             sequencer.settings.content.height = "auto";
    526             content.style.width = sequencer.settings.content.width+"px";
    527             content.style.height = sequencer.settings.content.height+"px";
    528             addClass(content, "vertical");
    529             break;
    530         default:
    531             break;
    532     }
    533     fContentType.parentNode.parentNode.removeChild(fContentType.parentNode);
    534 }
    535 
     754// WORK IN PROGRESS
     755
     756
     757
     758
     759
     760
     761
     762
     763/******************/
     764/* TEMP FUNCTIONS */
     765/******************/
     766
     767// Temp function that creates a dummy question to test the insertNewQuestions function.
    536768function debug_addQuestion() {
    537769    // Derp, natuurlijk werkt de addQuestion call niet twee keer. Hij creeert twee keer exact hetzelfde object. Bottom line: het werkt. Nu de editing code voor deze questions gaan schrijven!
     
    552784}
    553785
     786// Temp function that articially switches content type when the page is already loaded, to easily test layout changes and content flow.
    554787function debug_switchType() {
    555788    var content = ge("seqContent");
     
    569802    }
    570803}
    571 
    572 function createVarArray() {
    573     if (sequencer) delete window.sequencer;
    574     return {   // GLOBAL VAR TO STORE SEQUENCER SETTINGS!
    575         uid: "",                // The unique id of this sequencer (not DB related!). This will help to avoid global var conflicts. Assign this randomly! (STRING)
    576         session: {              // Properties of the currently loaded session
    577             title: "",              // Title or name (STRING)
    578             uid: "",                // Database UID of the current session (STRING)
    579             pipeline: {             // Pipeline
    580                 uids: [],               // Uids of objects in pipeline (STRING)
    581                 types: [],              // Types of objects in pipeline (STRING)
    582                 upToDate: []            // Whether or not object displays are up to date (BOOL)
    583             }
    584         },
    585         survey: {               // Properties of the loaded survey, if applicable (either this or the session tree above is filled in!) [THIS IS NOT CURRENTLY USED AND I SHOULD DELIBERATE ON WHAT VARIABLES TO PUT IN THIS TREE TO MAKE A FUNCTIONAL EDITOR THAT ALSO MATCHES THE DB FORMAT!]
    586             title: "",              // Title or the name of the survey
    587             uid: "",                // Uid of the survey
    588             questions: {            // Properties of the questions contained within this survey
    589                 uids: [],               // An array of uids of the questions, in the order that they appear in the survey
    590                 upToDate: []            // Whether or not a certain question needs an update
    591             }
    592         },
    593         state: {                // Operating state of the sequencer
    594             editing: false,         // Whether or not one of the contained child objects is currently being edited or in edit mode. Which one can be determined from the selectedStep property.
    595             updating: false,        // Whether or not new steps are currently being queried (to disable any further actions)
    596             numSteps: 0,            // Number of steps currently drawn in the editor (not necessarily same as number of steps in pipeline!) (INTEGER)
    597             loaded: false,          // Whether or not the sequencer content has been updated for the first time (BOOL)
    598             selectedStep: {         // Properties of the currently selected step
    599                 uid: "",                // UID of this step (STRING)
    600                 index: null             // The 'index' of this step in the current sequencer view (NOT the pipeline!) (INTEGER)
    601             }       
    602         },
    603         settings: {             // Various settings to determine the workings of the sequencer
    604             content: {              // Properties related to the content view of the sequencer
    605                 contentType: null,      // Type of the loaded parent object (STRING)
    606                 width: null,            // Width of the viewing area (INTEGER)
    607                 height: null,           // Height of the viewing area (INTEGER)
    608                 maxObjects: null,       // The maximum number of content elements to be displayed at once time (INTEGER)
    609                 orientation: null       // Whether the editor should be a vertical or horizontal editor (STRING)
    610             },
    611             efficientUpdating: true // Whether or not to use selective querying of the database for new step objects. True will only refresh out-of-date steps, False will refresh the whole pipeline
    612         }
    613     };
    614 }
  • Dev/trunk/pipelineEditor.php

    r184 r185  
    77
    88$sequencer = new PipelineSequencer();
    9 $sequencer->LoadSession($_SESSION['currentSession']); //load session into php part of the sequencer
     9$sequencer->LoadSession(); //load session into php part of the sequencer
    1010$sequencer->HandlePostData();
    1111?>
     
    3030        <div id="header">
    3131            <?php new Logo(); ?>
    32             <input type="button" onClick="debug_switchType();" value="debug_switchType()" />
    33             <input type="button" onClick="debug_addQuestion();" value="debug_addQuestion()" />
    3432        </div>
    3533
  • Dev/trunk/returnObjectDisplay.php

    r183 r185  
    33require 'classes/master.php';
    44
    5 //var_dump($_POST);
    6 if (isset($_POST['args']) && !empty($_POST['args'])) {
     5/*
     6 * Note: do not try to implement info panel displays in this file as well, it passes and queries a lot of data that you really do not need.
     7 * Since this function will be used so often, adding extra unneeded code to it will slow down the regular operation of the editor (refreshes, etc..) while not offering a significant advantage over the existing getInfo.php
     8 */
     9
     10
     11if(isset($_POST['args']) && !empty($_POST['args'])) {
    712    // Get arguments and convert to object
    813    $input = $_POST['args'];
    9     $inputDecoded = json_decode($input);
     14    $requestArray = json_decode($input);
    1015} else {
    1116    die('DOESNT WORK...');
     
    1419$dbi = new DatabaseInterface();
    1520$outputArray = array();
    16 foreach ($inputDecoded as $request) {
    17     $results = $dbi->get($request->type, array("uid" => $request->uid));
     21foreach ($requestArray as $request) {
     22    var_dump($request);
     23    $results = $dbi->get(strtolower($request->type), array("uid" => $request->uid));
     24   
     25    /*
     26     * Reden voor deze var dumps is dat de questions niet gevonden kunnen worden. De bovenstaande regel returnet geen question object, ook als deze zeker weten wel bestaat.
     27     * Even aan Jos vragen wat hier fout gaat?
     28     */
     29   
     30   
     31   
     32   
     33    var_dump($results);
    1834    if (isset($results) && !empty($results)) {
    1935        is_array($results) ? $object = $results[0] : $object = $results;
  • Dev/trunk/selectSession.php

    r168 r185  
    4545        $matching = $dbi->get("SESSION", array("uid" => $_POST['sessionUID']));
    4646        if (count($matching) == 1 && $matching[0] != null) {
     47            // DEZE SESSION MOET UITEINDELIJK EEN POST WORDEN, WANNEER DEZE HELE PAGINA IS OVERGEZET IN JAVASCRIPT!
    4748            $_SESSION['currentSession'] = $_POST['sessionUID'];
    4849            $_SESSION['updateNeeded'] = "true";
  • Dev/trunk/surveyEditor.php

    r178 r185  
    2525                <?php $surveyEditor->init(); ?>
    2626            </div>
     27            <div id="settingsFields">
     28                <input type="hidden" id="sContentTypeField" value="Survey" />
     29            </div>
    2730        </div>
    2831    </body>
Note: See TracChangeset for help on using the changeset viewer.