lib/netzke/window.rb in netzke-basepack-0.5.6 vs lib/netzke/window.rb in netzke-basepack-0.5.7

- old
+ new

@@ -1,17 +1,16 @@ module Netzke # == Window - # Ext.Window-based widget + # Ext.Window-based widget able to nest other Netzke widgets # # == Features - # * Persistent position - # * Persistent dimensions + # * Persistent position and dimensions # # == Instance configuration - # <tt>:height</tt> and <tt>:width</tt> - besides accepting a number (which would be just standard ExtJS), - # can accept a string specifying relative sizes, calculated from current browser window dimensions. - # E.g.: :height => "90%", :width => "60%" + # <tt>:item</tt> - nested Netzke widget, e.g.: + # + # netzke :window, :item => {:class_name => "GridPanel", :model => "User"} class Window < Base # Based on Ext.Window, naturally def self.js_base_class "Ext.Window" end @@ -24,60 +23,60 @@ end # Extends the JavaScript class def self.js_extend_properties { + # we nest widget inside the "fit" layout :layout => "fit", + # default width and height + :width => 300, + :height => 200, + :init_component => <<-END_OF_JAVASCRIPT.l, function(){ - // Width and height may be specified as percentage of available space, e.g. "60%". - // Convert them into actual pixels. - Ext.each(["width", "length"], function(k){ - if (Ext.isString(this[k])) { - this[k] = Ext.lib.Dom.getViewHeight() * parseFloat("." + this[k].substr(0, this[k].length - 1)); // "66%" => ".66" - } - }); - - // Superclass' initComponent + // superclass' initComponent #{js_full_class_name}.superclass.initComponent.call(this); - // Set the move and resize events after window is shown, so that they don't fire at initial rendering + // set the move and resize events after window is shown, so that they don't fire at initial rendering this.on("show", function(){ - this.on("move", this.onMove, this); - this.on("resize", this.onSelfResize, this); // Work around firing "resize" event twice (currently a bug in ExtJS) + this.on("move", this.onMoveResize, this); + this.on("resize", this.onMoveResize, this); }, this); + // instantiate the aggregatee if (this.itemConfig){ this.instantiateChild(this.itemConfig); } } END_OF_JAVASCRIPT - :on_move => <<-END_OF_JAVASCRIPT.l, - function(w,x,y){ - this.moveToPosition({x:x, y:y}); - } - END_OF_JAVASCRIPT + :on_move_resize => <<-END_OF_JAVASCRIPT.l, + function(){ + var x = this.getPosition()[0], y = this.getPosition()[1], w = this.getSize().width, h = this.getSize().height; - :on_self_resize => <<-END_OF_JAVASCRIPT.l, - function(w, width, height){ - this.selfResize({w:width, h:height}); + // Don't bother the server twice when both move and resize events are fired at the same time + // (which happens when the left or upper window border is dragged) + if (this.moveResizeTimer) {clearTimeout(this.moveResizeTimer)}; + + this.moveResizeTimer = (function(sizeAndPosition){ + this.setSizeAndPosition(sizeAndPosition); // API call + }).defer(10, this, [{x:x, y:y, w:w, h:h}]); // 10ms should be enough } END_OF_JAVASCRIPT + } end # Processing API calls from client - api :move_to_position - def move_to_position(params) - update_persistent_ext_config(:x => params[:x].to_i, :y => params[:y].to_i) - {} - end - - api :self_resize - def self_resize(params) - update_persistent_ext_config(:width => params[:w].to_i, :height => params[:h].to_i) + api :set_size_and_position + def set_size_and_position(params) + update_persistent_ext_config( + :x => params[:x].to_i, + :y => params[:y].to_i, + :width => params[:w].to_i, + :height => params[:h].to_i + ) {} end end end \ No newline at end of file