Changeset 2524

Show
Ignore:
Timestamp:
02/04/10 15:42:29 (6 weeks ago)
Author:
JensDiemer
Message:
  • Add confirm dialog for inline editing, if textarea content was changed.
  • Bugfix resize buttons in inline ajax editing view.
  • Don't send the inline form via ajax
Location:
branches/0.9/pylucid_project
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/pylucid_project/media/PyLucid/pylucid_js_tools.js

    r2516 r2524  
    1  
    21 
    32// helper function for console logging 
     
    87        window.console.log(Array.prototype.join.call(arguments,'')); 
    98} 
     9log("pylucid_js_tools.js loaded."); 
    1010 
    1111 
     
    4848        replace_complete_page(data) 
    4949    } else { 
     50        // log("put in #page_content:" + data); 
    5051        $("#page_content").html(data); 
    5152        $("#page_content").animate({ 
     
    7475 
    7576 
     77 
    7678function pylucid_ajax_form_view(form_id) { 
    7779    /************************************************************************* 
     
    9092    *************************************************************************/ 
    9193    $(form_id).bind('submit', function() { 
     94        var form = $(this); 
     95        log("pylucid_ajax_form_view submit form:" + form); 
    9296         
    9397        $("#page_content").html('<h2>send...</h2>'); 
     
    9599            opacity: 0.3 
    96100        }, 500 ); 
    97  
    98         var form = $(this); 
     101     
    99102        var form_data = form.serialize(); 
    100103        log("form data:" + form_data); 
     
    119122                log("complete:" + XMLHttpRequest.status); 
    120123                log("complete:" + XMLHttpRequest.getResponseHeader('Location')); 
    121                  
     124                 
    122125                if(XMLHttpRequest.status.toString()[0]=='3'){ 
    123126                    top.location.href = XMLHttpRequest.getResponseHeader('Location'); 
     
    130133        log("ajax done:" + XMLHttpRequest.getResponseHeader('Location')); 
    131134        return load_normal_link; // <-- important: Don't send the form in normal way. 
    132     });  
     135    }); 
    133136} 
    134137 
     
    206209 
    207210 
    208 MIN_ROWS = 5; 
    209 MAX_ROWS = 25; 
    210 MAX_LENGTH = 100; 
    211 RESIZE_FACTOR = 1.3; 
    212 jQuery(document).ready(function($) { 
    213     /************************************************************************* 
    214          * textarea resize buttons 
    215          */ 
     211var MIN_ROWS = 5; 
     212var MAX_ROWS = 25; 
     213var MAX_LENGTH = 100; 
     214var RESIZE_FACTOR = 1.3; 
     215 
     216function activate_resize_textarea_buttons() { 
     217    /************************************************************************* 
     218     * textarea resize buttons 
     219     */ 
     220    log("activate_resize_textarea_buttons()"); 
    216221    $(".resize_textarea" ).click(function () { 
    217222        button_id = $(this).attr('id'); 
    218         //              log("Clicked on: " + button_id); 
     223        //      log("Clicked on: " + button_id); 
    219224        var pos = button_id.indexOf("_"); 
    220225        var action = button_id.slice(0, pos); 
    221226        var textarea_id = button_id.slice(pos+1, button_id.length); 
    222         //              log("action:" + action); 
    223         //              log("textarea id:" + textarea_id); 
     227        //      log("action:" + action); 
     228        //      log("textarea id:" + textarea_id); 
    224229        var textarea = $("#"+textarea_id); 
    225230        var old_rows = textarea.attr("rows"); 
    226                  
     231         
    227232        var new_rows = false; 
    228233        if (action=="smaller") { 
     
    236241            new_rows = Math.ceil(old_rows * RESIZE_FACTOR); 
    237242        } 
    238                  
     243         
    239244        if (new_rows == false) { 
    240245            log("Error: Wrong textarea resize action:" + action); 
    241246            return; 
    242247        } 
    243         //              log("old rows:" + old_rows + " - new rows:" + new_rows); 
     248        //      log("old rows:" + old_rows + " - new rows:" + new_rows); 
    244249        textarea.animate({ 
    245250            rows: new_rows 
    246251        }, 100 ); 
    247252    }); 
     253} 
     254 
     255jQuery(document).ready(function($) { 
     256    activate_resize_textarea_buttons(); 
    248257         
    249258    /************************************************************************* 
  • branches/0.9/pylucid_project/pylucid_plugins/page_admin/templates/page_admin/edit_inline_form.html

    r2449 r2524  
    2020 
    2121<script type="text/javascript"> 
    22 $(document).ready(function(){ 
     22var textarea_changed = false; 
     23 
     24jQuery(document).ready(function($) { 
     25    log("edit_inline_form.html ready."); 
     26      
    2327    $("#ajax_preview").show(); // unhide ajax preview button 
    2428    
     29    $("#edit_page_form").change(function() { 
     30        log("edit page form change"); 
     31        textarea_changed = true; 
     32    }); 
     33    $("#edit_page_form").keypress(function() { 
     34        log("edit page form keypress"); 
     35        textarea_changed = true; 
     36    }); 
     37    $("#edit_page_form").bind('submit', function() { 
     38        log("submit: set textarea_changed = false"); 
     39        textarea_changed = false; 
     40        // $("#preview_fieldset").slideUp("slow"); 
     41        $("#edit_page_form").before('<h2 class="ajax_msg">{% trans "submit" %}...</h2>'); 
     42    }); 
     43     
     44    // $(window).bind('beforeunload', function() { 
     45    // ^ this doesn't work! 
     46    window.onbeforeunload = function() { 
     47        log("beforeunload evend called. textarea_changed:" + textarea_changed); 
     48        if (textarea_changed == true) { 
     49            return "{% trans "Textarea has been changed! Changes are not saved if you leave." %}";  
     50        } 
     51    } 
     52    
    2553    // from media/PyLucid/pylucid_js_tools.js 
    26     pylucid_ajax_form_view('#edit_page_form'); 
     54    // pylucid_ajax_form_view('#edit_page_form'); 
    2755    replace_openinwindow_links(); 
    2856     
     
    3058     
    3159    $("#ajax_preview").click(function() { 
    32         $("#edit_page_preview").html("<h2>loading...</h2>"); 
     60        log("ajax preview clicked"); 
     61        {# It's important here to add a class in h2 tag to make it invisible for the headline ancor! #} 
     62        $("#edit_page_preview").html('<h2 class="ajax_msg">{% trans "loading" %}...</h2>'); 
    3363        $("#preview_fieldset").slideDown(); 
    3464     
     
    4373        }); 
    4474    }); 
    45     $("#submit_preview").hide();     
     75    $("#submit_preview").hide(); 
     76     
     77    $("#abort_button").click(function() { 
     78        $("#edit_page_form").before('<h2 class="ajax_msg">{% trans "abort" %}...</h2>'); 
     79        self.location.href='{{ abort_url }}'; 
     80    }); 
     81     
     82    activate_resize_textarea_buttons(); 
    4683}); 
    4784</script> 
     
    64101         {% trans 'markup preview' %} 
    65102     </button> 
    66      <input onclick="self.location.href='{{ abort_url }}'" name="abort" value="{% trans 'abort' %}" type="reset" /> 
     103     <input type="button" id="abort_button" name="abort" value="{% trans 'abort' %}" /> 
    67104     <a href="{{ pagelinklist_url }}" class="openinwindow" title="{% trans 'List of all pages for creating links' %}"> 
    68105         <button type="button" class="button">{% trans 'page list' %}</button>