Created
March 9, 2011 20:04
-
-
Save danil-z/862885 to your computer and use it in GitHub Desktop.
components in session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdminSimpleApp < Netzke::Basepack::SimpleApp | |
#......... | |
def deliver_component_endpoint(params) | |
#if %w(schedule_panel, journal_panel).include?(params[:name]) | |
components[params[:name].to_sym].merge!(:school_id => params[:obj_id].to_i) | |
# for empty tabs | |
wipe_out_journal_pages(params[:name]) if params[:name] == "journal_panel" | |
super | |
end | |
def wipe_out_journal_pages(key_to_clear) | |
session.delete("#{key_to_clear}_items') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Blackbumer | |
class JournalSubjectTabPanel < Netzke::Base | |
js_base_class "Ext.TabPanel" | |
def final_config | |
tabs = stored_tabs.map { |tab| {:layout => :fit, :name => tab[:name], :title => tab[:title], :items => [ tab[:name].to_sym.component]} } || [] | |
orig = super | |
orig.merge( | |
:items => tabs | |
) | |
end | |
def stored_tabs | |
@stored_tabs = session["#{name}_items"] || [] | |
end | |
# Extends config stored in persistent_config | |
def normalize_config(c) | |
{ | |
:name => c[:name], | |
:title => c[:title], | |
:header => false | |
}.merge(config[:tab_component_config]) | |
end | |
def components | |
stored_tabs.inject({}){ |r,tab| r.merge(tab[:name].to_sym => config[:tab_component_config].merge(tab)) } | |
end | |
def default_config | |
super.merge({:tab_component_config => {:class_name => "Blackbumer::SubjectPageTabPanel"}}) | |
end | |
endpoint :select_classroom do |params| | |
component_session[:classroom_id] = params[:classroom_id].to_i | |
{} | |
end | |
endpoint :select_jdate do |params| | |
component_session[:jdate] = params[:jdate].to_date | |
{} | |
end | |
def conf_for_new_tab(obj) | |
{:name => "subject#{obj.id}", | |
:title=> obj.title, | |
:subject_id => obj.id, | |
:classroom_id => component_session[:classroom_id], | |
:jdate => component_session[:jdate] | |
} | |
end | |
endpoint :server_get_new_tabs do |params| | |
new_tabs_array = Subject.for_classroom_for_day(component_session[:classroom_id],component_session[:jdate]).map {|s| conf_for_new_tab(s)} || [] | |
@stored_tabs = new_tabs_array | |
session["#{name}_items"] = new_tabs_array | |
configs_tab_array = new_tabs_array.map {|t| component_instance(t[:name].to_sym).js_config} | |
if new_tabs_array.length > 0 | |
component = component_instance(new_tabs_array[0][:name].to_sym) if new_tabs_array.length > 0 | |
[{ | |
:eval_js => component.js_missing_code(params[:cache].to_s), | |
:eval_css => component.css_missing_code(params[:cache].to_s) | |
},{:add_tabs_from_server => configs_tab_array.to_nifty_json} | |
] | |
else | |
{} | |
end | |
end | |
js_method :add_tabs_from_server, <<-JS | |
function(params){ | |
Ext.each(Ext.decode(params), this.addTab, this); | |
} | |
JS | |
js_method :add_tab, <<-JS | |
function(mytab){ | |
var newTab = new Ext.Panel({ | |
title : mytab.title, | |
layout : 'fit' | |
}); | |
this.add(newTab); | |
this.instantiateAndRenderComponent(mytab,newTab.id); | |
} | |
JS | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment