rademade_admin 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/rademade_admin.coffee +1 -0
  3. data/app/assets/javascripts/rademade_admin/app/common/cropper.coffee +0 -4
  4. data/app/assets/javascripts/rademade_admin/app/common/image-preview.coffee +33 -0
  5. data/app/assets/javascripts/rademade_admin/app/templates/image-preview-popup.jst.ejs +3 -0
  6. data/app/assets/javascripts/rademade_admin/app/templates/related-item.jst.ejs +2 -2
  7. data/app/assets/javascripts/rademade_admin/library/ckeditor/config.js +1 -0
  8. data/app/assets/stylesheets/edit.css +15 -0
  9. data/app/assets/stylesheets/rademade_admin/base/main.sass +45 -39
  10. data/app/assets/stylesheets/rademade_admin/blocks/buttons/main.sass +6 -1
  11. data/app/assets/stylesheets/rademade_admin/blocks/form/select2.sass +85 -60
  12. data/app/controllers/rademade_admin/model_controller.rb +3 -0
  13. data/app/helpers/rademade_admin/field_helper.rb +25 -13
  14. data/app/helpers/rademade_admin/form_helper.rb +4 -6
  15. data/app/helpers/rademade_admin/uri_helper.rb +3 -3
  16. data/app/services/csv_service.rb +38 -0
  17. data/app/services/linker.rb +3 -1
  18. data/app/services/model_controller/instance_options.rb +7 -2
  19. data/app/services/model_controller/notifier.rb +15 -19
  20. data/app/services/model_controller/templates.rb +1 -0
  21. data/app/services/saver.rb +6 -1
  22. data/app/services/template_service.rb +38 -19
  23. data/app/services/upload/preview_service.rb +2 -1
  24. data/app/views/rademade_admin/_blocks/_form.html.erb +6 -5
  25. data/app/views/rademade_admin/_blocks/button/_hide.html.erb +2 -2
  26. data/app/views/rademade_admin/_layouts/main.html.erb +3 -6
  27. data/app/views/rademade_admin/abstract/index.html.erb +4 -2
  28. data/config/locales/rademade_admin.en.yml +2 -1
  29. data/config/locales/rademade_admin.ru.yml +2 -1
  30. data/lib/rademade_admin/{hrml_buffer.rb → html_buffer.rb} +0 -0
  31. data/lib/rademade_admin/input/related_select_input/related_list.rb +8 -5
  32. data/lib/rademade_admin/model/adapter/data/mongoid.rb +1 -1
  33. data/lib/rademade_admin/model/adapter/query/active_record.rb +1 -1
  34. data/lib/rademade_admin/model/configuration.rb +17 -1
  35. data/lib/rademade_admin/model/configuration/csv_fields.rb +12 -0
  36. data/lib/rademade_admin/model/configuration/list_field.rb +5 -1
  37. data/lib/rademade_admin/model/info.rb +10 -1
  38. data/lib/rademade_admin/model/info/data_item.rb +31 -13
  39. data/lib/rademade_admin/model/info/data_item/initializer.rb +37 -0
  40. data/lib/rademade_admin/model/info/data_items.rb +11 -1
  41. data/lib/rademade_admin/model/info/fields.rb +39 -26
  42. data/lib/rademade_admin/version.rb +1 -1
  43. metadata +22 -4
  44. data/app/assets/javascripts/rademade_admin/library/jquery/jquery.tablednd.js +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 506cc86834c33f984bbdf61e71dec4fa7a50e1e2
4
- data.tar.gz: ea1cc018f8994d3757f7647ee0897c75aec5cb5f
3
+ metadata.gz: cbf2b035073b7ecd22583c679174032a17198b6f
4
+ data.tar.gz: 680b96e301ee4c35cb8b056c9a2dad63525267b1
5
5
  SHA512:
6
- metadata.gz: c0802b51d1350071bebd1c4ae8cde902a18627f13a14aef041575e32ed52c3be0a2d903a5f6c729d46512cf2357337b3d866a41105ce1aa6c2ab40cef5166080
7
- data.tar.gz: 23254105027ffe82e06ecd9b0a61d61c1f0c96b520d43acb951fe62df286a38af1a8232989131bf1738c108e6e5aa1f4bfa14bda80d2971ad738537f5a72e784
6
+ metadata.gz: 4eeb141cfbcbda28277a22f2381190fc23b6567486b5492abff1888bda148b47876a56beb2edaaaa87121b216b8008d757497a5183a8c042e5a9c342939ca00a
7
+ data.tar.gz: 9cdac46cb24a8f0bca639994b135ec5380d8db904e8881bc1a046d55205fa32eb5c2abbe19a4867a28d902bc8e3d921bb73be989b70a22942f03076daf08d2f1
@@ -21,6 +21,7 @@
21
21
  #= require jquery-validation/src/core
22
22
  #= require jquery-validation/src/ajax
23
23
  #= require jquery-validation/src/delegate
24
+ #= require TableDnD/js/jquery.tablednd
24
25
  #= require leaflet/dist/leaflet-src
25
26
  #= require moment/moment
26
27
  #= require turbolinks
@@ -6,7 +6,6 @@ class @Cropper extends Backbone.View
6
6
  className : 'add_new_popup'
7
7
 
8
8
  events :
9
- 'click' : 'check'
10
9
  'click [data-crop]' : 'crop'
11
10
  'click [data-close]' : 'close'
12
11
 
@@ -31,9 +30,6 @@ class @Cropper extends Backbone.View
31
30
  $image.Jcrop
32
31
  onSelect : @_updateCropAttributes
33
32
 
34
- check : (e) ->
35
- @closePopup() if $(e.target).closest('.crop').length is 0
36
-
37
33
  crop : (e) ->
38
34
  e.preventDefault()
39
35
  @closePopup()
@@ -0,0 +1,33 @@
1
+ class @ImagePreview extends Backbone.View
2
+
3
+ className : 'add_new_popup hide'
4
+
5
+ events :
6
+ 'click' : 'close'
7
+
8
+ show : (imagePath) ->
9
+ @render(imagePath)
10
+ @$el.removeClass 'hide'
11
+
12
+ close : (e) ->
13
+ e.preventDefault()
14
+ @closePopup()
15
+
16
+ closePopup : () ->
17
+ @$el.addClass 'hide'
18
+
19
+ render : (imagePath) ->
20
+ @$el.html @_getHTML(imagePath : imagePath)
21
+
22
+ _getHTML : (data) ->
23
+ JST['rademade_admin/app/templates/image-preview-popup'](data)
24
+
25
+ @init : () ->
26
+ imagePreview = new ImagePreview
27
+ $('#pad-wrapper').append imagePreview.$el
28
+ $('tr .image-preview').click (e) ->
29
+ fullUrl = $(e.currentTarget).attr('full-url')
30
+ imagePreview.show(fullUrl) if fullUrl
31
+
32
+ $ ->
33
+ $(document).on 'page:load ready init-plugins', ImagePreview.init
@@ -0,0 +1,3 @@
1
+ <div class="image-preview-popup">
2
+ <img src="<%= imagePath %>">
3
+ </div>
@@ -1,5 +1,5 @@
1
1
  <span><%= text %></span><%
2
2
  if (editurl) {
3
- %><button data-edit="<%= editurl %>"><%= I18n.t('rademade_admin.edit_related_item') %></button><%
3
+ %><button class="select2-item-edit" data-edit="<%= editurl %>"><%= I18n.t('rademade_admin.edit_related_item') %></button><%
4
4
  }
5
- %><button data-remove><%= I18n.t('rademade_admin.destroy') %></button>
5
+ %><button class="select2-item-remove" data-remove><%= I18n.t('rademade_admin.destroy') %></button>
@@ -1,5 +1,6 @@
1
1
  if (CKEDITOR && CKEDITOR.config) {
2
2
  CKEDITOR.config.language = 'en';
3
+ CKEDITOR.config.forcePasteAsPlainText = true;
3
4
  CKEDITOR.config.toolbar = [
4
5
  { name: 'document', groups: [ 'mode' ], items: [ 'Source' ] },
5
6
  { name: 'editing', groups: [ 'find' ], items: [ 'Find', 'Replace' ] },
@@ -0,0 +1,15 @@
1
+ .image-preview-popup {
2
+ padding: 50px 0;
3
+ width: 75%;
4
+ height: 100%;
5
+ margin: auto;
6
+ text-align: center;
7
+ }
8
+
9
+ .image-preview-popup img {
10
+ width: 100%;
11
+ }
12
+
13
+ tr .image-preview {
14
+ cursor: pointer;
15
+ }
@@ -1,71 +1,77 @@
1
1
  html,
2
2
  body
3
- height: 100%
4
- min-height: 100%
3
+ height: 100%
4
+ min-height: 100%
5
+
5
6
  body
6
- font-size: 12px
7
- color: #2c4042
8
- background: #34495e
9
- +arial
7
+ font-size: 12px
8
+ color: #2c4042
9
+ background: #34495e
10
+ +arial
10
11
 
11
12
  a
12
- text-decoration: none
13
- outline: none
13
+ text-decoration: none
14
+ outline: none
14
15
 
15
16
  b,
16
17
  strong
17
- font-weight: 700
18
+ font-weight: 700
18
19
 
19
20
  .clear
20
- clear: both
21
- float: none !important
21
+ clear: both
22
+ float: none !important
22
23
 
23
24
  .wrapper
24
- min-width: 900px
25
- height: 100%
26
- overflow-x: hidden
27
- background: #34495e
25
+ min-width: 900px
26
+ height: 100%
27
+ overflow-x: hidden
28
+ background: #34495e
28
29
 
29
30
  .fix
30
- min-width: 900px
31
- padding: 0 0 0 15px
32
- margin: 0 auto
31
+ min-width: 900px
32
+ padding: 0 0 0 15px
33
+ margin: 0 auto
33
34
 
34
35
  .fl-l
35
- float: left
36
+ float: left
36
37
 
37
38
  .fl-r
38
- float: right
39
+ float: right
39
40
 
40
41
  .hide
41
- display: none !important
42
+ display: none !important
42
43
 
43
44
  .ico
44
- display: inline-block
45
- position: absolute
45
+ display: inline-block
46
+ position: absolute
46
47
 
47
48
  #overlay
48
- display: none
49
- position: fixed
50
- top: 0
51
- left: 0
52
- width: 100%
53
- height: 100%
54
- background-color: rgba(0, 0, 0, 0.7)
55
- z-index: 998
49
+ display: none
50
+ position: fixed
51
+ top: 0
52
+ left: 0
53
+ width: 100%
54
+ height: 100%
55
+ background-color: rgba(0, 0, 0, 0.7)
56
+ z-index: 998
56
57
 
57
58
  input[type="text"],
58
59
  input[type="password"],
59
60
  input[type="email"]
60
- margin: 0
61
- outline: 0
61
+ margin: 0
62
+ outline: 0
62
63
 
63
64
  input[type="checkbox"]
64
- margin: 0
65
- padding: 0
65
+ margin: 0
66
+ padding: 0
66
67
 
67
68
  textarea
68
- margin: 0
69
- padding: 0
70
- outline: 0
71
- resize: none
69
+ margin: 0
70
+ padding: 0
71
+ outline: 0
72
+ resize: none
73
+
74
+ textarea,
75
+ input
76
+ &:disabled
77
+ +opacity(0.3)
@@ -57,7 +57,10 @@ button
57
57
  border-color: #ac2925
58
58
 
59
59
  .r-margin
60
- margin-right: 20px
60
+ margin-right: 10px
61
+
62
+ .l-margin
63
+ margin-left: 10px
61
64
 
62
65
  .btn-sep
63
66
  margin: 0 10px
@@ -83,6 +86,8 @@ button
83
86
  .login-btn
84
87
  padding: 9px 12px
85
88
  width: 100%
89
+ height: auto
90
+ line-height: initial
86
91
  font-size: 18px
87
92
 
88
93
  .select-btn
@@ -1,67 +1,92 @@
1
1
  .form-box
2
- .input-holder
3
- .select2-container
4
- width: 100%
5
- height: 34px
6
- margin-bottom: 10px
7
- .select2-choices
8
- padding: 0
9
- display: block
10
- width: 100%
11
- font-size: 14px
12
- color: #555
13
- background-color: #fff
14
- background-image: none
15
- border: 1px solid #ccc
16
- +box-sizing(border-box)
17
- +border-radius(4px)
18
- +box-shadow(inset 0 1px 1px rgba(0,0,0,.075))
19
- +transition(border-color ease-in-out .15s,box-shadow ease-in-out .15s)
20
- &:focus
21
- border-color: #66afe9
22
- +box-shadow(inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6))
23
-
24
- .select2-search-choice
25
- display: none
2
+ .input-holder
3
+ .select2-container
4
+ width: 100%
5
+ height: 34px
6
+ margin-bottom: 10px
7
+ .select2-choices
8
+ padding: 0
9
+ display: block
10
+ width: 100%
11
+ font-size: 14px
12
+ color: #555
13
+ background-color: #fff
14
+ background-image: none
15
+ border: 1px solid #ccc
16
+ +box-sizing(border-box)
17
+ +border-radius(4px)
18
+ +box-shadow(inset 0 1px 1px rgba(0, 0, 0, .075))
19
+ +transition(border-color ease-in-out .15s, box-shadow ease-in-out .15s)
20
+ &:focus
21
+ border-color: #66afe9
22
+ +box-shadow(inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6))
26
23
 
27
- .select2-search-field
28
- height: 34px
24
+ .select2-search-choice
25
+ display: none
29
26
 
30
- input[type="text"]
31
- border: 0
32
- padding: 4px 12px
33
- &:focus
34
- outline: 0
35
- +box-shadow(none)
27
+ .select2-search-field
28
+ height: 34px
36
29
 
37
- .select2-choice
38
- height: 34px
39
- background-color: #fff
40
- background-image: none
41
- border: 1px solid #ccc
42
- .select2-chosen
43
- height: 34px
44
- line-height: 34px
45
- font-size: 14px
46
- .select2-arrow
47
- b
48
- background-position: 0 4px
30
+ input[type="text"]
31
+ border: 0
32
+ padding: 4px 12px
33
+ &:focus
34
+ outline: 0
35
+ +box-shadow(none)
49
36
 
37
+ .select2-choice
38
+ height: 34px
39
+ background-color: #fff
40
+ background-image: none
41
+ border: 1px solid #ccc
42
+ .select2-chosen
43
+ height: 34px
44
+ line-height: 34px
45
+ font-size: 14px
46
+ .select2-arrow
47
+ b
48
+ background-position: 0 4px
50
49
 
51
- .select2-items-list
50
+ .select2-items-list
51
+ float: left
52
+ margin-top: 15px
53
+ width: 100%
54
+ border-top: 1px solid #bdc3c7
55
+ li
56
+ padding: 10px 0
57
+ font-size: 14px
58
+ line-height: 24px
59
+ border-bottom: 1px solid #bdc3c7
60
+ +clear
61
+ span
52
62
  float: left
53
- margin-top: 15px
54
- width: 100%
55
- border-top: 1px solid #bdc3c7
56
- li
57
- padding: 10px 0
58
- font-size: 14px
59
- line-height: 24px
60
- border-bottom: 1px solid #bdc3c7
61
- +clear
62
- span
63
- float: left
64
- width: 63%
65
- +to
66
- button
67
- float: right
63
+ width: 63%
64
+ +to
65
+ button
66
+ float: right
67
+
68
+ .select2-item-edit,
69
+ .select2-item-remove
70
+ position: relative
71
+ width: 25px
72
+ height: 25px
73
+ background: none
74
+ overflow: hidden
75
+ text-indent: 100%
76
+ cursor: pointer
77
+ &:before
78
+ position: absolute
79
+ top: 0
80
+ left: 0
81
+ height: 100%
82
+ width: 100%
83
+ font-size: 14px
84
+ color: #000
85
+ text-indent: 0
86
+ @extend .glyphicon
87
+
88
+ .select2-item-edit
89
+ @extend .glyphicon-edit
90
+
91
+ .select2-item-remove
92
+ @extend .glyphicon-trash
@@ -61,6 +61,7 @@ module RademadeAdmin
61
61
  respond_to do |format|
62
62
  format.html { render_template }
63
63
  format.json { render :json => @items }
64
+ format.csv { send_data RademadeAdmin::CsvService.new(model_info, @items).to_csv }
64
65
  end
65
66
  end
66
67
 
@@ -80,6 +81,7 @@ module RademadeAdmin
80
81
  render_template
81
82
  end
82
83
 
84
+ # TODO move related to other controller or remove
83
85
  def related
84
86
  authorize! :read, model_class
85
87
  @related_model_info = RademadeAdmin::RelationService.new.related_model_info(model_info, params[:relation])
@@ -131,6 +133,7 @@ module RademadeAdmin
131
133
  end
132
134
 
133
135
  protected
136
+ # TODO move to search module
134
137
 
135
138
  def index_items
136
139
  conditions = Search::Conditions::List.new(params, model_info.data_items)
@@ -9,21 +9,23 @@ module RademadeAdmin::FieldHelper
9
9
  # @return [String]
10
10
  #
11
11
  def display_item_value(item, data_item)
12
- value = item.send(data_item.preview_accessor)
13
- if data_item.has_relation?
14
- # rm_todo extract method
15
- if data_item.relation.has_many?
16
- link_to data_item.label, admin_related_item(item, data_item.getter)
17
- else
18
- link_to value.to_s, admin_edit_uri(value) unless value.nil?
19
- end
20
- elsif data_item.has_uploader?
21
- RademadeAdmin::Upload::PreviewService.new(value).uploaded_file_html
12
+ value = raw_item_value(item, data_item)
13
+ return (value ? '✔' : '×') if value.is_a?(::Boolean)
14
+ value
15
+ end
16
+
17
+ def display_related_item(data_item, value)
18
+ if data_item.relation.has_many?
19
+ link_to(data_item.label, admin_related_item(item, data_item.getter))
22
20
  else
23
- value.to_s.html_safe
21
+ link_to(value.to_s, admin_edit_uri(value)) unless value.nil?
24
22
  end
25
23
  end
26
24
 
25
+ def display_upload_item(_, value)
26
+ RademadeAdmin::Upload::PreviewService.new(value).uploaded_file_html
27
+ end
28
+
27
29
  def pagination_option(number, name = 'paginate')
28
30
  hash_params = request.query_parameters.clone
29
31
  hash_params.delete(:page)
@@ -35,8 +37,18 @@ module RademadeAdmin::FieldHelper
35
37
  end
36
38
 
37
39
  def input_attr(attrs = {})
38
- attrs.deep_merge :wrapper_html => { :class => 'form-group' },
39
- :input_html => { :class => 'form-input' }
40
+ attrs.deep_merge(
41
+ wrapper_html: { class: 'form-group' },
42
+ input_html: { class: 'form-input' }
43
+ )
44
+ end
45
+
46
+ def raw_item_value(item, data_item)
47
+ return data_item.list_preview_handler.call(item) unless data_item.list_preview_handler.nil?
48
+ value = item.send(data_item.list_preview_accessor)
49
+ return display_upload_item(data_item, value) if data_item.has_uploader?
50
+ return display_related_item(data_item, value) if data_item.has_relation?
51
+ value.to_s.html_safe
40
52
  end
41
53
 
42
54
  end