Revision d790d9b7 ui/static/synnefo.js

b/ui/static/synnefo.js
90 90
   
91 91
}
92 92

  
93
// http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area 
94
$.fn.setCursorPosition = function(pos) {
95
    if ($(this).get(0).setSelectionRange) {
96
      $(this).get(0).setSelectionRange(pos, pos);
97
    } else if ($(this).get(0).createTextRange) {
98
      var range = $(this).get(0).createTextRange();
99
      range.collapse(true);
100
      range.moveEnd('character', pos);
101
      range.moveStart('character', pos);
102
      range.select();
103
    }
104
}
105

  
93 106
// jquery show/hide events
94 107
var _oldshow = $.fn.show;
95 108
$.fn.show = function(speed, callback) {
......
2133 2146

  
2134 2147

  
2135 2148
// generic info box
2136
function show_feedback_form() {
2149
function show_feedback_form(msg, from_error) {
2137 2150
    var box = $("#feedback-form");
2138 2151
    box.addClass("notification-box");
2139 2152

  
......
2141 2154
    box.find(".form-container").show();
2142 2155
    box.find("textarea").val("");
2143 2156
    box.find(".message").hide();
2144

  
2157
    
2158
    var initial_msg = msg || undefined;
2159
    
2145 2160
    var triggers = $("a#feedbackbox").overlay({
2146 2161
        // some mask tweaks suitable for modal dialogs
2147 2162
        mask: '#666',
......
2149 2164
        fixed: false,
2150 2165
        closeOnClick: false,
2151 2166
        oneInstance: false,
2152
        load: false,
2153
        onClose: function () {
2154
            // With partial refresh working properly,
2155
            // it is no longer necessary to refresh the whole page
2156
            // choose_view();
2157
        }
2167
        load: false
2158 2168
    });
2169

  
2159 2170
    
2171
    if (initial_msg && from_error) {
2172
        // feedback form from ajax_error window
2173
        box.find("textarea").val(initial_msg);
2174
        $("a#feedbackbox").overlay().onClose(function(){window.location.reload()});
2175
        box.find("textarea").height(200);
2176
        $("a#feedbackbox").overlay().onLoad(function(){box.find("textarea").focus().setCursorPosition(500);});
2177
        
2178
    }
2179

  
2160 2180
    $("#feedback-form form").unbind("submit");
2161 2181
    $("#feedback-form form").submit(function(event) {
2162 2182
        event.preventDefault();
......
2185 2205
    });
2186 2206
    
2187 2207
    $("a#feedbackbox").data('overlay').load();
2208

  
2209
    // reset feedback_pending for ajax_errors
2210
    window.FEEDBACK_PENDING = false;
2188 2211
    return false;
2189 2212
}
2190 2213

  

Also available in: Unified diff