netzke-basepack 0.7.7 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +15 -10
- data/{CHANGELOG.rdoc → CHANGELOG.md} +146 -110
- data/LICENSE +7 -1
- data/README.md +47 -56
- data/Rakefile +5 -5
- data/config/before-travis.sh +10 -0
- data/javascripts/basepack.js +0 -130
- data/javascripts/netzkeremotecombo.js +59 -0
- data/lib/netzke/basepack.rb +9 -14
- data/lib/netzke/basepack/accordion.rb +45 -0
- data/lib/netzke/basepack/active_record.rb +12 -0
- data/lib/netzke/basepack/active_record/relation_extensions.rb +27 -0
- data/lib/netzke/basepack/columns.rb +309 -0
- data/lib/netzke/basepack/data_accessor.rb +22 -12
- data/lib/netzke/basepack/data_adapters/abstract_adapter.rb +75 -11
- data/lib/netzke/basepack/data_adapters/active_record_adapter.rb +154 -49
- data/lib/netzke/basepack/fields.rb +162 -0
- data/lib/netzke/basepack/form.rb +136 -0
- data/lib/netzke/basepack/{form_panel → form}/javascripts/comma_list_cbg.js +0 -1
- data/lib/netzke/basepack/{form_panel/javascripts/form_panel.js → form/javascripts/form.js} +20 -26
- data/lib/netzke/basepack/{form_panel → form}/javascripts/n_radio_group.js +0 -1
- data/lib/netzke/basepack/{form_panel → form}/javascripts/readonly_mode.js +0 -0
- data/lib/netzke/basepack/form/services.rb +115 -0
- data/lib/netzke/basepack/{form_panel → form}/stylesheets/readonly_mode.css +0 -0
- data/lib/netzke/basepack/grid.rb +355 -0
- data/lib/netzke/basepack/{grid_panel → grid}/javascripts/advanced_search.js +1 -1
- data/lib/netzke/basepack/{grid_panel → grid}/javascripts/check_column_fix.js +0 -0
- data/lib/netzke/basepack/{grid_panel → grid}/javascripts/edit_in_form.js +3 -3
- data/lib/netzke/basepack/{grid_panel → grid}/javascripts/event_handling.js +5 -2
- data/lib/netzke/basepack/{grid_panel/javascripts/grid_panel.js → grid/javascripts/grid.js} +120 -132
- data/lib/netzke/basepack/{grid_panel → grid}/javascripts/misc.js +0 -0
- data/lib/netzke/basepack/grid/services.rb +216 -0
- data/lib/netzke/basepack/item_persistence.rb +44 -0
- data/lib/netzke/basepack/item_persistence/events_plugin.rb +47 -0
- data/lib/netzke/basepack/{paging_form_panel.rb → paging_form.rb} +24 -30
- data/lib/netzke/basepack/{paging_form_panel/javascripts/paging_form_panel.js → paging_form/javascripts/paging_form.js} +2 -4
- data/lib/netzke/basepack/query_builder.rb +44 -73
- data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +16 -2
- data/lib/netzke/basepack/record_form_window.rb +67 -0
- data/lib/netzke/basepack/search_panel.rb +22 -24
- data/lib/netzke/basepack/search_panel/javascripts/condition_field.js +2 -2
- data/lib/netzke/basepack/search_window.rb +47 -53
- data/lib/netzke/basepack/simple_app.rb +10 -13
- data/lib/netzke/basepack/simple_app/javascripts/simple_app.js +2 -8
- data/lib/netzke/basepack/tab_panel.rb +5 -4
- data/lib/netzke/basepack/tab_panel/javascripts/tab_panel.js +5 -5
- data/lib/netzke/basepack/version.rb +2 -2
- data/lib/netzke/basepack/viewport.rb +16 -0
- data/lib/netzke/basepack/window.rb +27 -18
- data/lib/netzke/basepack/window/javascripts/window.js +7 -1
- data/lib/netzke/basepack/wrap_lazy_loaded.rb +18 -18
- data/locales/en.yml +40 -24
- data/netzke-basepack.gemspec +51 -82
- data/stylesheets/basepack.css +0 -41
- data/test/basepack_test_app/Gemfile +9 -46
- data/test/basepack_test_app/Gemfile.lock +61 -96
- data/test/basepack_test_app/app/components/author_form.rb +8 -5
- data/test/basepack_test_app/app/components/author_grid.rb +2 -2
- data/test/basepack_test_app/app/components/book_form.rb +34 -31
- data/test/basepack_test_app/app/components/book_form_with_defaults.rb +6 -7
- data/test/basepack_test_app/app/components/book_form_with_file_upload.rb +10 -0
- data/test/basepack_test_app/app/components/book_form_with_nested_attributes.rb +5 -6
- data/test/basepack_test_app/app/components/book_grid.rb +19 -8
- data/test/basepack_test_app/app/components/book_grid_filtering.rb +4 -7
- data/test/basepack_test_app/app/components/book_grid_loader.rb +28 -15
- data/test/basepack_test_app/app/components/book_grid_with_custom_columns.rb +45 -21
- data/test/basepack_test_app/app/components/book_grid_with_default_values.rb +26 -8
- data/test/basepack_test_app/app/components/book_grid_with_excluded_columns.rb +11 -0
- data/test/basepack_test_app/app/components/book_grid_with_extra_feedback.rb +2 -2
- data/test/basepack_test_app/app/components/book_grid_with_extra_filters.rb +7 -6
- data/test/basepack_test_app/app/components/book_grid_with_mass_assignment_security.rb +9 -0
- data/test/basepack_test_app/app/components/book_grid_with_nested_attributes.rb +9 -9
- data/test/basepack_test_app/app/components/book_grid_with_overridden_columns.rb +5 -3
- data/test/basepack_test_app/app/components/book_grid_with_paging.rb +6 -8
- data/test/basepack_test_app/app/components/book_grid_with_persistence.rb +6 -4
- data/test/basepack_test_app/app/components/book_grid_with_scope.rb +6 -0
- data/test/basepack_test_app/app/components/book_grid_with_scoped_authors.rb +10 -7
- data/test/basepack_test_app/app/components/book_grid_with_virtual_attributes.rb +21 -13
- data/test/basepack_test_app/app/components/book_paging_form.rb +21 -0
- data/test/basepack_test_app/app/components/book_query_builder.rb +7 -6
- data/test/basepack_test_app/app/components/book_with_custom_primary_key_grid.rb +6 -7
- data/test/basepack_test_app/app/components/books_bound_to_author.rb +9 -7
- data/test/basepack_test_app/app/components/border_layout_panel_with_persistence.rb +12 -0
- data/test/basepack_test_app/app/components/double_book_grid.rb +19 -14
- data/test/basepack_test_app/app/components/form_without_model.rb +15 -16
- data/test/basepack_test_app/app/components/grid_with_initial_sorting.rb +7 -0
- data/test/basepack_test_app/app/components/grid_with_inline_data.rb +7 -0
- data/test/basepack_test_app/app/components/paging_form_with_search.rb +2 -2
- data/test/basepack_test_app/app/components/panel_with_persistent_regions.rb +35 -0
- data/test/basepack_test_app/app/components/query_builder.rb +7 -0
- data/test/basepack_test_app/app/components/simple_panel.rb +16 -11
- data/test/basepack_test_app/app/components/simple_window.rb +7 -6
- data/test/basepack_test_app/app/components/some_accordion.rb +18 -0
- data/test/basepack_test_app/app/components/some_auth_app.rb +5 -5
- data/test/basepack_test_app/app/components/some_border_layout.rb +20 -20
- data/test/basepack_test_app/app/components/some_search_panel.rb +6 -0
- data/test/basepack_test_app/app/components/some_simple_app.rb +30 -16
- data/test/basepack_test_app/app/components/some_tab_panel.rb +18 -15
- data/test/basepack_test_app/app/components/user_form.rb +18 -16
- data/test/basepack_test_app/app/components/user_form_with_default_fields.rb +5 -6
- data/test/basepack_test_app/app/components/user_grid.rb +11 -6
- data/test/basepack_test_app/app/components/user_grid_with_customized_form_fields.rb +5 -3
- data/test/basepack_test_app/app/components/window_component_loader.rb +25 -21
- data/test/basepack_test_app/app/models/address.rb +0 -26
- data/test/basepack_test_app/app/models/author.rb +0 -31
- data/test/basepack_test_app/app/models/book.rb +1 -42
- data/test/basepack_test_app/app/models/book_with_custom_primary_key.rb +1 -23
- data/test/basepack_test_app/app/models/role.rb +0 -21
- data/test/basepack_test_app/app/models/user.rb +0 -24
- data/test/basepack_test_app/app/views/layouts/components.html.erb +1 -1
- data/test/basepack_test_app/config/application.rb +1 -1
- data/test/basepack_test_app/config/database.yml.travis +2 -6
- data/test/basepack_test_app/config/initializers/netzke.rb +1 -6
- data/test/basepack_test_app/db/schema.rb +14 -14
- data/test/basepack_test_app/features/accordion_panel.feature +2 -2
- data/test/basepack_test_app/features/form_panel.feature +7 -7
- data/test/basepack_test_app/features/grid_panel.feature +93 -39
- data/test/basepack_test_app/features/grid_panel_with_custom_primary_key.feature +2 -1
- data/test/basepack_test_app/features/grid_sorting.feature +30 -6
- data/test/basepack_test_app/features/paging_form_panel.feature +7 -7
- data/test/basepack_test_app/features/persistent_regions.feature +30 -0
- data/test/basepack_test_app/features/search_in_grid.feature +5 -5
- data/test/basepack_test_app/features/simple_app.feature +6 -7
- data/test/basepack_test_app/features/step_definitions/form_panel_steps.rb +1 -1
- data/test/basepack_test_app/features/step_definitions/generic_steps.rb +109 -4
- data/test/basepack_test_app/features/step_definitions/grid_panel_steps.rb +8 -10
- data/test/basepack_test_app/features/step_definitions/window_steps.rb +27 -0
- data/test/basepack_test_app/features/tab_panel.feature +1 -1
- data/test/basepack_test_app/features/window.feature +17 -0
- data/test/unit/accordion_panel_test.rb +2 -2
- data/test/unit/grid_panel_test.rb +4 -4
- metadata +57 -83
- data/TODO.rdoc +0 -8
- data/lib/generators/netzke/basepack_generator.rb +0 -10
- data/lib/generators/netzke/templates/assets/ts-checkbox.gif +0 -0
- data/lib/generators/netzke/templates/create_netzke_field_lists.rb +0 -18
- data/lib/netzke/active_record.rb +0 -20
- data/lib/netzke/active_record/attributes.rb +0 -259
- data/lib/netzke/active_record/combobox_options.rb +0 -16
- data/lib/netzke/active_record/relation_extensions.rb +0 -37
- data/lib/netzke/basepack/accordion_panel.rb +0 -39
- data/lib/netzke/basepack/action_column.rb +0 -68
- data/lib/netzke/basepack/action_column/javascripts/action_column.js +0 -61
- data/lib/netzke/basepack/auth_app.rb +0 -159
- data/lib/netzke/basepack/basic_app.rb +0 -7
- data/lib/netzke/basepack/border_layout_panel.rb +0 -53
- data/lib/netzke/basepack/border_layout_panel/javascripts/border_layout_panel.js +0 -40
- data/lib/netzke/basepack/data_adapters/data_mapper_adapter.rb +0 -264
- data/lib/netzke/basepack/data_adapters/sequel_adapter.rb +0 -260
- data/lib/netzke/basepack/form_panel.rb +0 -144
- data/lib/netzke/basepack/form_panel/fields.rb +0 -208
- data/lib/netzke/basepack/form_panel/javascripts/misc.js +0 -4
- data/lib/netzke/basepack/form_panel/services.rb +0 -142
- data/lib/netzke/basepack/grid_panel.rb +0 -441
- data/lib/netzke/basepack/grid_panel/columns.rb +0 -400
- data/lib/netzke/basepack/grid_panel/javascripts/rows-dd.js +0 -281
- data/lib/netzke/basepack/grid_panel/record_form_window.rb +0 -41
- data/lib/netzke/basepack/grid_panel/services.rb +0 -235
- data/lib/netzke/basepack/panel.rb +0 -11
- data/lib/netzke/basepack/wrapper.rb +0 -28
- data/lib/netzke/data_mapper.rb +0 -18
- data/lib/netzke/data_mapper/attributes.rb +0 -273
- data/lib/netzke/data_mapper/combobox_options.rb +0 -11
- data/lib/netzke/data_mapper/relation_extensions.rb +0 -38
- data/lib/netzke/sequel.rb +0 -18
- data/lib/netzke/sequel/attributes.rb +0 -274
- data/lib/netzke/sequel/combobox_options.rb +0 -10
- data/lib/netzke/sequel/relation_extensions.rb +0 -40
- data/locales/zh-cn.yml +0 -79
- data/test/basepack_test_app/app/components/book_form_with_custom_fields.rb +0 -21
- data/test/basepack_test_app/app/components/book_grid_with_column_actions.rb +0 -15
- data/test/basepack_test_app/app/components/book_grid_with_defaults.rb +0 -6
- data/test/basepack_test_app/app/components/book_paging_form_panel.rb +0 -22
- data/test/basepack_test_app/app/components/generic_user_form.rb +0 -12
- data/test/basepack_test_app/app/components/simple_accordion.rb +0 -11
- data/test/basepack_test_app/app/components/simple_tab_panel.rb +0 -11
- data/test/basepack_test_app/app/components/simple_wrapper.rb +0 -7
- data/test/basepack_test_app/app/components/some_accordion_panel.rb +0 -22
- data/test/basepack_test_app/app/presenters/forms/generic_user.rb +0 -6
- data/test/basepack_test_app/app/views/components/loadable_window.html.erb +0 -9
- data/test/basepack_test_app/app/views/components/simple_panel.html.erb +0 -1
- data/test/basepack_test_app/features/components_in_view.feature +0 -11
- data/test/basepack_test_app/features/simple_panel.feature +0 -11
- data/test/basepack_test_app/features/validations_in_grid.feature +0 -13
- data/test/basepack_test_app/features/virtual_attributes.feature +0 -16
- data/test/basepack_test_app/spec/components/form_panel_spec.rb +0 -53
- data/test/basepack_test_app/spec/components/grid_panel_spec.rb +0 -10
- data/test/basepack_test_app/spec/data_adapter/adapter_spec.rb +0 -68
- data/test/basepack_test_app/spec/data_adapter/attributes_spec.rb +0 -56
- data/test/basepack_test_app/spec/data_adapter/relation_extensions_spec.rb +0 -125
- data/test/basepack_test_app/spec/factories.rb +0 -28
- data/test/basepack_test_app/spec/spec_helper.rb +0 -39
@@ -1,61 +0,0 @@
|
|
1
|
-
Ext.define('Ext.grid.column.NetzkeAction', {
|
2
|
-
extend: 'Ext.grid.column.Action',
|
3
|
-
alias: ['widget.netzkeactioncolumn'],
|
4
|
-
|
5
|
-
constructor: function(config) {
|
6
|
-
var me = this,
|
7
|
-
cfg = Ext.apply({}, config),
|
8
|
-
i,
|
9
|
-
item;
|
10
|
-
|
11
|
-
me.callParent([cfg]);
|
12
|
-
|
13
|
-
me.renderer = function(actions, meta) {
|
14
|
-
// previous renderer
|
15
|
-
var v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : '',
|
16
|
-
actions = Ext.decode(actions),
|
17
|
-
l = actions.length,
|
18
|
-
action;
|
19
|
-
|
20
|
-
meta.tdCls += ' ' + Ext.baseCSSPrefix + 'action-col-cell';
|
21
|
-
|
22
|
-
for (i = 0; i < l; i++) {
|
23
|
-
action = actions[i];
|
24
|
-
if (!action.hidden) {
|
25
|
-
v += '<img alt="' + (action.altText || me.altText) + '" src="' + (action.icon || Ext.BLANK_IMAGE_URL) +
|
26
|
-
'" class="' + Ext.baseCSSPrefix + 'action-col-icon ' + Ext.baseCSSPrefix + 'action-col-' + String(i) + ' ' + (action.iconCls || '') +
|
27
|
-
' ' + (Ext.isFunction(action.getClass) ? action.getClass.apply(action.scope||me.scope||me, arguments) : (me.iconCls || '')) + '"' +
|
28
|
-
((action.tooltip) ? ' data-qtip="' + action.tooltip + '"' : '') +
|
29
|
-
' data-name="' + action.name + '"' +
|
30
|
-
((action.handler) ? ' data-handler="' + action.handler + '"' : '') + ' />';
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
return v;
|
35
|
-
};
|
36
|
-
},
|
37
|
-
|
38
|
-
processEvent : function(type, view, cell, recordIndex, cellIndex, e){
|
39
|
-
var me = this,
|
40
|
-
target = e.getTarget(),
|
41
|
-
match = target.className.match("x-action-col-icon"),
|
42
|
-
fn, grid, record;
|
43
|
-
if (match) {
|
44
|
-
if (type == 'click') {
|
45
|
-
grid = me.ownerCt.ownerCt;
|
46
|
-
fn = (target.getAttribute("data-handler") || "").camelize(true);
|
47
|
-
fn = Ext.isFunction(grid[fn]) ? grid[fn] : undefined;
|
48
|
-
// if (fn) fn.call(grid, view, recordIndex, cellIndex, target, e);
|
49
|
-
if (fn) {
|
50
|
-
record = grid.getStore().getAt(recordIndex);
|
51
|
-
fn.call(grid, record, target, e);
|
52
|
-
} else {
|
53
|
-
Netzke.warning("Undefined handler for column action '" + target.getAttribute("data-name") + "'");
|
54
|
-
}
|
55
|
-
} else if (type == 'mousedown') {
|
56
|
-
return false;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
return me.callParent(arguments);
|
60
|
-
}
|
61
|
-
});
|
@@ -1,159 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module Basepack
|
3
|
-
# Extension to SimpleApp that brings in support for authentication and masquerading
|
4
|
-
# ** NOTE: it's WIP **
|
5
|
-
class AuthApp < SimpleApp
|
6
|
-
|
7
|
-
def default_config
|
8
|
-
super.tap do |c|
|
9
|
-
c[:login_url] = "/login"
|
10
|
-
c[:logout_url] = "/logout"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# class_config_option :login_url, "/login"
|
15
|
-
# # self.login_url = "/login"
|
16
|
-
#
|
17
|
-
# class_attribute :logout_url
|
18
|
-
# self.logout_url = "/logout"
|
19
|
-
|
20
|
-
js_method :on_login, <<-JS
|
21
|
-
function(){
|
22
|
-
window.location = this.loginUrl;
|
23
|
-
}
|
24
|
-
JS
|
25
|
-
|
26
|
-
js_method :on_logout, <<-JS
|
27
|
-
function(){
|
28
|
-
window.location = this.logoutUrl;
|
29
|
-
}
|
30
|
-
JS
|
31
|
-
|
32
|
-
js_method :on_toggle_config_mode, <<-JS
|
33
|
-
function(params){
|
34
|
-
this.toggleConfigMode();
|
35
|
-
}
|
36
|
-
JS
|
37
|
-
# WIP: todo - rewrite Ext.lib calls below
|
38
|
-
js_method :show_masquerade_selector, <<-JS
|
39
|
-
function(){
|
40
|
-
var w = new Ext.Window({
|
41
|
-
title: 'Masquerade as',
|
42
|
-
modal: true,
|
43
|
-
width: Ext.lib.Dom.getViewWidth() * 0.6,
|
44
|
-
height: Ext.lib.Dom.getViewHeight() * 0.6,
|
45
|
-
layout: 'fit',
|
46
|
-
closeAction :'destroy',
|
47
|
-
buttons: [{
|
48
|
-
text: 'Select',
|
49
|
-
handler : function(){
|
50
|
-
if (role = w.getNetzkeComponent().masquerade.role) {
|
51
|
-
Ext.Msg.confirm("Masquerading as a role", "Individual preferences for all users with this role will get overwritten as you make changes. Continue?", function(btn){
|
52
|
-
if (btn === 'yes') {
|
53
|
-
w.close();
|
54
|
-
}
|
55
|
-
});
|
56
|
-
} else {
|
57
|
-
w.close();
|
58
|
-
}
|
59
|
-
},
|
60
|
-
scope:this
|
61
|
-
},{
|
62
|
-
text:'As World',
|
63
|
-
handler:function(){
|
64
|
-
Ext.Msg.confirm("Masquerading as World", "Caution! All settings that you will modify will be overwritten for all roles and all users. Are you sure you know what you're doing?", function(btn){
|
65
|
-
if (btn === "yes") {
|
66
|
-
this.masquerade = {world:true};
|
67
|
-
w.close();
|
68
|
-
}
|
69
|
-
}, this);
|
70
|
-
},
|
71
|
-
scope:this
|
72
|
-
},{
|
73
|
-
text:'No masquerading',
|
74
|
-
handler:function(){
|
75
|
-
this.masquerade = {};
|
76
|
-
w.close();
|
77
|
-
},
|
78
|
-
scope:this
|
79
|
-
},{
|
80
|
-
text:'Cancel',
|
81
|
-
handler:function(){
|
82
|
-
w.hide();
|
83
|
-
},
|
84
|
-
scope:this
|
85
|
-
}],
|
86
|
-
listeners : {close: {fn: function(){
|
87
|
-
this.masqueradeAs(this.masquerade || w.getNetzkeComponent().masquerade || {});
|
88
|
-
}, scope: this}}
|
89
|
-
});
|
90
|
-
|
91
|
-
w.show(null, function(){
|
92
|
-
this.loadNetzkeComponent({id:"masqueradeSelector", container:w.id})
|
93
|
-
}, this);
|
94
|
-
|
95
|
-
}
|
96
|
-
JS
|
97
|
-
|
98
|
-
# Set the Logout button if Netzke::Core.current_user is set
|
99
|
-
def menu
|
100
|
-
[].tap do |menu|
|
101
|
-
user = Netzke::Core.current_user
|
102
|
-
if !user.nil?
|
103
|
-
user_name = user.respond_to?(:name) ? user.name : user.email # try to display user's name, fallback to email
|
104
|
-
menu << "->" <<
|
105
|
-
{
|
106
|
-
:text => user_name,
|
107
|
-
:menu => user_menu
|
108
|
-
}
|
109
|
-
else
|
110
|
-
menu << "->" << :login.action
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def user_menu
|
116
|
-
[:logout.action]
|
117
|
-
end
|
118
|
-
|
119
|
-
def initialize(*args)
|
120
|
-
super
|
121
|
-
|
122
|
-
if session[:netzke_just_logged_in] || session[:netzke_just_logged_out]
|
123
|
-
session[:config_mode] = false
|
124
|
-
session[:masq_world] = session[:masq_user] = session[:masq_roles] = nil
|
125
|
-
end
|
126
|
-
|
127
|
-
strong_children_config.deep_merge!(:mode => :config) if session[:config_mode]
|
128
|
-
end
|
129
|
-
|
130
|
-
action :masquerade_selector, :text => "Masquerade as ...", :handler => :show_masquerade_selector
|
131
|
-
|
132
|
-
action :toggle_config_mode do
|
133
|
-
{:text => "#{session[:config_mode] ? "Leave" : "Enter"} config mode"}
|
134
|
-
end
|
135
|
-
|
136
|
-
action :login, :icon => :door_in
|
137
|
-
|
138
|
-
action :logout, :icon => :door_out
|
139
|
-
|
140
|
-
#
|
141
|
-
# Interface section
|
142
|
-
#
|
143
|
-
endpoint :toggle_config_mode do |params|
|
144
|
-
session = Netzke::Base.session
|
145
|
-
session[:config_mode] = !session[:config_mode]
|
146
|
-
{:js => "window.location.reload();"}
|
147
|
-
end
|
148
|
-
|
149
|
-
endpoint :masquerade_as do |params|
|
150
|
-
session = Netzke::Base.session
|
151
|
-
session[:masq_world] = params[:world] == "true"
|
152
|
-
session[:masq_role] = params[:role].try(:to_i)
|
153
|
-
session[:masq_user] = params[:user].try(:to_i)
|
154
|
-
{:js => "window.location.reload();"}
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module Basepack
|
3
|
-
# Panel with border layout.
|
4
|
-
#
|
5
|
-
# == Features
|
6
|
-
# * When persistence enabled, remembers the sizes and collapsed/expanded states of its regions.
|
7
|
-
#
|
8
|
-
# == Example configuration:
|
9
|
-
#
|
10
|
-
# :items => [
|
11
|
-
# {:title => "Item One", :class_name => "Basepack::Panel", :region => :center},
|
12
|
-
# {:title => "Item Two", :class_name => "Basepack::Panel", :region => :west, :width => 300, :split => true}
|
13
|
-
# ]
|
14
|
-
class BorderLayoutPanel < Netzke::Base
|
15
|
-
js_mixin :border_layout_panel
|
16
|
-
|
17
|
-
def items
|
18
|
-
@border_layout_items ||= begin
|
19
|
-
updated_items = super
|
20
|
-
|
21
|
-
if config[:persistence]
|
22
|
-
updated_items.each do |item|
|
23
|
-
region = item[:region] || components[item[:netzke_component]][:region]
|
24
|
-
item.merge!({
|
25
|
-
:width => state[:"#{region}_region_width"],
|
26
|
-
:height => state[:"#{region}_region_height"],
|
27
|
-
:collapsed => state[:"#{region}_region_collapsed"]
|
28
|
-
})
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
updated_items
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
endpoint :region_resized do |params|
|
37
|
-
size_state_hash = {}
|
38
|
-
size_state_hash[:"#{params[:region]}_region_width"] = params[:width].to_i if params[:width]
|
39
|
-
size_state_hash[:"#{params[:region]}_region_height"] = params[:height].to_i if params[:height]
|
40
|
-
update_state(size_state_hash)
|
41
|
-
end
|
42
|
-
|
43
|
-
endpoint :region_collapsed do |params|
|
44
|
-
update_state(:"#{params[:region]}_region_collapsed" => true)
|
45
|
-
end
|
46
|
-
|
47
|
-
endpoint :region_expanded do |params|
|
48
|
-
update_state(:"#{params[:region]}_region_collapsed" => false)
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
{
|
2
|
-
layout: 'border',
|
3
|
-
|
4
|
-
initComponent: function(){
|
5
|
-
this.callParent();
|
6
|
-
|
7
|
-
// First time on "afterlayout", set resize events
|
8
|
-
if (this.persistence) {this.on('afterlayout', this.setRegionEvents, this, {single: true});}
|
9
|
-
},
|
10
|
-
|
11
|
-
setRegionEvents: function(){
|
12
|
-
this.items.each(function(item, index, length){
|
13
|
-
if (!item.oldSize) item.oldSize = item.getSize(); // remember initial size
|
14
|
-
|
15
|
-
item.on('resize', function(panel, w, h){
|
16
|
-
if (panel.region !== 'center' && w && h) {
|
17
|
-
var params = {region:panel.region};
|
18
|
-
|
19
|
-
if (panel.oldSize.width != w) {
|
20
|
-
params.width = w;
|
21
|
-
} else {
|
22
|
-
params.height = h;
|
23
|
-
}
|
24
|
-
|
25
|
-
panel.oldSize = panel.getSize();
|
26
|
-
this.regionResized(params);
|
27
|
-
}
|
28
|
-
}, this);
|
29
|
-
|
30
|
-
item.on('collapse', function(panel){
|
31
|
-
this.regionCollapsed({region: panel.region});
|
32
|
-
}, this);
|
33
|
-
|
34
|
-
item.on('expand', function(panel){
|
35
|
-
this.regionExpanded({region: panel.region});
|
36
|
-
}, this);
|
37
|
-
|
38
|
-
}, this);
|
39
|
-
}
|
40
|
-
}
|
@@ -1,264 +0,0 @@
|
|
1
|
-
module Netzke::Basepack::DataAdapters
|
2
|
-
class DataMapperAdapter < AbstractAdapter
|
3
|
-
def self.for_class?(model_class)
|
4
|
-
model_class <= DataMapper::Resource
|
5
|
-
end
|
6
|
-
|
7
|
-
def get_records(params, columns=[])
|
8
|
-
search_query = @model_class
|
9
|
-
|
10
|
-
# used for specifying models to join (for ordering and column selection)
|
11
|
-
links = []
|
12
|
-
# join association models into query if they are specified in query
|
13
|
-
# NOTE: AFAIK, in DataMapper there is no possibility to do
|
14
|
-
# OUTER JOINs, and inner join is not correct if a foreign key is
|
15
|
-
# nullable, so we don't join at all and instead rely on strategic
|
16
|
-
# eager loading.
|
17
|
-
|
18
|
-
#columns.each do |column|
|
19
|
-
#if column[:name].index('__')
|
20
|
-
#assoc, _ = column[:name].split('__')
|
21
|
-
#link = @model_class.relationships[assoc.to_sym].inverse
|
22
|
-
#links << link unless links.include? link
|
23
|
-
#end
|
24
|
-
#end
|
25
|
-
|
26
|
-
# apply filter
|
27
|
-
search_query = apply_column_filters search_query, params[:filter] if params[:filter]
|
28
|
-
query_options = {}
|
29
|
-
|
30
|
-
# apply sorting
|
31
|
-
if params[:sort] && sort_params = params[:sort]
|
32
|
-
order = []
|
33
|
-
sort_params.each do |sort_param|
|
34
|
-
assoc, method = sort_param["property"].split("__")
|
35
|
-
dir = sort_param["direction"].downcase
|
36
|
-
|
37
|
-
# if a sorting scope is set, call the scope with the given direction
|
38
|
-
column = columns.detect { |c| c[:name] == sort_param["property"] }
|
39
|
-
if column.try(:'has_key?', :sorting_scope)
|
40
|
-
search_query = search_query.send(column[:sorting_scope].to_sym, dir.to_sym)
|
41
|
-
else
|
42
|
-
if method
|
43
|
-
order << @model_class.send(assoc).send(method).send(dir)
|
44
|
-
link = @model_class.relationships[assoc.to_sym].inverse
|
45
|
-
links << link unless links.include? link
|
46
|
-
else
|
47
|
-
order << assoc.to_sym.send(dir)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
query_options[:order] = order unless order.empty?
|
52
|
-
query_options[:links] = links unless links.empty?
|
53
|
-
end
|
54
|
-
|
55
|
-
# apply paging
|
56
|
-
query_options[:limit]=params[:limit] if params[:limit]
|
57
|
-
query_options[:offset]=params[:start] if params[:start]
|
58
|
-
|
59
|
-
# apply scope
|
60
|
-
search_query = search_query.extend_with(params[:scope]) if params[:scope]
|
61
|
-
|
62
|
-
search_query.all(query_options)
|
63
|
-
end
|
64
|
-
|
65
|
-
def count_records(params, columns=[])
|
66
|
-
# delete pagig related params, as this would break the query
|
67
|
-
params=params.reject { |k, v|
|
68
|
-
[:start, :limit, :page].include? k.to_sym
|
69
|
-
}
|
70
|
-
# this will NOT do a SELECT *, but a SELECT COUNT(*)
|
71
|
-
get_records(params, columns).count
|
72
|
-
end
|
73
|
-
|
74
|
-
def map_type type
|
75
|
-
@typemap ||= {
|
76
|
-
DataMapper::Property::Integer => :integer,
|
77
|
-
DataMapper::Property::Serial => :integer,
|
78
|
-
DataMapper::Property::Boolean => :boolean,
|
79
|
-
DataMapper::Property::Date => :date,
|
80
|
-
DataMapper::Property::DateTime => :datetime,
|
81
|
-
DataMapper::Property::Time => :time,
|
82
|
-
DataMapper::Property::String => :string,
|
83
|
-
DataMapper::Property::Text => :text
|
84
|
-
}
|
85
|
-
@typemap[type]
|
86
|
-
end
|
87
|
-
|
88
|
-
def get_assoc_property_type assoc_name, prop_name
|
89
|
-
assoc = @model_class.send(assoc_name)
|
90
|
-
# prop_name could be a virtual column, check it first, return nil in this case
|
91
|
-
assoc.respond_to?(prop_name) ? map_type(assoc.send(prop_name).property.class) : nil
|
92
|
-
end
|
93
|
-
|
94
|
-
# like get_assoc_property_type but for non-association columns
|
95
|
-
def get_property_type column
|
96
|
-
map_type(column.class)
|
97
|
-
end
|
98
|
-
|
99
|
-
def column_virtual? c
|
100
|
-
assoc_name, assoc_method = c[:name].split '__'
|
101
|
-
if assoc_method
|
102
|
-
column_names=@model_class.send(assoc_name).model.column_names
|
103
|
-
column_name=assoc_method
|
104
|
-
else
|
105
|
-
column_names=@model_class.column_names
|
106
|
-
column_name=c[:name]
|
107
|
-
end
|
108
|
-
!column_names.include? column_name
|
109
|
-
end
|
110
|
-
|
111
|
-
# Returns options for comboboxes in grids/forms
|
112
|
-
def combobox_options_for_column(column, method_options = {})
|
113
|
-
query = method_options[:query]
|
114
|
-
|
115
|
-
# First, check if we have options for this column defined in persistent storage
|
116
|
-
options = column[:combobox_options] && column[:combobox_options].split("\n")
|
117
|
-
if options
|
118
|
-
query ? options.select{ |o| o.index(/^#{query}/) }.map{ |el| [el] } : options
|
119
|
-
else
|
120
|
-
assoc_name, assoc_method = column[:name].split '__'
|
121
|
-
|
122
|
-
if assoc_name
|
123
|
-
# Options for an asssociation attribute
|
124
|
-
relation = @model_class.send(assoc_name).model
|
125
|
-
|
126
|
-
relation = relation.extend_with(method_options[:scope]) if method_options[:scope]
|
127
|
-
|
128
|
-
if class_for(assoc_name).column_names.include?(assoc_method)
|
129
|
-
# apply query
|
130
|
-
relation = relation.all(assoc_method.to_sym.send(:like) => "%#{query}%") if query.present?
|
131
|
-
relation.all.map{ |r| [r.id, r.send(assoc_method)] }
|
132
|
-
else
|
133
|
-
relation.all.map{ |r| [r.id, r.send(assoc_method)] }.select{ |id,value| value =~ /^#{query}/ }
|
134
|
-
end
|
135
|
-
else
|
136
|
-
# Options for a non-association attribute
|
137
|
-
res=@model_class.netzke_combo_options_for(column[:name], method_options)
|
138
|
-
|
139
|
-
# ensure it is an array-in-array, as Ext will fail otherwise
|
140
|
-
raise RuntimeError, "netzke_combo_options_for should return an Array" unless res.kind_of? Array
|
141
|
-
return [[]] if res.empty?
|
142
|
-
|
143
|
-
unless res.first.kind_of? Array
|
144
|
-
res=res.map do |v|
|
145
|
-
[v]
|
146
|
-
end
|
147
|
-
end
|
148
|
-
return res
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def foreign_key_for assoc_name
|
154
|
-
@model_class.relationships[assoc_name].child_key.first.name.to_s
|
155
|
-
end
|
156
|
-
|
157
|
-
# Returns the model class for an association
|
158
|
-
def class_for assoc_name
|
159
|
-
@model_class.send(assoc_name).model
|
160
|
-
end
|
161
|
-
|
162
|
-
def destroy(ids)
|
163
|
-
@model_class.all(:id => ids).destroy
|
164
|
-
end
|
165
|
-
|
166
|
-
def find_record(id)
|
167
|
-
@model_class.get(id)
|
168
|
-
end
|
169
|
-
|
170
|
-
# Build a hash of foreign keys and the associated model
|
171
|
-
def hash_fk_model
|
172
|
-
@model_class.relationships.inject({}) do |foreign_keys, rel|
|
173
|
-
if rel.kind_of? DataMapper::Associations::ManyToOne::Relationship
|
174
|
-
foreign_keys[rel.child_key.first.name]=rel.parent_model.to_s.downcase.to_sym
|
175
|
-
foreign_keys
|
176
|
-
end
|
177
|
-
end || {}
|
178
|
-
end
|
179
|
-
|
180
|
-
def move_records(params)
|
181
|
-
@model_class.all(:id => params[:ids]).each_with_index do |item, index|
|
182
|
-
item.move(:to => params[:new_index] + index)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
# give the data adapter the opporunity to process error messages
|
187
|
-
# must return an raay of the form ["Title can't be blank", "Foo can't be blank"]
|
188
|
-
def errors_array(record)
|
189
|
-
record.errors.to_a.flatten
|
190
|
-
end
|
191
|
-
|
192
|
-
# Needed for seed and tests
|
193
|
-
def last
|
194
|
-
@model_class.last
|
195
|
-
end
|
196
|
-
|
197
|
-
def destroy_all
|
198
|
-
@model_class.all.destroy
|
199
|
-
end
|
200
|
-
|
201
|
-
private
|
202
|
-
|
203
|
-
# Parses and applies grid column filters
|
204
|
-
#
|
205
|
-
# Example column grid data:
|
206
|
-
#
|
207
|
-
# {"0" => {
|
208
|
-
# "data" => {
|
209
|
-
# "type" => "numeric",
|
210
|
-
# "comparison" => "gt",
|
211
|
-
# "value" => 10 },
|
212
|
-
# "field" => "id"
|
213
|
-
# },
|
214
|
-
# "1" => {
|
215
|
-
# "data" => {
|
216
|
-
# "type" => "string",
|
217
|
-
# "value" => "pizza"
|
218
|
-
# },
|
219
|
-
# "field" => "food_name"
|
220
|
-
# }}
|
221
|
-
#
|
222
|
-
# This will result in:
|
223
|
-
# Clazz.get(:id => 10, :food_name.like => "%pizza")
|
224
|
-
def apply_column_filters(relation, column_filter)
|
225
|
-
# these are still JSON-encoded due to the migration to Ext.direct
|
226
|
-
column_filter=JSON.parse(column_filter)
|
227
|
-
|
228
|
-
conditions = {}
|
229
|
-
column_filter.each do |v|
|
230
|
-
assoc, method = v["field"].split('__')
|
231
|
-
if method
|
232
|
-
query_path = relation.send(assoc).send(method) # Book.athor.last_name.like
|
233
|
-
else
|
234
|
-
query_path = assoc.to_sym # :last_name.like
|
235
|
-
end
|
236
|
-
|
237
|
-
value = v["value"]
|
238
|
-
type = v["type"]
|
239
|
-
case v["comparison"]
|
240
|
-
when "lt"
|
241
|
-
query_path=query_path.lt if ["date","numeric"].include? type
|
242
|
-
when "gt"
|
243
|
-
query_path=query_path.gt if ["date","numeric"].include? type
|
244
|
-
else
|
245
|
-
query_path=query_path.like if type == "string"
|
246
|
-
end
|
247
|
-
|
248
|
-
case type
|
249
|
-
when "string"
|
250
|
-
conditions[query_path]="%#{value}%"
|
251
|
-
when "date"
|
252
|
-
# convert value to the DB date
|
253
|
-
value.match /(\d\d)\/(\d\d)\/(\d\d\d\d)/
|
254
|
-
conditions[query_path]="#{$3}-#{$1}-#{$2}"
|
255
|
-
else
|
256
|
-
conditions[query_path]=value
|
257
|
-
end
|
258
|
-
end
|
259
|
-
relation.all conditions
|
260
|
-
end
|
261
|
-
|
262
|
-
end
|
263
|
-
|
264
|
-
end
|