app/soc/content/js/survey-edit-090703.js
changeset 2560 a944c0169ad8
parent 2541 7ef468836f6e
equal deleted inserted replaced
2559:af2874bc01f3 2560:a944c0169ad8
    74           $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
    74           $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
    75                              'short_answer__' + $(this).attr('name'));
    75                              'short_answer__' + $(this).attr('name'));
    76         }
    76         }
    77       );
    77       );
    78 
    78 
       
    79       // add index information to choice fields
       
    80       widget.find('[name=create-option-button]').each(
       
    81         function () {
       
    82           $(
       
    83             '#index_for_' + $(this).attr('value')
       
    84           )
       
    85           .val(
       
    86             $(this).getPosition()
       
    87           );
       
    88         }
       
    89       );
       
    90 
    79       widget.find('.long_answer').each(
    91       widget.find('.long_answer').each(
    80         function () {
    92         function () {
    81           $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
    93           $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
    82                              'long_answer__' + $(this).attr('name'))
    94                              'long_answer__' + $(this).attr('name'))
    83           .attr('overflow', 'auto');
    95           .attr('overflow', 'auto');
   157               $(this).preserveDefaultText(DEFAULT_SHORT_ANSWER_TEXT);
   169               $(this).preserveDefaultText(DEFAULT_SHORT_ANSWER_TEXT);
   158             }
   170             }
   159           }
   171           }
   160         );
   172         );
   161 
   173 
   162         widget.find('.long_answer').each(
   174         widget.find('.long_answer, .tooltip_entry').each(
   163           function () {
   175           function () {
   164             if ($(this).val().length < 1 ||
   176             if ($(this).val().length < 1 ||
   165             $(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
   177             $(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
   166               $(this).preserveDefaultText(DEFAULT_LONG_ANSWER_TEXT);
   178               $(this).preserveDefaultText(DEFAULT_LONG_ANSWER_TEXT);
   167             }
   179             }
   348             }
   360             }
   349           }
   361           }
   350         );
   362         );
   351 
   363 
   352         // don't save default value
   364         // don't save default value
   353         widget.find('.long_answer').each(
   365         widget.find('.long_answer, .tooltip_entry').each(
   354           function () {
   366           function () {
   355             if ($(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
   367             if ($(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
   356               $(this).val('');
   368               $(this).val('');
   357             }
   369             }
   358           }
   370           }
   395   */
   407   */
   396   jQuery.fn.extend({
   408   jQuery.fn.extend({
   397 
   409 
   398     // get position of survey field
   410     // get position of survey field
   399     getPosition: function () {
   411     getPosition: function () {
   400       var this_row = $(this).parents('tr:first');
   412       var this_fieldset = $(this).parents('fieldset:first');
   401       var this_table = this_row.parents('table:first');
   413       var this_table = this_fieldset.parents('table:first');
   402       var position = this_table.find('tr').index(this_row) + '__';
   414       var position = this_table.find('fieldset').index(this_fieldset) + '__';
   403       return position;
   415       return position;
   404     }
   416     }
   405   });
   417   });
   406 }(jQuery));
   418 }(jQuery));
   407 
   419 
   553             $("#new_question_content").val('');
   565             $("#new_question_content").val('');
   554             $("#new_question_options").val('');
   566             $("#new_question_options").val('');
   555 
   567 
   556             var new_field = false;
   568             var new_field = false;
   557             var type = button_id + "__";
   569             var type = button_id + "__";
   558             var field_count = survey_table.find('tr').length;
   570             var field_count = survey_table.find('fieldset').length;
   559             var new_field_count = field_count + 1 + '__';
   571             var new_field_count = field_count + 1 + '__';
   560 
   572 
   561             var MIN_ROWS = 10;
   573             var MIN_ROWS = 10;
   562             var MAX_ROWS = MIN_ROWS * 2;
   574             var MAX_ROWS = MIN_ROWS * 2;
   563             var DEFAULT_OPTION_TEXT = 'Add A New Option...';
   575             var DEFAULT_OPTION_TEXT = 'Add A New Option...';
   584                           "<input type='text' ",
   596                           "<input type='text' ",
   585                            "class='short_answer'>", "</fieldset>"
   597                            "class='short_answer'>", "</fieldset>"
   586                           ].join("");
   598                           ].join("");
   587               break;
   599               break;
   588             case "long_answer":
   600             case "long_answer":
   589               field_count = survey_table.find('tr').length;
   601               field_count = survey_table.find('fieldset').length;
   590               new_field_count = field_count + 1 + '__';
   602               new_field_count = field_count + 1 + '__';
   591               new_field = ['<fieldset>\n', '<label for="required_for_',
   603               new_field = ['<fieldset>\n', '<label for="required_for_',
   592                            field_name, '">Required</label>',
   604                            field_name, '">Required</label>',
   593                            '<select id="required_for_', field_name,
   605                            '<select id="required_for_', field_name,
   594                            '" name="required_for_', field_name,
   606                            '" name="required_for_', field_name,
   626                 '\n  <input type="hidden" name="NEW_', field_name,
   638                 '\n  <input type="hidden" name="NEW_', field_name,
   627                 '" id="NEW_', field_name, '" value="', question_content,
   639                 '" id="NEW_', field_name, '" value="', question_content,
   628                 '"/>'
   640                 '"/>'
   629               ].join("");
   641               ].join("");
   630 
   642 
   631               field_count = survey_table.find('tr').length;
   643               field_count = survey_table.find('fieldset').length;
   632               new_field_count = field_count + 1 + '__';
   644               new_field_count = field_count + 1 + '__';
   633               var formatted_name = (SURVEY_PREFIX + new_field_count + type +
   645               var formatted_name = (SURVEY_PREFIX + new_field_count + type +
   634                                     field_name);
   646                                     field_name);
   635               if (button_id === 'choice')  {
   647               if (button_id === 'choice')  {
   636                 var name = (field_name);
   648                 var name = (field_name);