netzke-core 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v0.2.4
2
+ Some minor improvements.
3
+
1
4
  v0.2.3
2
5
  FeedbackGhost will show the feedback on the top of the screen independent of the page scrolling.
3
6
  Ext.Panel#loadWidget will accept null as url to delete the currently loaded widget
data/javascripts/core.js CHANGED
@@ -10,126 +10,126 @@ Ext.Ajax.extraParams = {
10
10
 
11
11
  // helper method to do multiple Ext.apply's
12
12
  Ext.chainApply = function(objectArray){
13
- var res = {};
14
- Ext.each(objectArray, function(obj){Ext.apply(res, obj)});
15
- return res;
13
+ var res = {};
14
+ Ext.each(objectArray, function(obj){Ext.apply(res, obj)});
15
+ return res;
16
16
  };
17
17
 
18
18
  // implementation of totalProperty, successProperty and root configuration options for ArrayReader
19
19
  Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {
20
- readRecords : function(o){
21
- var sid = this.meta ? this.meta.id : null;
22
- var recordType = this.recordType, fields = recordType.prototype.fields;
23
- var records = [];
24
- // console.info(this.meta);
25
- var root = o[this.meta.root] || o, totalRecords = o[this.meta.totalProperty], success = o[this.meta.successProperty];
26
- for(var i = 0; i < root.length; i++){
27
- var n = root[i];
28
- var values = {};
29
- var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
30
- for(var j = 0, jlen = fields.length; j < jlen; j++){
31
- var f = fields.items[j];
32
- var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
33
- var v = n[k] !== undefined ? n[k] : f.defaultValue;
34
- v = f.convert(v, n);
35
- values[f.name] = v;
36
- }
37
- var record = new recordType(values, id);
38
- record.json = n;
39
- records[records.length] = record;
40
- }
41
- return {
42
- records : records,
43
- totalRecords : totalRecords,
44
- success : success
45
- };
20
+ readRecords : function(o){
21
+ var sid = this.meta ? this.meta.id : null;
22
+ var recordType = this.recordType, fields = recordType.prototype.fields;
23
+ var records = [];
24
+ // console.info(this.meta);
25
+ var root = o[this.meta.root] || o, totalRecords = o[this.meta.totalProperty], success = o[this.meta.successProperty];
26
+ for(var i = 0; i < root.length; i++){
27
+ var n = root[i];
28
+ var values = {};
29
+ var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
30
+ for(var j = 0, jlen = fields.length; j < jlen; j++){
31
+ var f = fields.items[j];
32
+ var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
33
+ var v = n[k] !== undefined ? n[k] : f.defaultValue;
34
+ v = f.convert(v, n);
35
+ values[f.name] = v;
36
+ }
37
+ var record = new recordType(values, id);
38
+ record.json = n;
39
+ records[records.length] = record;
46
40
  }
41
+ return {
42
+ records : records,
43
+ totalRecords : totalRecords,
44
+ success : success
45
+ };
46
+ }
47
47
  });
48
48
 
49
49
  // Methods common to all widget classes
50
50
  Ext.widgetMixIn = {
51
- widgetInit:function(config){
51
+ widgetInit:function(config){
52
52
  this.app = Ext.getCmp('feedback_ghost');
53
53
  // this.app = Ext.getCmp('application');
54
54
  if (config.tools) Ext.each(config.tools, function(i){i.on.click = this[i.on.click].createDelegate(this)}, this);
55
55
  if (config.actions) Ext.each(config.actions, function(i){i.handler = this[i.handler].createDelegate(this);}, this);
56
- },
56
+ },
57
57
 
58
- setEvents: function(){
59
- this.on('beforedestroy', function(){
60
- // clean-up menus
61
- if (this.app && !!this.app.unhostMenus) {
62
- // alert('beforedestroy');
63
- this.app.unhostMenus(this)
64
- }
65
- }, this);
66
-
67
- this.on('render', this.onWidgetLoad, this);
68
- },
58
+ setEvents: function(){
59
+ this.on('beforedestroy', function(){
60
+ // clean-up menus
61
+ if (this.app && !!this.app.unhostMenus) {
62
+ // alert('beforedestroy');
63
+ this.app.unhostMenus(this)
64
+ }
65
+ }, this);
66
+
67
+ this.on('render', this.onWidgetLoad, this);
68
+ },
69
69
 
70
- feedback:function(msg){
71
- if (this.initialConfig.quiet) return false;
72
- if (this.app && !!this.app.showFeedback) {
73
- this.app.showFeedback(msg)
74
- } else {
75
- // there's no application to show the feedback - so, we do it ourselves
76
- if (typeof msg == 'string'){
77
- alert(msg)
78
- } else {
79
- var compoundResponse = ""
80
- Ext.each(msg, function(m){
70
+ feedback:function(msg){
71
+ if (this.initialConfig.quiet) return false;
72
+ if (this.app && !!this.app.showFeedback) {
73
+ this.app.showFeedback(msg)
74
+ } else {
75
+ // there's no application to show the feedback - so, we do it ourselves
76
+ if (typeof msg == 'string'){
77
+ alert(msg)
78
+ } else {
79
+ var compoundResponse = ""
80
+ Ext.each(msg, function(m){
81
81
  compoundResponse += m.msg + "\n"
82
82
  })
83
- if (compoundResponse != "") alert(compoundResponse);
84
- }
85
- };
86
- },
83
+ if (compoundResponse != "") alert(compoundResponse);
84
+ }
85
+ };
86
+ },
87
87
 
88
- addMenus:function(menus){
89
- if (this.app && !!this.app.hostMenu) {
90
- Ext.each(menus, function(menu){this.app.hostMenu(menu, this)}, this)
91
- }
92
- },
93
-
94
- onWidgetLoad:Ext.emptyFn // gets overridden
88
+ addMenus:function(menus){
89
+ if (this.app && !!this.app.hostMenu) {
90
+ Ext.each(menus, function(menu){this.app.hostMenu(menu, this)}, this)
91
+ }
92
+ },
93
+
94
+ onWidgetLoad:Ext.emptyFn // gets overridden
95
95
  };
96
96
 
97
97
  // Make Panel with layout 'fit' capable to dynamically load widgets
98
98
  Ext.override(Ext.Panel, {
99
- getWidget: function(){
100
- return this.items.get(0)
101
- },
102
-
103
- loadWidget: function(url, params){
104
- if (!params) params = {}
105
-
106
- this.remove(this.getWidget()); // first delete previous widget
107
-
108
- if (!url) return false;
109
-
110
- // we will let the server know which components we have cached
111
- var cachedComponentNames = [];
112
- for (name in Ext.componentCache) {
113
- cachedComponentNames.push(name);
114
- }
115
-
116
- this.disable(); // to visually emphasize loading
117
-
118
- Ext.Ajax.request(
119
- {url:url, params:Ext.apply(params, {components_cache:Ext.encode(cachedComponentNames)}), script:false, callback:function(panel, success, response){
120
- var response = Ext.decode(response.responseText);
121
- if (response['classDefinition']) eval(response['classDefinition']); // evaluate widget's class if it was sent
99
+ getWidget: function(){
100
+ return this.items.get(0)
101
+ },
102
+
103
+ loadWidget: function(url, params){
104
+ if (!params) params = {}
105
+
106
+ this.remove(this.getWidget()); // first delete previous widget
107
+
108
+ if (!url) return false; // don't load any widget if the url is null
109
+
110
+ // we will let the server know which components we have cached
111
+ var cachedComponentNames = [];
112
+ for (name in Ext.componentCache) {
113
+ cachedComponentNames.push(name);
114
+ }
115
+
116
+ this.disable(); // to visually emphasize loading
117
+
118
+ Ext.Ajax.request(
119
+ {url:url, params:Ext.apply(params, {components_cache:Ext.encode(cachedComponentNames)}), script:false, callback:function(panel, success, response){
120
+ var response = Ext.decode(response.responseText);
121
+ if (response['classDefinition']) eval(response['classDefinition']); // evaluate widget's class if it was sent
122
122
 
123
- response.config.parent = this // we might want to know the parent panel in advance (e.g. to know its size)
124
- var instance = new Ext.componentCache[response.config.widgetClassName](response.config)
125
-
126
- this.add(instance);
127
- this.doLayout();
128
- this.enable();
129
- }, scope:this}
130
- )
131
-
132
- }
123
+ response.config.parent = this // we might want to know the parent panel in advance (e.g. to know its size)
124
+ var instance = new Ext.componentCache[response.config.widgetClassName](response.config)
125
+
126
+ this.add(instance);
127
+ this.doLayout();
128
+ this.enable();
129
+ }, scope:this}
130
+ )
131
+
132
+ }
133
133
  });
134
134
 
135
135
  // Some Rubyish String extensions
@@ -24,7 +24,7 @@ class NetzkeLayout < ActiveRecord::Base
24
24
  end
25
25
 
26
26
  def self.by_widget(widget_name)
27
- self.find(:first, :conditions => {:widget_name => widget_name, :user_id => user_id})
27
+ self.find(:first, :conditions => {:widget_name => widget_name.to_s, :user_id => user_id})
28
28
  end
29
29
 
30
30
  def move_item(old_index, new_index)
@@ -30,17 +30,14 @@ class NetzkePreference < ActiveRecord::Base
30
30
  end
31
31
 
32
32
  def normalized_value
33
- klass = read_attribute(:pref_type)
33
+ klass = read_attribute(:pref_type)
34
34
  norm_value = read_attribute(:value)
35
- if klass.nil?
36
- # do not cast
37
- r = norm_value
38
- elsif klass == 'Boolean'
39
- r = norm_value == 'false' ? false : (norm_value == 'true' || norm_value)
40
- elsif klass == 'NilClass'
41
- r = nil
42
- elsif klass == 'Array' || klass == 'Hash'
43
- r = JSON.parse(norm_value)
35
+
36
+ case klass
37
+ when nil then r = norm_value # do not cast
38
+ when 'Boolean' then r = norm_value == 'false' ? false : (norm_value == 'true' || norm_value)
39
+ when 'NilClass' then r = nil
40
+ when 'Array', 'Hash' then r = JSON.parse(norm_value)
44
41
  else
45
42
  r = norm_value.send(ELEMENTARY_CONVERTION_METHODS[klass])
46
43
  end
@@ -48,30 +45,25 @@ class NetzkePreference < ActiveRecord::Base
48
45
  end
49
46
 
50
47
  def normalized_value=(new_value)
51
- # norm_value = (new_value.to_s if new_value == true or new_value == false) || new_value
52
48
  case new_value.class.name
53
- when "Array"
54
- write_attribute(:value, new_value.to_json)
55
- when "Hash"
56
- write_attribute(:value, new_value.to_json)
57
- else
58
- write_attribute(:value, new_value.to_s)
49
+ when "Array" then write_attribute(:value, new_value.to_json)
50
+ when "Hash" then write_attribute(:value, new_value.to_json)
51
+ else write_attribute(:value, new_value.to_s)
59
52
  end
60
53
  write_attribute(:pref_type, [TrueClass, FalseClass].include?(new_value.class) ? 'Boolean' : new_value.class.to_s)
61
54
  end
62
55
 
63
56
  def self.[](pref_name)
64
- pref_name = pref_name.to_s
57
+ pref_name = pref_name.to_s
65
58
  conditions = {:name => pref_name, :user_id => user_id, :widget_name => self.widget_name}
66
- pref = self.find(:first, :conditions => conditions)
67
- # pref = @@user.nil? ? self.find_by_name(pref_name) : self.find_by_name_and_user_id(pref_name, @@user.id)
59
+ pref = self.find(:first, :conditions => conditions)
68
60
  pref && pref.normalized_value
69
61
  end
70
62
 
71
63
  def self.[]=(pref_name, new_value)
72
- pref_name = pref_name.to_s
64
+ pref_name = pref_name.to_s
73
65
  conditions = {:name => pref_name, :user_id => user_id, :widget_name => self.widget_name}
74
- pref = self.find(:first, :conditions => conditions)
66
+ pref = self.find(:first, :conditions => conditions)
75
67
 
76
68
  # if assigning nil, simply delete the eventually found preference
77
69
  if new_value.nil?
@@ -5,14 +5,14 @@ module Netzke
5
5
  res = ""
6
6
 
7
7
  if ENV['RAILS_ENV'] == 'development'
8
- res << javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all-debug.js")
9
- else
10
- res << javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all.js")
8
+ res << javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all-debug.js")
9
+ else
10
+ res << javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all.js")
11
11
  end
12
12
  res << javascript_tag( "Ext.authenticityToken = '#{form_authenticity_token}'") # forgery protection
13
- res << javascript_include_tag("/netzke/netzke.js")
13
+ res << javascript_include_tag("/netzke/netzke.js")
14
14
 
15
- res
15
+ res
16
16
  end
17
17
 
18
18
  def netzke_css_include(theme_name = :default)
data/lib/netzke/base.rb CHANGED
@@ -16,9 +16,9 @@ module Netzke
16
16
  # Global Netzke::Base configuration
17
17
  def config
18
18
  set_default_config({
19
- :javascripts => [],
20
- :css => [],
21
- :layout_manager => "NetzkeLayout",
19
+ :javascripts => [],
20
+ :css => [],
21
+ :layout_manager => "NetzkeLayout",
22
22
  :persistent_config_manager => "NetzkePreference"
23
23
  })
24
24
  end
@@ -97,8 +97,8 @@ module Netzke
97
97
  attr_reader :pref
98
98
 
99
99
  def initialize(config = {}, parent = nil)
100
- @config = initial_config.recursive_merge(config)
101
- @parent = parent
100
+ @config = initial_config.recursive_merge(config)
101
+ @parent = parent
102
102
  @id_name = parent.nil? ? config[:name].to_s : "#{parent.id_name}__#{config[:name]}"
103
103
 
104
104
  @flash = []
@@ -240,7 +240,7 @@ module Netzke
240
240
  end
241
241
  end
242
242
 
243
- #### API section
243
+ #### Interface
244
244
  def get_widget(params = {})
245
245
  # if browser does not have our component class cached (and all dependencies), send it to him
246
246
  components_cache = (JSON.parse(params[:components_cache]) if params[:components_cache]) || []
@@ -33,10 +33,10 @@ module Netzke
33
33
  res.merge!(:id => @id_name)
34
34
 
35
35
  # include tools and actions
36
- res.merge!(:tools => tools) if tools
36
+ res.merge!(:tools => tools) if tools
37
37
  res.merge!(:actions => actions) if actions
38
- res.merge!(:bbar => tbar) if tbar
39
- res.merge!(:tbar => bbar) if bbar
38
+ res.merge!(:bbar => tbar) if tbar
39
+ res.merge!(:tbar => bbar) if bbar
40
40
 
41
41
  # include permissions
42
42
  res.merge!(:permissions => permissions) unless available_permissions.empty?
@@ -123,17 +123,17 @@ module Netzke
123
123
  # default config that is always passed into the constructor
124
124
  def js_default_config
125
125
  {
126
- :title => "config.id.humanize()".l,
126
+ :title => "config.id.humanize()".l,
127
127
  :listeners => js_listeners,
128
- :tools => "config.tools".l,
129
- :actions => "config.actions".l,
130
- :tbar => "config.tbar".l,
131
- :bbar => "config.bbar".l,
132
- # :items => "config.items".l,
133
- # :items => js_items,
134
- :height => 400,
135
- :width => 800,
136
- :border => false
128
+ :tools => "config.tools".l,
129
+ :actions => "config.actions".l,
130
+ :tbar => "config.tbar".l,
131
+ :bbar => "config.bbar".l,
132
+ # :items => "config.items".l,
133
+ # :items => js_items,
134
+ :height => 400,
135
+ :width => 800,
136
+ :border => false
137
137
  }
138
138
  end
139
139
 
data/netzke-core.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{netzke-core}
5
- s.version = "0.2.3"
5
+ s.version = "0.2.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sergei Kozlov"]
9
- s.date = %q{2009-01-25}
9
+ s.date = %q{2009-01-28}
10
10
  s.description = %q{Build ExtJS/Rails widgets with minimum effort}
11
11
  s.email = %q{sergei@writelesscode.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_layout.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/js_class_builder.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "README.mdown", "tasks/netzke_core_tasks.rake"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netzke-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Kozlov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-25 00:00:00 -06:00
12
+ date: 2009-01-28 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15