padrino-admin 0.6.3 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -0
- data/VERSION +1 -1
- data/lib/padrino-admin.rb +24 -5
- data/lib/padrino-admin/access_control.rb +75 -29
- data/lib/padrino-admin/{ext_js/column_store.rb → column_store.rb} +31 -15
- data/lib/padrino-admin/config.rb +36 -0
- data/lib/padrino-admin/generators/actions.rb +62 -7
- data/lib/padrino-admin/generators/admin_app.rb +27 -26
- data/lib/padrino-admin/generators/admin_page.rb +20 -18
- data/lib/padrino-admin/generators/admin_uploader.rb +83 -0
- data/lib/padrino-admin/generators/app/app.rb.tt +1 -3
- data/lib/padrino-admin/generators/app/controllers/accounts.rb +1 -1
- data/lib/padrino-admin/generators/app/public/flash/swfupload.swf +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/back.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/background.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-content.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-hd-slate.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-hd.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-intro.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-login.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-menu-slate.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-menu.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/btn-login.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/admin/cancel.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/categories.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/admin/close.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/admin/close.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/delete.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/download.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/duplicate.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/edit.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/export.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/hd-bg.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/image.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/loader.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/logo-loader.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/logo-small.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/new.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/no-image.png +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/preview.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/print.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/save.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/{backend → admin}/support.gif +0 -0
- data/lib/padrino-admin/generators/app/public/images/admin/up.gif +0 -0
- data/lib/padrino-admin/generators/app/public/javascripts/ext.js +4 -1
- data/lib/padrino-admin/generators/app/public/javascripts/swfupload.js +4 -0
- data/lib/padrino-admin/generators/app/public/stylesheets/admin.css +25 -43
- data/lib/padrino-admin/generators/app/public/stylesheets/login.css +3 -3
- data/lib/padrino-admin/generators/app/public/stylesheets/standard.css +53 -52
- data/lib/padrino-admin/generators/app/views/accounts/_form.haml +1 -0
- data/lib/padrino-admin/generators/app/views/base/index.haml +5 -7
- data/lib/padrino-admin/generators/app/views/javascripts/admin.js.erb +217 -297
- data/lib/padrino-admin/generators/app/views/sessions/new.haml +1 -1
- data/lib/padrino-admin/generators/templates/{controller.rb.tt → page/controller.rb.tt} +1 -1
- data/lib/padrino-admin/generators/templates/{db → page/db}/seeds.rb.tt +0 -0
- data/lib/padrino-admin/generators/templates/{views → page/views}/_form.haml.tt +0 -0
- data/lib/padrino-admin/generators/templates/{views → page/views}/edit.haml.tt +0 -0
- data/lib/padrino-admin/generators/templates/{views → page/views}/grid.js.erb.tt +1 -1
- data/lib/padrino-admin/generators/templates/{views → page/views}/new.haml.tt +0 -0
- data/lib/padrino-admin/generators/templates/{views → page/views}/store.jml.tt +0 -0
- data/lib/padrino-admin/generators/templates/uploader/controller.rb +24 -0
- data/lib/padrino-admin/generators/templates/uploader/lib/uploader.rb +54 -0
- data/lib/padrino-admin/generators/templates/uploader/views/grid.js.erb +56 -0
- data/lib/padrino-admin/generators/templates/uploader/views/store.jml +10 -0
- data/lib/padrino-admin/helpers/authentication.rb +30 -19
- data/lib/padrino-admin/helpers/view.rb +172 -35
- data/lib/padrino-admin/locale/admin/en.yml +1 -0
- data/lib/padrino-admin/middleware/flash_middleware.rb +36 -0
- data/lib/padrino-admin/orm.rb +33 -0
- data/lib/padrino-admin/orm/abstract.rb +94 -0
- data/lib/padrino-admin/{adapters/ar.rb → orm/activerecord.rb} +69 -36
- data/lib/padrino-admin/orm/datamapper.rb +214 -0
- data/lib/padrino-admin/{adapters/mm.rb → orm/mongomapper.rb} +36 -20
- data/lib/padrino-admin/utils/literal.rb +1 -1
- data/padrino-admin.gemspec +62 -51
- data/test/fixtures/active_record.rb +14 -2
- data/test/fixtures/data_mapper.rb +2 -1
- data/test/fixtures/mongo_mapper.rb +1 -1
- data/test/fixtures/test_column_store.jml +1 -0
- data/test/helper.rb +3 -2
- data/test/test_access_control.rb +1 -1
- data/test/test_active_record.rb +56 -1
- data/test/test_column_store.rb +56 -10
- data/test/test_data_mapper.rb +67 -1
- metadata +58 -47
- data/lib/padrino-admin/adapters.rb +0 -108
- data/lib/padrino-admin/adapters/dm.rb +0 -147
- data/lib/padrino-admin/ext_js/config.rb +0 -186
- data/test/fixtures/test_generic.jml +0 -7
- data/test/fixtures/test_javascript.jml +0 -81
@@ -1,186 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'yaml'
|
3
|
-
require 'erb'
|
4
|
-
require 'json/pure' unless defined?(JSON) || defined?(JSON::Pure)
|
5
|
-
|
6
|
-
module Padrino
|
7
|
-
module ExtJs
|
8
|
-
|
9
|
-
class ConfigError < RuntimeError; end
|
10
|
-
|
11
|
-
# This class it's used for JSON variables.
|
12
|
-
# Normally if we convert this { :function => "alert('Test')" } will be:
|
13
|
-
#
|
14
|
-
# { "function": "alert('Test')" }
|
15
|
-
#
|
16
|
-
# But if in our javascript need to "eval" this function is not possible because
|
17
|
-
# it's a string.
|
18
|
-
#
|
19
|
-
# Using Padrino::ExtJs::Variable the result will be:
|
20
|
-
#
|
21
|
-
# { "function" : alert('Test') }
|
22
|
-
#
|
23
|
-
# Normally an ExtJs Variable can be handled with ExtJs Config like:
|
24
|
-
#
|
25
|
-
# function: !js alert('Test')
|
26
|
-
#
|
27
|
-
class Variable < String
|
28
|
-
yaml_as "tag:yaml.org,2002:js"
|
29
|
-
|
30
|
-
def to_json(*a) #:nodoc:
|
31
|
-
self
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Json Pretty Printer.
|
36
|
-
# Thanks to http://github.com/techcrunch/json_printer
|
37
|
-
class JsonPrinter
|
38
|
-
attr_reader :buf, :indent
|
39
|
-
|
40
|
-
# ==== Arguments
|
41
|
-
# obj<Object>::
|
42
|
-
# The object to be rendered into JSON. This object and all of its
|
43
|
-
# associated objects must be either nil, true, false, a String, a Symbol,
|
44
|
-
# a Numeric, an Array, or a Hash.
|
45
|
-
#
|
46
|
-
# ==== Returns
|
47
|
-
# <String>::
|
48
|
-
# The pretty-printed JSON ecoding of the given <i>obj</i>. This string
|
49
|
-
# can be parsed by any compliant JSON parser without modification.
|
50
|
-
#
|
51
|
-
# ==== Examples
|
52
|
-
# See <tt>JsonPrinter</tt> docs.
|
53
|
-
#
|
54
|
-
def self.render(obj, indent=1)
|
55
|
-
indent = " "*indent
|
56
|
-
new(obj, indent).buf
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
private
|
61
|
-
# Execute the JSON rendering of <i>obj</i>, storing the result in the
|
62
|
-
# <tt>buf</tt>.
|
63
|
-
#
|
64
|
-
def initialize(obj, indent="")
|
65
|
-
@buf = ""
|
66
|
-
@indent = indent
|
67
|
-
render(obj)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Increase the indentation level.
|
71
|
-
#
|
72
|
-
def indent_out
|
73
|
-
@indent << " "
|
74
|
-
end
|
75
|
-
|
76
|
-
# Decrease the indendation level.
|
77
|
-
#
|
78
|
-
def indent_in
|
79
|
-
@indent.slice!(-1, 1)
|
80
|
-
end
|
81
|
-
|
82
|
-
# Append the given <i>str</i> to the <tt>buf</tt>.
|
83
|
-
#
|
84
|
-
def print(str)
|
85
|
-
@buf << str
|
86
|
-
end
|
87
|
-
|
88
|
-
# Recursive rendering method. Primitive values, like nil, true, false,
|
89
|
-
# numbers, symbols, and strings are converted to JSON and appended to the
|
90
|
-
# buffer. Enumerables are treated specially to generate pretty whitespace.
|
91
|
-
#
|
92
|
-
def render(obj)
|
93
|
-
# We can't use a case statement here becuase "when Hash" doesn't work for
|
94
|
-
# ActiveSupport::OrderedHash - respond_to?(:values) is a more reliable
|
95
|
-
# indicator of hash-like behavior.
|
96
|
-
if NilClass === obj
|
97
|
-
print("null")
|
98
|
-
|
99
|
-
elsif TrueClass === obj
|
100
|
-
print("true")
|
101
|
-
|
102
|
-
elsif FalseClass === obj
|
103
|
-
print("false")
|
104
|
-
|
105
|
-
elsif String === obj
|
106
|
-
print(escape_json_string(obj))
|
107
|
-
|
108
|
-
elsif Symbol === obj
|
109
|
-
print("\"#{obj}\"")
|
110
|
-
|
111
|
-
elsif Numeric === obj
|
112
|
-
print(obj.to_s)
|
113
|
-
|
114
|
-
elsif Time === obj
|
115
|
-
print(obj.to_s)
|
116
|
-
|
117
|
-
elsif obj.respond_to?(:keys)
|
118
|
-
print("{")
|
119
|
-
indent_out
|
120
|
-
last_key = obj.keys.last
|
121
|
-
obj.each do |(key, val)|
|
122
|
-
render(key)
|
123
|
-
case val
|
124
|
-
when Hash, Array
|
125
|
-
indent_out
|
126
|
-
print(":\n#{indent}")
|
127
|
-
render(val)
|
128
|
-
indent_in
|
129
|
-
else
|
130
|
-
print(": ")
|
131
|
-
render(val)
|
132
|
-
end
|
133
|
-
print(",\n#{indent}") unless key == last_key
|
134
|
-
end
|
135
|
-
indent_in
|
136
|
-
print("}")
|
137
|
-
|
138
|
-
elsif Array === obj
|
139
|
-
print("[")
|
140
|
-
indent_out
|
141
|
-
last_index = obj.size - 1
|
142
|
-
obj.each_with_index do |elem, index|
|
143
|
-
render(elem)
|
144
|
-
print(",\n#{indent}") unless index == last_index
|
145
|
-
end
|
146
|
-
indent_in
|
147
|
-
print("]")
|
148
|
-
|
149
|
-
else
|
150
|
-
raise "unrenderable object: #{obj.inspect}"
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# Special JSON character escape cases.
|
155
|
-
ESCAPED_CHARS = {
|
156
|
-
"\010" => '\b',
|
157
|
-
"\f" => '\f',
|
158
|
-
"\n" => '\n',
|
159
|
-
"\r" => '\r',
|
160
|
-
"\t" => '\t',
|
161
|
-
'"' => '\"',
|
162
|
-
'\\' => '\\\\',
|
163
|
-
'>' => '\u003E',
|
164
|
-
'<' => '\u003C',
|
165
|
-
'&' => '\u0026'}
|
166
|
-
|
167
|
-
# String#to_json extracted from ActiveSupport, using interpolation for speed.
|
168
|
-
#
|
169
|
-
def escape_json_string(str)
|
170
|
-
begin
|
171
|
-
"\"#{
|
172
|
-
str.gsub(/[\010\f\n\r\t"\\><&]/) { |s| ESCAPED_CHARS[s] }.
|
173
|
-
gsub(/([\xC0-\xDF][\x80-\xBF]|
|
174
|
-
[\xE0-\xEF][\x80-\xBF]{2}|
|
175
|
-
[\xF0-\xF7][\x80-\xBF]{3})+/nx) do |s|
|
176
|
-
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')
|
177
|
-
end
|
178
|
-
}\""
|
179
|
-
rescue Encoding::CompatibilityError
|
180
|
-
rawbytes = str.dup.force_encoding 'ASCII-8BIT'
|
181
|
-
escape_json_string(rawbytes)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# Set grouping view
|
2
|
-
# var gw = new Ext.grid.GroupingView({ forceFit: false });
|
3
|
-
gw: !groupingView
|
4
|
-
forceFit: false
|
5
|
-
|
6
|
-
# Set app title
|
7
|
-
# Admin.app.setTitle('List Ecommerces');
|
8
|
-
eval: !title List Ecommerces
|
9
|
-
|
10
|
-
# Set grid toolbar
|
11
|
-
# var tbar = new Ext.Toolbar({
|
12
|
-
# buttons: [{
|
13
|
-
# handler: add,
|
14
|
-
# text: Admin.locale.buttons.add,
|
15
|
-
# disabled: false,
|
16
|
-
# cls: "x-btn-text-icon add",
|
17
|
-
# id: "add"
|
18
|
-
# },{
|
19
|
-
# handler: edit,
|
20
|
-
# text: Admin.locale.buttons.edit,
|
21
|
-
# disabled: true,
|
22
|
-
# cls: "x-btn-text-icon edit",
|
23
|
-
# id: "edit"
|
24
|
-
# },{
|
25
|
-
# handler: remove,
|
26
|
-
# text: Admin.locale.buttons.remove,
|
27
|
-
# disabled: true,
|
28
|
-
# cls: "x-btn-text-icon remove",
|
29
|
-
# id: "remove"
|
30
|
-
# }]
|
31
|
-
# });
|
32
|
-
tbar: !toolbar # you can provide => {except: edit} or {only: [edit, add]}
|
33
|
-
|
34
|
-
# Set our selection model
|
35
|
-
# var sm = new Ext.grid.CheckboxSelectionModel();
|
36
|
-
sm: !checkBoxSelectionModel;
|
37
|
-
|
38
|
-
# Grouping Store
|
39
|
-
store: !groupingStore
|
40
|
-
url: /admin/ecommerces.json
|
41
|
-
reader: !jsonReader
|
42
|
-
fields: <%= @store.store_fields %>
|
43
|
-
|
44
|
-
# Paging toolbar
|
45
|
-
bbar: !pagingToolbar
|
46
|
-
|
47
|
-
# Grid
|
48
|
-
gridPanel:
|
49
|
-
Ext.grid.GridPanel:
|
50
|
-
bbar: bbar
|
51
|
-
clicksToEdit: 1
|
52
|
-
cm: cm
|
53
|
-
region: "center"
|
54
|
-
sm: sm
|
55
|
-
viewConfig: { "forceFit":true }
|
56
|
-
plugins: [new Ext.grid.Search()]
|
57
|
-
border: false
|
58
|
-
tbar: tbar
|
59
|
-
id: "grid-ecommerces"
|
60
|
-
bodyBorder: false
|
61
|
-
store: store
|
62
|
-
view: gw
|
63
|
-
|
64
|
-
# Fix an issue with some browser
|
65
|
-
eval: "gridPanel.on('dblclick', function() { setTimeout(function() { edit() }, 200);"
|
66
|
-
|
67
|
-
# Enable disable toolbar buttons when necessary
|
68
|
-
eval: |
|
69
|
-
gridPanelCheckboxSelectionModel.on('selectionchange', function(){
|
70
|
-
var n = gridPanelCheckboxSelectionModel.getSelected();
|
71
|
-
var btns = gridPanelToolbar.items.map;
|
72
|
-
if(!n){
|
73
|
-
btns.remove.disable();
|
74
|
-
btns.edit.disable();
|
75
|
-
return;
|
76
|
-
} else {
|
77
|
-
btns.remove.enable();
|
78
|
-
btns.edit.enable();
|
79
|
-
return;
|
80
|
-
}
|
81
|
-
});
|