Show
Ignore:
Timestamp:
10/18/08 16:34:04 (3 months ago)
Author:
nick
Message:

Make a start on JS to help you pick locales and categories, but not quite finished yet

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/templates/edit_form.tt

    r1083 r1229  
    9595          [% ELSE %] 
    9696            Locales (one per line): 
     97            <span id="pick_locale"></span> 
    9798          [% END %] 
    9899        </label> 
     
    119120          [% ELSE %] 
    120121            Categories (one per line): 
     122            <span id="pick_category"></span> 
    121123          [% END %] 
    122124        </label> 
     
    136138        [% END %] 
    137139      </div> 
     140 
     141          <script type="text/javascript"> 
     142             function pick(metadata_type, textbox_id) { 
     143                    var textbox = document.getElementById(textbox_id); 
     144 
     145                        // For adding the new metadata to the textarea 
     146                        var add_md = function(picked) { 
     147                           var last = textbox.value.substring(textbox.value.length - 1); 
     148                           if(last == "\r" || last == "\n") { 
     149                              // Already has new line 
     150                           } else { 
     151                              textbox.value = textbox.value + "\r\n"; 
     152                           } 
     153 
     154                           textbox.value = textbox.value + picked; 
     155                        }; 
     156 
     157                        // Fetch the data 
     158                        $.getJSON("[% cgi_url %]?action=metadata;format=json;type=" + metadata_type, function(data) { 
     159//                              alert(data[metadata_type][0]); 
     160//                              add_md(data[metadata_type][1]); 
     161                        }); 
     162                 } 
     163 
     164             function pick_locale() { 
     165                    pick("locale", "locales"); 
     166                 } 
     167             function pick_category() { 
     168                    pick("category", "categories"); 
     169                 } 
     170 
     171             $(document).ready(function() { 
     172                    $("#pick_locale").html("<a href='javascript:pick_locale()'>pick Locale</a>"); 
     173                    $("#pick_category").html("<a href='javascript:pick_category()'>pick Category</a>"); 
     174                 }); 
     175          </script> 
    138176 
    139177      <div class="edit_form_group" id="summary_group">