app/soc/content/js/survey-edit-090825.js
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 12 Sep 2009 00:36:49 +0200
changeset 2898 ac5f77cd6046
parent 2801 0ee67cc9bd20
permissions -rw-r--r--
Fix 500 when saving /site/edit without email When saving /site/edit with no no_reply_email set, a 500 error page would be returned due to an empty value being passed as value to the datastore (which is not allowed for email fields).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     1
 /* Copyright 2009 the Melange authors.
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     2
 *
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     3
 * Licensed under the Apache License, Version 2.0 (the "License");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     4
 * you may not use this file except in compliance with the License.
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     5
 * You may obtain a copy of the License at
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     6
 *
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     7
 *   http://www.apache.org/licenses/LICENSE-2.0
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     8
 *
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     9
 * Unless required by applicable law or agreed to in writing, software
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    10
 * distributed under the License is distributed on an "AS IS" BASIS,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    12
 * See the License for the specific language governing permissions and
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    13
 * limitations under the License.
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    14
 */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    15
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    16
/*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    17
*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    18
* @author <a href="mailto:ajaksu@gmail.com">Daniel Diniz</a>
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    19
* @author <a href="mailto:jamesalexanderlevy@gmail.com">James Levy</a>
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    20
*/
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    21
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    22
(function ($) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    23
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    24
  var DEFAULT_LONG_ANSWER_TEXT = 'Write a Custom Prompt For This Question...';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    25
  var DEFAULT_SHORT_ANSWER_TEXT = 'Write a Custom Prompt...';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    26
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    27
  $(function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    28
    /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    29
    * == Set Selectors ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    30
    *
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    31
    */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    32
    var widget = $('div#survey_widget');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    33
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    34
    widget.parents('td.formfieldvalue:first').css({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    35
      'float': 'left',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    36
      'width': 200
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    37
    });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    38
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    39
    /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    40
    * == Setup for existing surveys ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    41
    *
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    42
    */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    43
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    44
    if ($('input#id_title').val() === '' && $('.formfielderror').length < 1) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    45
      widget.find('tr').remove();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    46
    }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    47
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    48
    widget.find('table:first').show();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    49
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    50
    /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    51
    *  Restore survey content html from editPost
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    52
    *  if POST fails
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    53
    */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    54
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    55
    var SURVEY_PREFIX = 'survey__';
2570
851640749319 Several Survey UI fixes.
Daniel Diniz <ajaksu@gmail.com>
parents: 2562
diff changeset
    56
    var del_el = ["<a class='delete'><img ",
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    57
                  "src='/soc/content/images/minus.gif'/></a>"].join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    58
    var del_li = ["<a class='delete_item' id='del_",
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    59
                  "' ><img src='/soc/content/images/minus.gif'/></a> "];
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    60
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    61
    var survey_html = $('form').find("#id_survey_html").attr('value');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    62
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    63
    function renderHTML() {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    64
      // render existing survey forms
2570
851640749319 Several Survey UI fixes.
Daniel Diniz <ajaksu@gmail.com>
parents: 2562
diff changeset
    65
      widget.find('td.twolineformfieldlabel > label').prepend(del_el).end();
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    66
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    67
      $('ol').find('li').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    68
        function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    69
          $(this).prepend(del_li.join($(this).attr('id'))).end();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    70
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    71
      );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    72
      widget.find('.short_answer').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    73
        function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    74
          $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    75
                             'short_answer__' + $(this).attr('name'));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    76
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    77
      );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    78
2560
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    79
      // add index information to choice fields
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    80
      widget.find('[name=create-option-button]').each(
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    81
        function () {
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    82
          $(
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    83
            '#index_for_' + $(this).attr('value')
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    84
          )
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    85
          .val(
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    86
            $(this).getPosition()
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    87
          );
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    88
        }
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    89
      );
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
    90
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    91
      widget.find('.long_answer').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    92
        function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    93
          $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    94
                             'long_answer__' + $(this).attr('name'))
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    95
          .attr('overflow', 'auto');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    96
          // TODO: replace scrollbar with jquery autogrow
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    97
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    98
      );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    99
    }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   100
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   101
    if (survey_html && survey_html.length > 1) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   102
      widget.html(survey_html); // we don't need to re-render HTML
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   103
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   104
      widget.find('.long_answer,input').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   105
        function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   106
          $(this).val($(this).attr('val'));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   107
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   108
      );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   109
    }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   110
    else {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   111
      renderHTML();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   112
    }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   113
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   114
    var survey = widget.find('tbody:first');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   115
    var options = widget.find('#survey_options');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   116
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   117
    /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   118
    * == Handle Enter key on dialogs ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   119
    */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   120
    $('form input, form button, form select').keypress(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   121
      function (e) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   122
        if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   123
          $(this).parents('.ui-dialog:first').find(":button:first").click();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   124
          return false;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   125
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   126
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   127
    );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   128
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   129
    /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   130
    * == Display survey answers inline ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   131
    */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   132
    $('a.fetch_answers').click(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   133
      function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   134
        var user = this.id.replace('results_for_', '');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   135
        var path = window.location.pathname;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   136
        path = path.replace('/edit/', '/show/').replace('/results/', '/show/');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   137
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   138
        // TODO(ajaksu) add Date().getTime() to query arg if needed
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   139
        var query = '?read_only=true&user_results=' + user;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   140
        var scrollable = ['<div style="overflow-y: auto; ',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   141
                          'margin-bottom: 100px;"></div>'].join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   142
        $(scrollable).load(path + query + ' #survey_widget').dialog({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   143
          title: user,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   144
          height: 500,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   145
          width: 700
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   146
        });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   147
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   148
    );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   149
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   150
    /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   151
    * == Initiation ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   152
    *
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   153
    * Runs on PageLoad and Each Time Field is Added to Survey
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   154
    *
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   155
    */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   156
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   157
    survey.bind('init',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   158
      function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   159
        // TODO(jamslevy) unnecessarily redundant
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   160
        // TODO(jamslevy) This should be refactored as a jQuery function that
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   161
        // acts on only a single field and it should be merged with renderHTML
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   162
        // since they have comparable functionality.
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   163
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   164
        widget.find('input').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   165
          function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   166
            if (($(this).val().length < 1 ||
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   167
            $(this).val() === DEFAULT_SHORT_ANSWER_TEXT) &&
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   168
            ($(this).attr('type') !== 'hidden')) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   169
              $(this).preserveDefaultText(DEFAULT_SHORT_ANSWER_TEXT);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   170
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   171
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   172
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   173
2560
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
   174
        widget.find('.long_answer, .tooltip_entry').each(
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   175
          function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   176
            if ($(this).val().length < 1 ||
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   177
            $(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   178
              $(this).preserveDefaultText(DEFAULT_LONG_ANSWER_TEXT);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   179
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   180
            $(this).growfield();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   181
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   182
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   183
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   184
        widget.find('a.delete img').click(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   185
          function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   186
            // delete a field
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   187
            var this_field = $(this).parents('tr:first');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   188
            var deleted_id = $(this_field).find('label').attr('for');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   189
            var delete_this = confirm(["Deleting this field will remove all ",
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   190
                                       "answers submitted for this field. ",
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   191
                                       "Continue?"].join(""));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   192
            if (delete_this) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   193
              var edit_form = $('#EditForm');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   194
              var deleted_field = $('#__deleted__');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   195
              if (deleted_field.val()) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   196
                deleted_field.val(deleted_field.val() + ',' +
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   197
                                  deleted_id.replace('id_', '')).end();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   198
              }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   199
              else {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   200
                var deleted_input = $("<input type='hidden' value='" +
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   201
                                      deleted_id.replace('id_', '') + "' />");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   202
                deleted_input.attr({'id': '__deleted__'}).attr({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   203
                  'name': '__deleted__'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   204
                });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   205
                edit_form.append(deleted_input);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   206
              }
2526
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   207
              this_field.next('tr').remove().end()
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   208
                        .remove();
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   209
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   210
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   211
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   212
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   213
        // Add list/choice-field item to survey
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   214
        $('[name=create-option-button]').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   215
          function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   216
            $(this).click(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   217
              function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   218
                var new_option_val = $('#new_item_field_ul_id');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   219
                var new_option_dialog = $("#new_item_dialog");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   220
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   221
                new_option_val.val($(this).parents('fieldset').children('ol')
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   222
                .attr('id'));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   223
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   224
                new_option_dialog.dialog('open').find('input:first').focus();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   225
              }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   226
            )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   227
            .hover(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   228
              function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   229
                $(this).addClass("ui-state-hover");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   230
              },
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   231
              function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   232
                $(this).removeClass("ui-state-hover");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   233
              }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   234
            )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   235
            .mousedown(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   236
              function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   237
                $(this).addClass("ui-state-active");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   238
              }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   239
            )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   240
            .mouseup(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   241
              function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   242
                $(this).removeClass("ui-state-active");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   243
              }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   244
            );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   245
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   246
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   247
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   248
        options.find('.AddQuestion').click(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   249
          function (e) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   250
            // Choose a field type
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   251
            $("#new_question_button_id").val($(this).attr('id'));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   252
            var question_options_div = $('#question_options_div');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   253
            if ($(this).attr('id') === 'choice')  {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   254
              question_options_div.show();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   255
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   256
            else {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   257
              question_options_div.hide();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   258
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   259
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   260
            $("#new_question_dialog").dialog('open').find('input:first')
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   261
            .focus();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   262
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   263
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   264
      }).trigger('init')
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   265
      .bind('option_init',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   266
        function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   267
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   268
          // Delete list/choice-field item from survey
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   269
          widget.find('a.delete_item').click(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   270
            function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   271
              var to_delete = this.id.replace('del_', '');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   272
              $('#delete_item_field').val(to_delete);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   273
              $('#delete_item_dialog').dialog('open');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   274
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   275
          ).end();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   276
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   277
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   278
      ).trigger('option_init');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   279
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   280
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   281
    /* GSOC ROLE-SPECIFIC FIELD PLUGIN
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   282
    * Choice between student/mentor renders required GSOC specific fields
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   283
    */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   284
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   285
    var taking_access_field = $('select#id_taking_access');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   286
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   287
    var addRoleFields = function (role_type) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   288
      // these should ideally be generated with django forms
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   289
      // TODO: apply info tooltips
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   290
      var CHOOSE_A_PROJECT_FIELD = [
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   291
        '<tr class="role-specific"><th><label>Choose Project:</label></th>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   292
        '<td> <select disabled=TRUE id="id_survey__NA__selection__project"',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   293
        ' name="survey__1__selection__see"><option>Survey Taker\'s Projects',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   294
        'For This Program</option></select> </td></tr>'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   295
      ].join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   296
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   297
      var CHOOSE_A_GRADE_FIELD = [
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   298
        '<tr class="role-specific"><th><label>Assign Grade:</label></th><td>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   299
        '<select disabled=TRUE id="id_survey__NA__selection__grade"',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   300
        'name="survey__1__selection__see"><option>Pass/Fail</option></select>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   301
        '</td></tr>'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   302
      ].join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   303
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   304
      // flush existing role-specific fields
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   305
      var role_specific_fields = survey.find('tr.role-specific');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   306
      role_specific_fields.remove();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   307
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   308
      switch (role_type) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   309
      case "mentor evaluation":
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   310
        survey.prepend(CHOOSE_A_PROJECT_FIELD);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   311
        survey.append(CHOOSE_A_GRADE_FIELD);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   312
        break;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   313
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   314
      case "student evaluation":
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   315
        survey.prepend(CHOOSE_A_PROJECT_FIELD);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   316
        break;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   317
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   318
    };
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   319
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   320
    taking_access_field.change(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   321
      function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   322
        var role_type = $(this).val();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   323
        addRoleFields(role_type);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   324
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   325
    );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   326
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   327
    addRoleFields(taking_access_field.val());
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   328
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   329
    /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   330
    * == Survey Submission Handler ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   331
    */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   332
    // Bind submit
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   333
    $('form').bind('submit',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   334
      function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   335
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   336
        /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   337
        * get rid of role-specific fields
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   338
        */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   339
        survey.find('tr.role-specific').remove();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   340
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   341
        /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   342
        * Save survey content html from editPost
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   343
        * if POST fails
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   344
        */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   345
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   346
        // save field vals
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   347
        widget.find('.long_answer,input').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   348
          function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   349
            $(this).attr('val', $(this).val());
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   350
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   351
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   352
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   353
        $(this).find("#id_survey_html").attr('value', widget.html());
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   354
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   355
        // don't save default value
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   356
        widget.find('input').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   357
          function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   358
            if ($(this).val() === DEFAULT_SHORT_ANSWER_TEXT) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   359
              $(this).val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   360
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   361
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   362
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   363
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   364
        // don't save default value
2560
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
   365
        widget.find('.long_answer, .tooltip_entry').each(
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   366
          function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   367
            if ($(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   368
              $(this).val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   369
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   370
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   371
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   372
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   373
        // get rid of the options
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   374
        $('input#id_s_html')
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   375
        .val(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   376
          widget
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   377
          .find(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   378
            'div#survey_options'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   379
          )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   380
          .remove()
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   381
          .end()
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   382
          .html()
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   383
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   384
        // only needed for HTML
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   385
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   386
        // Get option order per field
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   387
        survey.find('.sortable').each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   388
          function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   389
            $('#order_for_' + this.id)
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   390
            .val(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   391
              $(this).sortable(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   392
                'serialize'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   393
              )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   394
            );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   395
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   396
        );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   397
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   398
    );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   399
  });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   400
}(jQuery));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   401
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   402
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   403
(function ($) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   404
  /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   405
  * == Utils ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   406
  *
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   407
  */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   408
  jQuery.fn.extend({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   409
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   410
    // get position of survey field
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   411
    getPosition: function () {
2560
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
   412
      var this_fieldset = $(this).parents('fieldset:first');
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
   413
      var this_table = this_fieldset.parents('table:first');
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
   414
      var position = this_table.find('fieldset').index(this_fieldset) + '__';
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   415
      return position;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   416
    }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   417
  });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   418
}(jQuery));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   419
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   420
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   421
(function ($) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   422
  /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   423
  * == Sortable options ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   424
  */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   425
  $(function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   426
    $(".sortable").each(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   427
      function (i, domEle) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   428
        $(domEle).sortable().disableSelection().end();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   429
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   430
    );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   431
  });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   432
}(jQuery));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   433
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   434
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   435
(function ($) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   436
  /*
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   437
  * == Editable options ==
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   438
  */
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   439
  $(function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   440
    function onSubmitEditable(content) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   441
      var id_ = $(this).parent().attr('id').replace('-li-', '_');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   442
      id_ = id_ + '__field';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   443
      $('#' + id_).val(content.current);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   444
    }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   445
    $('.editable_option').editable({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   446
      editBy: 'dblclick',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   447
      submit: 'change',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   448
      cancel: 'cancel',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   449
      onSubmit: onSubmitEditable
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   450
    });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   451
  });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   452
}(jQuery));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   453
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   454
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   455
(function ($) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   456
  $(function () {
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2670
diff changeset
   457
    var del_li = [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2670
diff changeset
   458
      "<a class='delete_item' id='del_",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2670
diff changeset
   459
      "' ><img src='/soc/content/images/minus.gif'/></a> "
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2670
diff changeset
   460
    ];
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   461
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   462
    // Confirmation dialog for deleting list/choice-field item from survey
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   463
    $("#delete_item_dialog").dialog({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   464
      autoOpen: false,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   465
      bgiframe: true,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   466
      resizable: false,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   467
      height: 300,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   468
      modal: true,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   469
      overlay: {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   470
        backgroundColor: '#000',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   471
        opacity: 0.5
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   472
      },
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   473
      buttons: {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   474
        'Delete this item': function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   475
          $('#' + $('#delete_item_field').val()).remove();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   476
          $('#delete_item_field').val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   477
          $(this).dialog('close');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   478
        },
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   479
        Cancel: function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   480
          $('#delete_item_field').val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   481
          $(this).dialog('close');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   482
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   483
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   484
    });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   485
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   486
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   487
    //  Dialog for adding list/choice-field item to survey
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   488
    $("#new_item_dialog").dialog({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   489
      bgiframe: true,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   490
      autoOpen: false,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   491
      height: 300,
2570
851640749319 Several Survey UI fixes.
Daniel Diniz <ajaksu@gmail.com>
parents: 2562
diff changeset
   492
      width: 300,
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   493
      modal: true,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   494
      buttons: {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   495
        'Add option': function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   496
          var ol_id =  $('#new_item_field_ul_id').val();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   497
          var ol = $('#' + ol_id);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   498
          var name = $('#new_item_name').val();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   499
          var i = ol.find('li').length;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   500
          var id_ = 'id_' + ol_id + '_' + i;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   501
          var option_html = $([
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   502
            '<li id="id-li-', ol_id, '_', i,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   503
            '" class="ui-state-defaolt sortable_li">',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   504
            '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   505
            '<span id="', id_, '" class="editable_option" name="', id_,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   506
            '__field">', name, '</span>', '<input type="hidden" id="', id_,
2541
7ef468836f6e Fixes bug when option name contains double quotes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2526
diff changeset
   507
            '__field" name="', id_, '__field" value="',
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2670
diff changeset
   508
            name.replace(/\"/g, '&quot;'), '" >', '</li>'
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   509
          ].join(""));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   510
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   511
          ol.append(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   512
            option_html
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   513
            .prepend(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   514
              del_li.join(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   515
                option_html.attr('id')
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   516
              )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   517
            )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   518
          );
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   519
          ol.sortable().disableSelection();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   520
          $('#new_item_name').val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   521
          $('#new_item_field_ol_id').val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   522
          $(this).dialog('close');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   523
        },
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   524
        Cancel: function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   525
          $('#new_item_name').val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   526
          $('#new_item_field_ul_id').val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   527
          $(this).dialog('close');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   528
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   529
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   530
    });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   531
  });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   532
}(jQuery));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   533
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   534
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   535
(function ($) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   536
  $(function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   537
    //  Dialog for adding new question to survey
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   538
    var SURVEY_PREFIX = 'survey__';
2570
851640749319 Several Survey UI fixes.
Daniel Diniz <ajaksu@gmail.com>
parents: 2562
diff changeset
   539
    var del_el = ["<a class='delete'><img ",
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   540
              "src='/soc/content/images/minus.gif'/></a>"].join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   541
    var del_li = ["<a class='delete_item' id='del_",
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   542
                  "' ><img src='/soc/content/images/minus.gif'/></a> "];
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   543
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   544
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   545
    var widget = $('div#survey_widget');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   546
    var survey = widget.find('tbody:first');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   547
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   548
    $("#new_question_dialog").dialog({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   549
      bgiframe: true,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   550
      autoOpen: false,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   551
      height: 400,
2570
851640749319 Several Survey UI fixes.
Daniel Diniz <ajaksu@gmail.com>
parents: 2562
diff changeset
   552
      width: 300,
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   553
      modal: true,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   554
      buttons: {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   555
        'Add question': function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   556
          var button_id = $("#new_question_button_id").val();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   557
          var survey_table = $('div#survey_widget').find('tbody:first');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   558
          $("#new_question_button_id").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   559
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   560
          var field_template =  $(["<tr><th><label>", del_el,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   561
                                   "</label></th><td>  </td></tr>"].join(""));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   562
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   563
          var field_name = $("#new_question_name").val();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   564
          var question_content = $("#new_question_content").val();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   565
          var question_options = $("#new_question_options").val();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   566
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   567
          if (field_name !== '') {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   568
            $("#new_question_name").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   569
            $("#new_question_content").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   570
            $("#new_question_options").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   571
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   572
            var new_field = false;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   573
            var type = button_id + "__";
2560
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
   574
            var field_count = survey_table.find('fieldset').length;
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   575
            var new_field_count = field_count + 1 + '__';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   576
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   577
            var MIN_ROWS = 10;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   578
            var MAX_ROWS = MIN_ROWS * 2;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   579
            var DEFAULT_OPTION_TEXT = 'Add A New Option...';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   580
            var default_option = ["<option>", DEFAULT_OPTION_TEXT,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   581
                                  "</option>"].join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   582
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   583
            // create the HTML for the field
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   584
            switch (button_id) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   585
            case "short_answer":
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   586
              new_field = ["<fieldset>\n",
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   587
                          '<label for="required_for_',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   588
                           field_name, '">Required</label>',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   589
                           '<select id="required_for_', field_name,
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   590
                           '" name="required_for_', field_name,
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   591
                           '"><option value="True" selected="selected">True',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   592
                           '</option>', '<option value="False">False</option>',
2526
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   593
                           '</select>', '<label for="comment_for_',
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   594
                           field_name, '">Allow Comments</label>',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   595
                           '<select id="comment_for_', field_name,
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   596
                           '" name="comment_for_', field_name, '">',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   597
                           '<option value="True" selected="selected">',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   598
                           'True</option>', '<option value="False">',
2526
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   599
                           'False</option>', '</select>',
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   600
                          "<input type='text' ",
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   601
                           "class='short_answer'>", "</fieldset>"
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   602
                          ].join("");
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   603
              break;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   604
            case "long_answer":
2560
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
   605
              field_count = survey_table.find('fieldset').length;
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   606
              new_field_count = field_count + 1 + '__';
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   607
              new_field = ['<fieldset>\n', '<label for="required_for_',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   608
                           field_name, '">Required</label>',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   609
                           '<select id="required_for_', field_name,
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   610
                           '" name="required_for_', field_name,
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   611
                           '"><option value="True" selected="selected">True',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   612
                           '</option>', '<option value="False">False</option>',
2526
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   613
                           '</select>', '<label for="comment_for_',
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   614
                           field_name, '">Allow Comments</label>',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   615
                           '<select id="comment_for_', field_name,
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   616
                           '" name="comment_for_', field_name, '">',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   617
                           '<option value="True" selected="selected">',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   618
                           'True</option>', '<option value="False">',
2526
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   619
                           'False</option>', '</select>',
2670
884f808d8469 fix for issue 653 by adding wrap=hard attr to textareas for surveys
James Levy <jamesalexanderlevy@gmail.com>
parents: 2572
diff changeset
   620
                           "<textarea wrap='hard' cols='40' rows='", MIN_ROWS,
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   621
                           "' class='long_answer'/>", '</fieldset>'
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   622
                          ].join("");
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   623
              break;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   624
            case "selection":
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   625
              new_field = ["<select><option></option>", default_option,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   626
                           "</select>"].join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   627
              break;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   628
            case "pick_multi":
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   629
              new_field = ["<fieldset class='fieldset'><input type='button'",
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   630
                           "value='", DEFAULT_OPTION_TEXT, "' /></fieldset>"]
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   631
                          .join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   632
              break;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   633
            case "choice":
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   634
              new_field = ["<fieldset class='fieldset'><input type='button'",
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   635
                           "value='", DEFAULT_OPTION_TEXT, "' /></fieldset>"]
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   636
                          .join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   637
              break;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   638
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   639
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   640
            if (new_field) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   641
              var question_for = [
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   642
                '\n  <input type="hidden" name="NEW_', field_name,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   643
                '" id="NEW_', field_name, '" value="', question_content,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   644
                '"/>'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   645
              ].join("");
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   646
2560
a944c0169ad8 Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents: 2541
diff changeset
   647
              field_count = survey_table.find('fieldset').length;
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   648
              new_field_count = field_count + 1 + '__';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   649
              var formatted_name = (SURVEY_PREFIX + new_field_count + type +
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   650
                                    field_name);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   651
              if (button_id === 'choice')  {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   652
                var name = (field_name);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   653
                new_field = $([
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   654
                  '<fieldset>\n', '<label for="required_for_', name,
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   655
                  '">Required</label>',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   656
                  '<select id="required_for_', name, '" name="required_for_',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   657
                  name, '"><option value="True" selected="selected">True',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   658
                  '</option>', '<option value="False">False</option>',
2526
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   659
                  '</select>', '<label for="comment_for_', name,
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   660
                  '">Allow Comments</label>', '<select id="comment_for_', name,
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   661
                  '" name="comment_for_', name, '">',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   662
                  '<option value="True" selected="selected">True</option>',
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   663
                  '<option value="False">False</option>',
2526
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   664
                  '</select>',
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   665
                  '<label for="render_for_', name,
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   666
                  '">Render as</label>', '\n  <select id="render_for_', name,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   667
                  '" name="render_for_', name, '">', '\n    <option',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   668
                  'selected="selected" value="select">select</option>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   669
                  '\n    <option value="checkboxes">checkboxes</option>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   670
                  '\n    <option value="radio_buttons">radio_buttons</option>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   671
                  '\n  </select>', '\n  <input type="hidden" id="order_for_',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   672
                  name, '\n  " name="order_for_', name, '" value=""/>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   673
                  '\n  <input type="hidden" id="index_for_', name,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   674
                  '\n  " name="index_for_', name, '" value="',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   675
                  (field_count + 1), '"/>\n  <ol id="', name,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   676
                  '" class="sortable"></ol>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   677
                  question_for, '\n  <button name="create-option-button"',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   678
                  'id="create-option-button__', name,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   679
                  '" class="ui-button ui-state-default ui-corner-all" value="',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   680
                  name, '" onClick="return false;">Create new option',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   681
                  '</button>\n</fieldset>'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   682
                ].join(""));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   683
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   684
                $(new_field).attr({
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   685
                  'id': 'id_' + formatted_name,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   686
                  'name': formatted_name
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   687
                });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   688
                field_template
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   689
                .find(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   690
                  'label'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   691
                )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   692
                .attr(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   693
                  'for',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   694
                  'NEW_' + name
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   695
                )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   696
                .append(question_content).end()
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   697
                .find(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   698
                  'td'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   699
                )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   700
                .append(new_field);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   701
                survey_table.append(field_template).end();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   702
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   703
                if (question_options) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   704
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   705
                  var options_array = question_options.split('\n');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   706
                  var ol = $('#' + name);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   707
                  var length = options_array.length;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   708
                  var oname = '';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   709
                  var id_ = '';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   710
                  var option_html = '';
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   711
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   712
                  for (var i = 0; i < length; i = i + 1) {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   713
                    id_ = 'id_' + name + '_' + i;
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   714
                    oname = options_array[i];
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   715
                    option_html = $([
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   716
                      '<li id="id-li-', name, '_', i,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   717
                      '" class="ui-state-defaolt sortable_li">',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   718
                      '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   719
                      '<span id="' + id_ + '" class="editable_option" name="',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   720
                      id_, '__field">', oname, '</span>', '<input ',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   721
                      'type="hidden" id="', id_, '__field" name="', id_,
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2670
diff changeset
   722
                      '__field" value="', oname.replace(/\"/g, '&quot;'), '" >', '</li>'
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   723
                    ].join(""));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   724
                    ol.append(option_html.prepend(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   725
                      del_li.join(option_html.attr('id'))));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   726
                    ol.sortable().disableSelection();
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   727
                  }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   728
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   729
                  survey.trigger('option_init');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   730
                }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   731
              }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   732
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   733
              else {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   734
                new_field = $(new_field);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   735
                // maybe the name should be serialized in a more common format
2502
2e096acc8720 Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents: 2423
diff changeset
   736
                $(new_field).find('.long_answer, .short_answer').attr({
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   737
                  'id': 'id_' + formatted_name,
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   738
                  'name': formatted_name
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   739
                });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   740
                field_template.find(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   741
                  'label'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   742
                )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   743
                .attr(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   744
                  'for',
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   745
                  'id_' + formatted_name
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   746
                )
2526
8f29bfb9eb52 Survey editing/taking Javascript and CSS fixes.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2505
diff changeset
   747
                .append(question_content).end()
2423
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   748
                .find(
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   749
                  'td'
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   750
                )
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   751
                .append(new_field).append($(question_for));
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   752
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   753
                survey_table.append(field_template);
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   754
              }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   755
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   756
              survey.trigger('init');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   757
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   758
            }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   759
          }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   760
          $("#new_question_name").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   761
          $("#new_question_content").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   762
          $("#new_question_options").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   763
          $(this).dialog('close');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   764
        },
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   765
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   766
        Cancel: function () {
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   767
          $('#new_question_name').val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   768
          $("#new_question_button_id").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   769
          $("#new_question_content").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   770
          $("#new_question_options").val('');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   771
          $(this).dialog('close');
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   772
        }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   773
      }
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   774
    });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   775
  });
d6b4be046c26 Adding JS files for use in Surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   776
}(jQuery));