rear 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +20 -0
- data/LICENSE +19 -0
- data/README.md +101 -0
- data/Rakefile +79 -0
- data/assets/api.js +307 -0
- data/assets/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css +8 -0
- data/assets/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js +26 -0
- data/assets/bootstrap/css/bootstrap-responsive.min.css +9 -0
- data/assets/bootstrap/css/bootstrap.min.css +9 -0
- data/assets/bootstrap/img/glyphicons-halflings-white.png +0 -0
- data/assets/bootstrap/img/glyphicons-halflings.png +0 -0
- data/assets/bootstrap/js/bootstrap.min.js +6 -0
- data/assets/jquery.js +5 -0
- data/assets/noty/jquery.noty.js +520 -0
- data/assets/noty/layouts/top.js +34 -0
- data/assets/noty/layouts/topRight.js +43 -0
- data/assets/noty/promise.js +432 -0
- data/assets/noty/themes/default.js +156 -0
- data/assets/select2-bootstrap.css +86 -0
- data/assets/select2/select2-spinner.gif +0 -0
- data/assets/select2/select2.css +652 -0
- data/assets/select2/select2.min.js +22 -0
- data/assets/select2/select2.png +0 -0
- data/assets/select2/select2x2.png +0 -0
- data/assets/ui.css +75 -0
- data/assets/xhr.js +4 -0
- data/bin/rear +65 -0
- data/docs/Assocs.md +100 -0
- data/docs/Columns.md +404 -0
- data/docs/Deploy.md +62 -0
- data/docs/FileManager.md +75 -0
- data/docs/Filters.md +341 -0
- data/docs/Setup.md +201 -0
- data/lib/rear.rb +13 -0
- data/lib/rear/actions.rb +98 -0
- data/lib/rear/constants.rb +61 -0
- data/lib/rear/controller_setup.rb +249 -0
- data/lib/rear/helpers.rb +17 -0
- data/lib/rear/helpers/class.rb +46 -0
- data/lib/rear/helpers/columns.rb +68 -0
- data/lib/rear/helpers/filters.rb +147 -0
- data/lib/rear/helpers/generic.rb +73 -0
- data/lib/rear/helpers/order.rb +47 -0
- data/lib/rear/helpers/pager.rb +35 -0
- data/lib/rear/helpers/render.rb +37 -0
- data/lib/rear/home_controller.rb +10 -0
- data/lib/rear/input.rb +341 -0
- data/lib/rear/orm.rb +73 -0
- data/lib/rear/rear.rb +74 -0
- data/lib/rear/setup.rb +9 -0
- data/lib/rear/setup/associations.rb +33 -0
- data/lib/rear/setup/columns.rb +109 -0
- data/lib/rear/setup/filters.rb +314 -0
- data/lib/rear/setup/generic.rb +59 -0
- data/lib/rear/setup/menu.rb +39 -0
- data/lib/rear/templates/editor/ace.slim +7 -0
- data/lib/rear/templates/editor/assocs.slim +10 -0
- data/lib/rear/templates/editor/boolean.slim +5 -0
- data/lib/rear/templates/editor/bulk_edit.slim +75 -0
- data/lib/rear/templates/editor/checkbox.slim +5 -0
- data/lib/rear/templates/editor/ckeditor.slim +7 -0
- data/lib/rear/templates/editor/date.slim +9 -0
- data/lib/rear/templates/editor/datetime.slim +9 -0
- data/lib/rear/templates/editor/layout.slim +103 -0
- data/lib/rear/templates/editor/password.slim +1 -0
- data/lib/rear/templates/editor/radio.slim +5 -0
- data/lib/rear/templates/editor/select.slim +3 -0
- data/lib/rear/templates/editor/string.slim +1 -0
- data/lib/rear/templates/editor/text.slim +1 -0
- data/lib/rear/templates/editor/time.slim +9 -0
- data/lib/rear/templates/error.slim +36 -0
- data/lib/rear/templates/filters/boolean.slim +10 -0
- data/lib/rear/templates/filters/checkbox.slim +15 -0
- data/lib/rear/templates/filters/date.slim +10 -0
- data/lib/rear/templates/filters/datetime.slim +10 -0
- data/lib/rear/templates/filters/layout.slim +26 -0
- data/lib/rear/templates/filters/radio.slim +14 -0
- data/lib/rear/templates/filters/select.slim +9 -0
- data/lib/rear/templates/filters/string.slim +3 -0
- data/lib/rear/templates/filters/text.slim +3 -0
- data/lib/rear/templates/filters/time.slim +10 -0
- data/lib/rear/templates/home.slim +0 -0
- data/lib/rear/templates/layout.slim +78 -0
- data/lib/rear/templates/pager.slim +22 -0
- data/lib/rear/templates/pane/ace.slim +2 -0
- data/lib/rear/templates/pane/assocs.slim +62 -0
- data/lib/rear/templates/pane/boolean.slim +2 -0
- data/lib/rear/templates/pane/checkbox.slim +5 -0
- data/lib/rear/templates/pane/ckeditor.slim +2 -0
- data/lib/rear/templates/pane/date.slim +2 -0
- data/lib/rear/templates/pane/datetime.slim +2 -0
- data/lib/rear/templates/pane/layout.slim +111 -0
- data/lib/rear/templates/pane/password.slim +2 -0
- data/lib/rear/templates/pane/quickview.slim +21 -0
- data/lib/rear/templates/pane/radio.slim +5 -0
- data/lib/rear/templates/pane/select.slim +5 -0
- data/lib/rear/templates/pane/string.slim +2 -0
- data/lib/rear/templates/pane/text.slim +2 -0
- data/lib/rear/templates/pane/time.slim +2 -0
- data/lib/rear/utils.rb +288 -0
- data/rear.gemspec +27 -0
- data/test/helpers.rb +33 -0
- data/test/models/ar.rb +52 -0
- data/test/models/dm.rb +53 -0
- data/test/models/sq.rb +58 -0
- data/test/setup.rb +4 -0
- data/test/templates/adhoc/book/editor/name.slim +1 -0
- data/test/templates/adhoc/book/editor/string.slim +1 -0
- data/test/templates/adhoc/book/pane/name.slim +1 -0
- data/test/templates/adhoc/book/pane/string.slim +1 -0
- data/test/templates/shared/shared-templates/editor/string.slim +1 -0
- data/test/templates/shared/shared-templates/pane/string.slim +1 -0
- data/test/test__assocs.rb +249 -0
- data/test/test__columns.rb +269 -0
- data/test/test__crud.rb +81 -0
- data/test/test__custom_templates.rb +147 -0
- data/test/test__filters.rb +228 -0
- metadata +220 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzMxZTgzYTI0ODY4ZjExZmVhZWJkNWU2NWJhYWE4YTc2ODc5ZGM5Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZmEzZmE4ZGE1NjMxNjAxZjQyNjdlNTE4ZmRkODFlYjIxMTY5OTY5Ng==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZWJhZmZmMWQ3N2IzMDRjZWVlODAzMmIzZjQ2ZjUyNmU5NDI2ZTYzY2I4MzZl
|
10
|
+
YzlmOGNhYjJjOGZlOThlZDZlYjU0NTViYzRlMDdmY2JjNTFhMzFkYzhhNWRm
|
11
|
+
NzQ4NmU1NDUwYzIyZjJkZGFlMzZhMTE4ZGYzNjcxNDY5ODlmNzc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDNlY2NmNjViOTk1ZTU3MDYxYjEwYjg1YTQwZDM1MmRkZDQyMDg1NDQyYmY1
|
14
|
+
ZWY4MzNlNzQ3MmMwNjNiY2VlZmFiOTI5MThhODEzMTgyZGIzYmZiZDUyYWNm
|
15
|
+
NDRhMmU5NWUzNjE1YTdjMGNjZjkyZDgyMGE5YjQyNWNhNzY2NTM=
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
if ENV['E_DEV']
|
5
|
+
%w[e el rear].each do |g|
|
6
|
+
gem g, path: File.expand_path('../../' + g, __FILE__)
|
7
|
+
end
|
8
|
+
else
|
9
|
+
gem 'el'
|
10
|
+
end
|
11
|
+
|
12
|
+
gem 'rake', '~> 10'
|
13
|
+
gem 'specular', '>= 0.2.1'
|
14
|
+
gem 'sonar', '>= 0.1.5'
|
15
|
+
gem 'nokogiri', '~> 1.5'
|
16
|
+
gem 'activerecord', '~> 3.2', require: 'active_record'
|
17
|
+
gem 'sqlite3', '~> 1.3'
|
18
|
+
gem 'data_mapper', '~> 1.2'
|
19
|
+
gem 'dm-sqlite-adapter', '~> 1.2'
|
20
|
+
gem 'sequel'
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2013 Silviu Rusu <slivuz@gmail.com>
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"),
|
6
|
+
to deal in the Software without restriction, including without limitation
|
7
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8
|
+
and/or sell copies of the Software, and to permit persons to whom the Software
|
9
|
+
is furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
12
|
+
copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
|
2
|
+
# Rear
|
3
|
+
|
4
|
+
<a href="https://travis-ci.org/espresso/rear">
|
5
|
+
<img align="right" src="https://travis-ci.org/espresso/rear.png"></a>
|
6
|
+
|
7
|
+
### ORM-agnostic CRUDifier for Espresso Framework ([DEMO](http://rear.rbho.me/))
|
8
|
+
|
9
|
+
## Highlights
|
10
|
+
|
11
|
+
- `ActiveRecord`, `DataMapper`, `Sequel` support
|
12
|
+
- Associations of any type supported
|
13
|
+
- Fully dynamic interface, no scaffolding
|
14
|
+
- Custom templates when needed
|
15
|
+
- Minimal dependencies - `Espresso` and `Slim`
|
16
|
+
- Tested on all 1.9+ Rubies
|
17
|
+
|
18
|
+
|
19
|
+
## Quick Start
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'rear' # or add "gem 'rear'" to Gemfile
|
23
|
+
|
24
|
+
# model
|
25
|
+
class Page < ActiveRecord::Base
|
26
|
+
# ...
|
27
|
+
end
|
28
|
+
|
29
|
+
# controller
|
30
|
+
Rear.register Page do
|
31
|
+
# setups goes here, if any
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
**Run**
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Rear.run
|
39
|
+
|
40
|
+
# or
|
41
|
+
E.new do
|
42
|
+
mount Rear.controllers
|
43
|
+
run
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Tutorial
|
48
|
+
|
49
|
+
### [Setup](https://github.com/espresso/rear/blob/master/docs/Setup.md)
|
50
|
+
|
51
|
+
|
52
|
+
[Primary key](https://github.com/espresso/rear/blob/master/docs/Setup.md#primary-key) |
|
53
|
+
[Ordering](https://github.com/espresso/rear/blob/master/docs/Setup.md#ordering) |
|
54
|
+
[Items per page](https://github.com/espresso/rear/blob/master/docs/Setup.md#items-per-page) |
|
55
|
+
[Menu Label](https://github.com/espresso/rear/blob/master/docs/Setup.md#menu-label) |
|
56
|
+
[Menu Positioning](https://github.com/espresso/rear/blob/master/docs/Setup.md#menu-positioning) |
|
57
|
+
[Menu Grouping](https://github.com/espresso/rear/blob/master/docs/Setup.md#menu-grouping) |
|
58
|
+
[ReadOnly Mode](https://github.com/espresso/rear/blob/master/docs/Setup.md#readonly-mode)
|
59
|
+
|
60
|
+
|
61
|
+
### [Columns](https://github.com/espresso/rear/blob/master/docs/Columns.md)
|
62
|
+
|
63
|
+
[Type](https://github.com/espresso/rear/blob/master/docs/Columns.md#column-types) |
|
64
|
+
[Label](https://github.com/espresso/rear/blob/master/docs/Columns.md#columns-label) |
|
65
|
+
[Radio/Checkbox/Select](https://github.com/espresso/rear/blob/master/docs/Columns.md#radiocheckboxselect-columns) |
|
66
|
+
[Readonly/Disabled](https://github.com/espresso/rear/blob/master/docs/Columns.md#readonlydisabled-columns) |
|
67
|
+
[Rows](https://github.com/espresso/rear/blob/master/docs/Columns.md#organizing-columns-by-rows) |
|
68
|
+
[HTML Attributes](https://github.com/espresso/rear/blob/master/docs/Columns.md#html-attributes) |
|
69
|
+
[Loading Data](https://github.com/espresso/rear/blob/master/docs/Columns.md#loading-data)<br>
|
70
|
+
[Hiding Columns](https://github.com/espresso/rear/blob/master/docs/Columns.md#hiding-columns) |
|
71
|
+
[Resetting Columns](https://github.com/espresso/rear/blob/master/docs/Columns.md#resetting-columns)
|
72
|
+
|
73
|
+
|
74
|
+
### [Associations](https://github.com/espresso/rear/blob/master/docs/Assocs.md)
|
75
|
+
|
76
|
+
[Columns List](https://github.com/espresso/rear/blob/master/docs/Assocs.md#columns-list) |
|
77
|
+
[Ignored Associations](https://github.com/espresso/rear/blob/master/docs/Assocs.md#ignored-associations) |
|
78
|
+
[Readonly Associations](https://github.com/espresso/rear/blob/master/docs/Assocs.md#readonly-associations)
|
79
|
+
|
80
|
+
|
81
|
+
### [Filters](https://github.com/espresso/rear/blob/master/docs/Filters.md)
|
82
|
+
|
83
|
+
[Type](https://github.com/espresso/rear/blob/master/docs/Filters.md#filter-types) |
|
84
|
+
[Comparison Functions](https://github.com/espresso/rear/blob/master/docs/Filters.md#comparison-functions) |
|
85
|
+
[Optioned Filters](https://github.com/espresso/rear/blob/master/docs/Filters.md#optioned-filters) |
|
86
|
+
[Decorative Filters](https://github.com/espresso/rear/blob/master/docs/Filters.md#decorative-filters) |
|
87
|
+
[Quick Filters](https://github.com/espresso/rear/blob/master/docs/Filters.md#quick-filters)
|
88
|
+
|
89
|
+
### More
|
90
|
+
|
91
|
+
[FileManager](https://github.com/espresso/rear/blob/master/docs/FileManager.md) |
|
92
|
+
[Deploy](https://github.com/espresso/rear/blob/master/docs/Deploy.md) |
|
93
|
+
[Demo](http://rear.rbho.me/)
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
- Fork Rear repository
|
98
|
+
- Make your changes
|
99
|
+
- Submit a pull request
|
100
|
+
|
101
|
+
### Author - [Silviu Rusu](https://github.com/slivu). License - [MIT](https://github.com/espresso/rear/blob/master/LICENSE).
|
data/Rakefile
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'bundler/gem_helper'
|
3
|
+
require './test/helpers'
|
4
|
+
require './test/setup'
|
5
|
+
|
6
|
+
def run orm, message = nil
|
7
|
+
|
8
|
+
require './test/models/%s' % orm
|
9
|
+
Dir['./test/test__*.rb'].each { |f| require f }
|
10
|
+
Rear.mount! # initializing Rear controllers
|
11
|
+
puts message
|
12
|
+
|
13
|
+
session = Specular.new
|
14
|
+
session.boot { include Sonar }
|
15
|
+
session.before do |app|
|
16
|
+
include EASpecHelpers
|
17
|
+
if app && EUtils.is_app?(app)
|
18
|
+
app.mount
|
19
|
+
app(app)
|
20
|
+
map(app.base_url)
|
21
|
+
app.ipp(1000) if app.respond_to?(:ipp)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
session.run /RearTest/
|
25
|
+
puts session.failures if session.failed?
|
26
|
+
puts session.summary
|
27
|
+
exit session.exit_code
|
28
|
+
end
|
29
|
+
|
30
|
+
def run_ar
|
31
|
+
run :ar, "\n***\n Running ActiveRecord tests ..."
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_dm
|
35
|
+
run :dm, "\n***\n Running DataMapper tests ..."
|
36
|
+
end
|
37
|
+
|
38
|
+
def run_sq
|
39
|
+
run :sq, "\n***\n Running Sequel tests ..."
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Run ActiveRecord tests'
|
43
|
+
task('test:ar') { run_ar }
|
44
|
+
|
45
|
+
desc 'Run DataMapper tests'
|
46
|
+
task('test:dm') { run_dm }
|
47
|
+
|
48
|
+
desc 'Run Sequel tests'
|
49
|
+
task('test:sq') { run_sq }
|
50
|
+
|
51
|
+
desc 'Run All tests'
|
52
|
+
task :test do
|
53
|
+
exitcode = 0
|
54
|
+
(pid = fork { run_ar }) && Process.wait(pid); exitcode += $?.exitstatus
|
55
|
+
(pid = fork { run_dm }) && Process.wait(pid); exitcode += $?.exitstatus
|
56
|
+
(pid = fork { run_sq }) && Process.wait(pid); exitcode += $?.exitstatus
|
57
|
+
exitcode == 0 || fail
|
58
|
+
end
|
59
|
+
|
60
|
+
namespace :assets do
|
61
|
+
desc 'Update css files to correctly load background images'
|
62
|
+
task :css do
|
63
|
+
puts "Looking for css files containing background(-image)?:url ..."
|
64
|
+
src = /background(\-image)?[\s+]?\:(.*?)url\((\W+)?([^\.]*)\.(\w+)(\W+)?\)/
|
65
|
+
dst = 'background\1:\2url(\3\4.\5%s\6)' % RearConstants::ASSETS__SUFFIX
|
66
|
+
Dir[File.expand_path('../assets/**/*.css', __FILE__)].each do |file|
|
67
|
+
css = File.read(file)
|
68
|
+
if css =~ src
|
69
|
+
puts "Updating #{file}"
|
70
|
+
File.open(file, 'w') {|f| f << css.gsub(src, dst)}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
puts "Done"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
task default: :test
|
78
|
+
|
79
|
+
Bundler::GemHelper.install_tasks
|
data/assets/api.js
ADDED
@@ -0,0 +1,307 @@
|
|
1
|
+
RearAPI = function() {
|
2
|
+
|
3
|
+
var errorInstance;
|
4
|
+
|
5
|
+
this.switch_page = function(domSelector, url) {
|
6
|
+
$.ajax({
|
7
|
+
url: url,
|
8
|
+
type: 'GET'
|
9
|
+
}).done(function(response) {
|
10
|
+
$(domSelector).html(response);
|
11
|
+
});
|
12
|
+
}
|
13
|
+
|
14
|
+
this.check_multiple = function(domSelector, sourceElement, isControlElement) {
|
15
|
+
var status = sourceElement.checked;
|
16
|
+
|
17
|
+
if(isControlElement)
|
18
|
+
return $(domSelector).prop('checked', status);
|
19
|
+
|
20
|
+
if (event.shiftKey) { // if holding Shift, toggle elements before clicked one
|
21
|
+
$(domSelector).each(function(i,e) {
|
22
|
+
// break iteration when arriving at checked element
|
23
|
+
if(e == sourceElement) return false;
|
24
|
+
$(e).prop('checked', status);
|
25
|
+
});
|
26
|
+
} else if (event.altKey) { // if holding Alt, toggle elements after clicked one
|
27
|
+
var sourceElementFound = false;
|
28
|
+
$(domSelector).each(function(i,e) {
|
29
|
+
// moving to next element until arriving to checked one
|
30
|
+
if(e == sourceElement) return sourceElementFound = true;
|
31
|
+
if(sourceElementFound) $(e).prop('checked', status);
|
32
|
+
});
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
this.trigger_selectable = function(domSelector) {
|
37
|
+
// using select.selectable instead of just .selectable
|
38
|
+
// to avoid Select2 to apply twice when pages loaded by XHR.
|
39
|
+
// that's it, Select2 converts .selectable elements into divs,
|
40
|
+
// so select.selectable wont match converted elements anymore.
|
41
|
+
$(domSelector || 'select.selectable').each(function(i,e) {
|
42
|
+
if($(e).select2 == 'undefined') return false;
|
43
|
+
$(e).select2({width: 'resolve'});
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
47
|
+
this.trigger_hoverable = function(domSelector) {
|
48
|
+
$(domSelector || ".hoverable").hover(
|
49
|
+
function () { $(this).addClass("hoverable-hover") },
|
50
|
+
function () { $(this).removeClass("hoverable-hover") }
|
51
|
+
);
|
52
|
+
}
|
53
|
+
|
54
|
+
this.CRUD = function(objectID, baseURL, redirectURL, readonly) {
|
55
|
+
var objectID = objectID,
|
56
|
+
baseURL = baseURL,
|
57
|
+
redirectURL = redirectURL;
|
58
|
+
|
59
|
+
this.save = function() {
|
60
|
+
if(readonly) {
|
61
|
+
Rear.warn('ReadOnly Mode! Item Not Saved');
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
if (objectID > 0) {
|
65
|
+
var requestMethod = 'PUT',
|
66
|
+
url = [baseURL, objectID].join('/'),
|
67
|
+
alert = "Item Successfully Updated";
|
68
|
+
} else {
|
69
|
+
var requestMethod = 'POST',
|
70
|
+
url = baseURL,
|
71
|
+
alert = "Item Successfully Created";
|
72
|
+
}
|
73
|
+
|
74
|
+
$.ajax({
|
75
|
+
url: url,
|
76
|
+
type: requestMethod,
|
77
|
+
data: $('#editor-main_form').serialize(),
|
78
|
+
complete: function(xhr) {
|
79
|
+
if(xhr.statusText == "OK") {
|
80
|
+
if (objectID > 0) {
|
81
|
+
if(errorInstance) errorInstance.close();
|
82
|
+
Rear.alert(alert);
|
83
|
+
} else {
|
84
|
+
localStorage['flash'] = alert;
|
85
|
+
window.location = [redirectURL, xhr.responseText].join('/');
|
86
|
+
}
|
87
|
+
} else Rear.error(xhr.responseText);
|
88
|
+
}
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
this.delete = function(redirectURL) {
|
93
|
+
if(readonly) {
|
94
|
+
Rear.warn('ReadOnly Mode! Item Not Deleted');
|
95
|
+
return false;
|
96
|
+
}
|
97
|
+
$.ajax({
|
98
|
+
url: [baseURL, objectID].join('/'),
|
99
|
+
type: 'DELETE',
|
100
|
+
complete: function(xhr) {
|
101
|
+
if(xhr.statusText == "OK") {
|
102
|
+
localStorage['flash'] = "Item Successfully Deleted";
|
103
|
+
window.location = redirectURL;
|
104
|
+
} else Rear.error(xhr.responseText);
|
105
|
+
}
|
106
|
+
});
|
107
|
+
}
|
108
|
+
|
109
|
+
this.delete_selected = function(baseURL, redirectURL, readonly) {
|
110
|
+
if(readonly) {
|
111
|
+
Rear.warn('ReadOnly Mode! No Items Deleted');
|
112
|
+
return false;
|
113
|
+
}
|
114
|
+
var items = []
|
115
|
+
$('.pane-selected_item:checked').each(function(i,e) {
|
116
|
+
items.push($(e).val());
|
117
|
+
});
|
118
|
+
$.ajax({
|
119
|
+
url: baseURL,
|
120
|
+
type: 'DELETE',
|
121
|
+
data: {items: items.join(' ')},
|
122
|
+
complete: function(xhr) {
|
123
|
+
if(xhr.statusText == "OK") {
|
124
|
+
localStorage['flash'] = "Selected Items Successfully Deleted";
|
125
|
+
window.location = redirectURL;
|
126
|
+
} else Rear.error(xhr.responseText);
|
127
|
+
}
|
128
|
+
});
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
this.BulkCRUD = function(baseURL) {
|
133
|
+
|
134
|
+
this.invoke = function(){
|
135
|
+
var form = $('#bulk_editor-main_form');
|
136
|
+
if(!form) {
|
137
|
+
Rear.error('No form found for bulk editing');
|
138
|
+
return false;
|
139
|
+
}
|
140
|
+
|
141
|
+
$.ajax({
|
142
|
+
url: baseURL,
|
143
|
+
type: 'POST',
|
144
|
+
data: form.serialize(),
|
145
|
+
complete: function(xhr) {
|
146
|
+
if(xhr.statusText == 'OK') {
|
147
|
+
if(errorInstance) errorInstance.close();
|
148
|
+
Rear.sticky_alert(xhr.responseText);
|
149
|
+
} else
|
150
|
+
Rear.error(xhr.responseText);
|
151
|
+
}
|
152
|
+
});
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
this.Assoc = function(baseURL, domSelector, readonly) {
|
157
|
+
var urlArray = baseURL.split('?');
|
158
|
+
var baseURL = urlArray[0],
|
159
|
+
queryString = urlArray[1],
|
160
|
+
domSelector = domSelector,
|
161
|
+
readonly = readonly;
|
162
|
+
|
163
|
+
this.load = function() {
|
164
|
+
this.load_attached();
|
165
|
+
this.load_detached();
|
166
|
+
}
|
167
|
+
this.load_attached = function(attacher) {
|
168
|
+
// queryString are used here only to pass assoc filters
|
169
|
+
// and it makes sense to apply assoc filters only on detached items
|
170
|
+
$.get(baseURL + '/true', function(response) {
|
171
|
+
$(domSelector.replace(/_detached$/, '')).html(response);
|
172
|
+
$('.pane-assoc-attacher').each(function(i,e) {
|
173
|
+
$(e).attr('checked', e == attacher);
|
174
|
+
});
|
175
|
+
});
|
176
|
+
}
|
177
|
+
this.load_detached = function(callback) {
|
178
|
+
$.get(baseURL, queryString, function(response) {
|
179
|
+
$(domSelector + '_detached').html(response);
|
180
|
+
callback && typeof(callback) === "function" && callback();
|
181
|
+
});
|
182
|
+
}
|
183
|
+
|
184
|
+
this.create = function(remoteID) {
|
185
|
+
if(readonly) {
|
186
|
+
Rear.warn('ReadOnly Relation! Any updates discarded');
|
187
|
+
return false;
|
188
|
+
}
|
189
|
+
invoke('POST', remoteID);
|
190
|
+
}
|
191
|
+
this.delete = function(remoteID) {
|
192
|
+
if(readonly) {
|
193
|
+
Rear.warn('ReadOnly Relation! Any updates discarded');
|
194
|
+
return false;
|
195
|
+
}
|
196
|
+
invoke('DELETE', remoteID);
|
197
|
+
}
|
198
|
+
|
199
|
+
var invoke = function(requestMethod, remoteID) {
|
200
|
+
$.ajax({
|
201
|
+
type: requestMethod,
|
202
|
+
url: baseURL,
|
203
|
+
data: {target_item_id: remoteID},
|
204
|
+
complete: function(xhr, txtResponse) {
|
205
|
+
if(txtResponse == 'success') {
|
206
|
+
Rear.alert('Relation Updated');
|
207
|
+
} else {
|
208
|
+
if(xhr.status == 400)
|
209
|
+
Rear.warn(xhr.responseText);
|
210
|
+
else if(xhr.status == 500)
|
211
|
+
Rear.error(xhr.responseText);
|
212
|
+
}
|
213
|
+
}
|
214
|
+
});
|
215
|
+
}
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
this.Filters = function(domID, url) {
|
220
|
+
var domID = domID, url = url;
|
221
|
+
|
222
|
+
this.apply = function() {
|
223
|
+
invoke(
|
224
|
+
'#' + domID,
|
225
|
+
$('#pane-filters-form-' + domID).serialize()
|
226
|
+
);
|
227
|
+
}
|
228
|
+
|
229
|
+
this.reset = function() {
|
230
|
+
invoke('#' + domID, {});
|
231
|
+
}
|
232
|
+
|
233
|
+
this.update = function() {
|
234
|
+
invoke(
|
235
|
+
'#pane-filters-input-' + domID,
|
236
|
+
$('#pane-filters-form-' + domID).serialize()
|
237
|
+
);
|
238
|
+
}
|
239
|
+
|
240
|
+
var invoke = function(domSelector, data) {
|
241
|
+
$.ajax({
|
242
|
+
url: url, type: 'GET', data: data
|
243
|
+
}).done(function(response) {
|
244
|
+
$(domSelector).html(response);
|
245
|
+
});
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
249
|
+
this.alert = function(msg, timeout) {
|
250
|
+
noty({
|
251
|
+
text: msg,
|
252
|
+
type: 'information',
|
253
|
+
layout: 'topRight',
|
254
|
+
timeout: timeout || 2000
|
255
|
+
});
|
256
|
+
}
|
257
|
+
|
258
|
+
this.sticky_alert = function(msg) {
|
259
|
+
noty({
|
260
|
+
text: msg,
|
261
|
+
type: 'information',
|
262
|
+
layout: 'topRight'
|
263
|
+
});
|
264
|
+
}
|
265
|
+
|
266
|
+
this.warn = function(msg, timeout) {
|
267
|
+
noty({
|
268
|
+
text: msg,
|
269
|
+
type: 'warning',
|
270
|
+
layout: 'topRight',
|
271
|
+
timeout: timeout || 3000
|
272
|
+
});
|
273
|
+
}
|
274
|
+
|
275
|
+
this.sticky_warn = function(msg) {
|
276
|
+
noty({
|
277
|
+
text: msg,
|
278
|
+
type: 'warning',
|
279
|
+
layout: 'topRight'
|
280
|
+
});
|
281
|
+
}
|
282
|
+
|
283
|
+
this.error = function(msg) {
|
284
|
+
msg = msg.replace(/</gm, '<').replace(/>/gm, '>').
|
285
|
+
replace(/\n|\r/gm, '<br>').replace(/\t/gm, ' ');
|
286
|
+
errorInstance = noty({
|
287
|
+
text: '<div style="text-align: left; max-height: 280px; overflow: auto;">' + msg + '</div>',
|
288
|
+
type: 'warning', layout: 'top', modal: true, closeWith: ['button'],
|
289
|
+
buttons: [
|
290
|
+
{addClass: 'btn btn-primary', text: 'Close', onClick: function($noty) {
|
291
|
+
$noty.close();
|
292
|
+
}
|
293
|
+
}
|
294
|
+
]
|
295
|
+
});
|
296
|
+
}
|
297
|
+
|
298
|
+
}
|
299
|
+
|
300
|
+
Rear = new RearAPI();
|
301
|
+
|
302
|
+
$(function(){
|
303
|
+
if(localStorage['flash']) {
|
304
|
+
Rear.alert(localStorage['flash']);
|
305
|
+
localStorage.removeItem('flash');
|
306
|
+
}
|
307
|
+
});
|