rademade_admin 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.svg +229 -0
- data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/images/rademade_admin/ico/btn-attach.png +0 -0
- data/app/assets/images/rademade_admin/logos/logo.png +0 -0
- data/app/assets/javascripts/rademade_admin.coffee +8 -4
- data/app/assets/javascripts/rademade_admin/app/app.coffee +2 -1
- data/app/assets/javascripts/rademade_admin/app/common/datetime-picker.coffee +7 -0
- data/app/assets/javascripts/rademade_admin/app/common/dnd-sort.coffee +23 -32
- data/app/assets/javascripts/rademade_admin/app/common/droplist.coffee +8 -0
- data/app/assets/javascripts/rademade_admin/app/common/lang-panel.coffee +6 -0
- data/app/assets/javascripts/rademade_admin/app/common/related-index.coffee +6 -9
- data/app/assets/javascripts/rademade_admin/app/common/sort-list.coffee +10 -14
- data/app/assets/javascripts/rademade_admin/app/common/uploader.coffee +3 -3
- data/app/assets/javascripts/rademade_admin/app/form-popup/initializer.coffee +24 -37
- data/app/assets/javascripts/rademade_admin/app/form-popup/view.coffee +32 -18
- data/app/assets/javascripts/rademade_admin/app/forms/remove.coffee +4 -3
- data/app/assets/javascripts/rademade_admin/app/select2/model.coffee +7 -0
- data/app/assets/javascripts/rademade_admin/app/select2/related/collection-view.coffee +35 -0
- data/app/assets/javascripts/rademade_admin/app/select2/related/collection.coffee +28 -0
- data/app/assets/javascripts/rademade_admin/app/select2/related/model.coffee +15 -0
- data/app/assets/javascripts/rademade_admin/app/select2/related/view.coffee +40 -0
- data/app/assets/javascripts/rademade_admin/app/select2/view.coffee +78 -0
- data/app/assets/javascripts/rademade_admin/form/form-ajax.coffee +48 -0
- data/app/assets/javascripts/rademade_admin/form/form-initializater.coffee +45 -0
- data/app/assets/javascripts/rademade_admin/form/form-validation.coffee +42 -0
- data/app/assets/javascripts/rademade_admin/form/form.coffee +62 -0
- data/app/assets/javascripts/rademade_admin/library/ckeditor/config.js +14 -12
- data/app/assets/stylesheets/{rademade_admin/bootstrap → old/-bootstrap}/bootstrap-overrides.css.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/bootstrap → old/-bootstrap}/main.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/chart-showcase.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/datatables.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/elements.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/error.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/form-showcase.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/form-wizard.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/gallery.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/grids.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/icons.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/index.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/layout.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/new-user.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/personal-info.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/popup.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/signin.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/tables.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/ui-elements.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/user-list.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/user-profile.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/web-app-icons.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/lib → old/-lib}/bootstrap.datepicker.css.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/lib → old/-lib}/morris.css.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/base.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/edit.css +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/file-upload.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/notifier.custom.css.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/scaffolds.scss.erb +0 -0
- data/app/assets/stylesheets/rademade_admin.sass.erb +96 -0
- data/app/assets/stylesheets/rademade_admin/base/main.sass +71 -0
- data/app/assets/stylesheets/rademade_admin/blocks/buttons/main.sass +81 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/input.sass +29 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/label.sass +31 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/select.sass +26 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/select2.sass +67 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/table.sass +42 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/texarea.sass +20 -0
- data/app/assets/stylesheets/rademade_admin/blocks/header/_logo.sass +7 -0
- data/app/assets/stylesheets/rademade_admin/blocks/header/_menu.sass +80 -0
- data/app/assets/stylesheets/rademade_admin/blocks/header/_search.sass +37 -0
- data/app/assets/stylesheets/rademade_admin/blocks/page/content/_main.sass +11 -0
- data/app/assets/stylesheets/rademade_admin/blocks/page/headline/main.sass +44 -0
- data/app/assets/stylesheets/rademade_admin/blocks/page/menu/_main.sass +31 -0
- data/app/assets/stylesheets/rademade_admin/lib/datepicker.sass +373 -0
- data/app/assets/stylesheets/rademade_admin/lib/glyphicon.sass.erb +618 -0
- data/app/assets/stylesheets/rademade_admin/lib/notifier.css.erb +661 -0
- data/app/assets/stylesheets/rademade_admin/lib/uploader.sass +66 -0
- data/app/assets/stylesheets/rademade_admin/mixins/clear.sass +5 -0
- data/app/assets/stylesheets/rademade_admin/mixins/fonts.sass +8 -0
- data/app/assets/stylesheets/rademade_admin/mixins/sprite.sass +7 -0
- data/app/assets/stylesheets/rademade_admin/mixins/text-overflow.sass +6 -0
- data/app/assets/stylesheets/rademade_admin/mixins/user-select.sass +5 -0
- data/app/assets/stylesheets/rademade_admin/modules/breadcrumbs/main.sass +30 -0
- data/app/assets/stylesheets/rademade_admin/modules/errors/error.sass.erb +19 -0
- data/app/assets/stylesheets/rademade_admin/modules/form/main.sass +15 -0
- data/app/assets/stylesheets/rademade_admin/modules/header/main.sass +6 -0
- data/app/assets/stylesheets/rademade_admin/modules/login/_main.sass +79 -0
- data/app/assets/stylesheets/rademade_admin/modules/main-menu/main.sass +0 -0
- data/app/assets/stylesheets/rademade_admin/modules/page/main.sass +16 -0
- data/app/assets/stylesheets/rademade_admin/modules/pagination/main.sass +51 -0
- data/app/assets/stylesheets/rademade_admin/modules/popup/new.sass +18 -0
- data/app/assets/stylesheets/rademade_admin/var/colors.sass +0 -0
- data/app/assets/stylesheets/rademade_admin/var/images.sass +2 -0
- data/app/assets/stylesheets/rademade_admin/var/width.sass +13 -0
- data/app/controllers/rademade_admin/abstract_controller.rb +18 -2
- data/app/controllers/rademade_admin/application_controller.rb +1 -1
- data/app/controllers/rademade_admin/dashboard_controller.rb +1 -1
- data/app/controllers/rademade_admin/file_controller.rb +25 -0
- data/app/controllers/rademade_admin/model_controller.rb +66 -47
- data/app/controllers/rademade_admin/sessions_controller.rb +3 -3
- data/app/helpers/rademade_admin/field_helper.rb +21 -32
- data/app/helpers/rademade_admin/form_helper.rb +57 -27
- data/app/helpers/rademade_admin/menu_helper.rb +12 -5
- data/app/helpers/rademade_admin/uri_helper.rb +50 -62
- data/app/inputs/rademade_admin/date_time_input.rb +13 -0
- data/app/inputs/rademade_admin/file_input.rb +72 -0
- data/app/inputs/rademade_admin/related_select_input.rb +78 -0
- data/app/serializers/autocomplete/link_serializer.rb +6 -4
- data/app/services/linker.rb +8 -14
- data/app/services/login.rb +5 -3
- data/app/services/model_controller/breadcrumbs.rb +36 -0
- data/app/services/model_controller/instance_options.rb +7 -5
- data/app/services/model_controller/model_options.rb +10 -7
- data/app/services/model_controller/notifier.rb +10 -6
- data/app/services/model_controller/templates.rb +4 -3
- data/app/services/relation_service.rb +11 -0
- data/app/services/saver.rb +59 -24
- data/app/services/search/conditions/abstract.rb +15 -14
- data/app/services/search/conditions/autocomplete.rb +11 -9
- data/app/services/search/conditions/list.rb +6 -5
- data/app/services/search/conditions/related_list.rb +17 -13
- data/app/services/search/{conditions/part/where.rb → part/abstract.rb} +7 -9
- data/app/services/search/part/order.rb +17 -0
- data/app/services/search/part/where.rb +19 -0
- data/app/services/sortable_service.rb +27 -27
- data/app/services/template_service.rb +68 -0
- data/app/services/upload/preview_service.rb +86 -0
- data/app/views/layouts/rademade_admin.html.erb +13 -4
- data/app/views/rademade_admin/_blocks/_header.html.erb +35 -28
- data/app/views/rademade_admin/_blocks/_menu.html.erb +20 -23
- data/app/views/rademade_admin/_blocks/_on_page_select.html.erb +15 -0
- data/app/views/rademade_admin/_blocks/_pagination.html.erb +1 -18
- data/app/views/rademade_admin/_blocks/_sub_menu.html.erb +3 -3
- data/app/views/rademade_admin/_blocks/form/_control.html.erb +3 -0
- data/app/views/rademade_admin/_blocks/form/_lang_panel.html.erb +19 -0
- data/app/views/rademade_admin/_blocks/sub_menu/_link.html.erb +6 -5
- data/app/views/rademade_admin/_blocks/table/_head.html.erb +13 -0
- data/app/views/rademade_admin/_layouts/inner.html.erb +21 -33
- data/app/views/rademade_admin/_layouts/inner/form.html.erb +6 -13
- data/app/views/rademade_admin/_layouts/inner/index_table.html.erb +31 -55
- data/app/views/rademade_admin/_layouts/inner/related_index_table.html.erb +26 -54
- data/app/views/rademade_admin/abstract/_form.html.erb +6 -9
- data/app/views/rademade_admin/abstract/edit.html.erb +3 -8
- data/app/views/rademade_admin/abstract/index.html.erb +38 -67
- data/app/views/rademade_admin/abstract/new.html.erb +3 -8
- data/app/views/rademade_admin/abstract/related.html.erb +48 -0
- data/app/views/rademade_admin/dashboard/index.html.erb +4 -5
- data/app/views/rademade_admin/dashboard/login.html.erb +19 -30
- data/config/initializers/carrier_wave/mongoid.rb +48 -0
- data/config/initializers/ckeditor.rb +3 -0
- data/config/initializers/kaminari_route_proxy.rb +16 -0
- data/config/initializers/simple_form.rb +147 -0
- data/config/initializers/simple_form/rademade_component.rb +9 -0
- data/config/initializers/simple_form/wrappers.rb +28 -0
- data/config/locales/rademade_admin.en.yml +28 -0
- data/config/locales/simple_form.en.yml +26 -0
- data/config/routes.rb +1 -2
- data/lib/rademade_admin.rb +7 -5
- data/lib/rademade_admin/bower/performer.rb +1 -1
- data/lib/rademade_admin/breadcrumbs/render/rademade.rb +31 -0
- data/lib/rademade_admin/engine.rb +2 -2
- data/lib/rademade_admin/input/related_select_input/model_data.rb +40 -0
- data/lib/rademade_admin/input/related_select_input/related_list.rb +60 -0
- data/lib/rademade_admin/model/adapter/data.rb +119 -0
- data/lib/rademade_admin/model/adapter/data/active_record.rb +109 -0
- data/lib/rademade_admin/model/adapter/data/mongoid.rb +77 -0
- data/{app/services/search/query_adapter/abstract.rb → lib/rademade_admin/model/adapter/query.rb} +15 -5
- data/lib/rademade_admin/model/adapter/query/active_record.rb +50 -0
- data/lib/rademade_admin/model/adapter/query/mongoid.rb +57 -0
- data/lib/rademade_admin/model/configuration.rb +43 -16
- data/lib/rademade_admin/model/configuration/field_label.rb +16 -0
- data/lib/rademade_admin/model/configuration/fields.rb +47 -21
- data/lib/rademade_admin/model/configuration/fields_labels.rb +31 -0
- data/lib/rademade_admin/model/configuration/form_field.rb +27 -0
- data/lib/rademade_admin/model/configuration/form_fields.rb +18 -0
- data/lib/rademade_admin/model/configuration/list_field.rb +21 -0
- data/lib/rademade_admin/model/configuration/list_fields.rb +18 -0
- data/lib/rademade_admin/model/graph.rb +9 -9
- data/lib/rademade_admin/model/info.rb +53 -68
- data/lib/rademade_admin/model/info/data_item.rb +130 -0
- data/lib/rademade_admin/model/info/data_items.rb +130 -0
- data/lib/rademade_admin/model/info/field.rb +39 -0
- data/lib/rademade_admin/model/info/fields.rb +87 -0
- data/lib/rademade_admin/model/info/relation.rb +49 -0
- data/lib/rademade_admin/model/info/relations.rb +40 -0
- data/lib/rademade_admin/model/info/uploader.rb +16 -0
- data/lib/rademade_admin/model/info/uploaders.rb +35 -0
- data/lib/rademade_admin/model/reflection.rb +38 -9
- data/lib/rademade_admin/routing/mapper.rb +9 -5
- data/lib/rademade_admin/search/searcher.rb +22 -0
- data/lib/rademade_admin/sortable.rb +1 -0
- data/lib/rademade_admin/uploader/photo.rb +1 -0
- data/lib/rademade_admin/user.rb +7 -6
- data/lib/rademade_admin/version.rb +1 -1
- data/lib/tasks/rademade_bower_install.rake +10 -2
- data/lib/templates/erb/scaffold/_form.html.erb +13 -0
- metadata +195 -109
- data/app/assets/javascripts/rademade_admin/app/common/relation-list.coffee +0 -109
- data/app/assets/javascripts/rademade_admin/app/form-popup/collection.coffee +0 -20
- data/app/assets/javascripts/rademade_admin/app/form-popup/model.coffee +0 -4
- data/app/assets/javascripts/rademade_admin/detail_admin/theme.js +0 -56
- data/app/assets/javascripts/rademade_admin/form/form-ajax-submit.coffee +0 -157
- data/app/assets/stylesheets/rademade_admin.scss.erb +0 -19
- data/app/helpers/rademade_admin/name_helper.rb +0 -18
- data/app/helpers/rademade_admin/upload_preview_helper.rb +0 -60
- data/app/inputs/rademade_admin/admin_file_input.rb +0 -71
- data/app/inputs/rademade_admin/admin_select_input.rb +0 -82
- data/app/inputs/rademade_admin/admin_textarea_input.rb +0 -6
- data/app/inputs/rademade_admin/boolean_input.rb +0 -14
- data/app/services/form_builder.rb +0 -4
- data/app/services/search/query_adapter/active_record.rb +0 -45
- data/app/services/search/query_adapter/mongoid.rb +0 -51
- data/app/services/search/searcher.rb +0 -20
- data/app/views/rademade_admin/_blocks/_form_control.html.erb +0 -5
- data/app/views/rademade_admin/abstract/related_index.html.erb +0 -85
- data/config/initializers/devise.rb +0 -251
- data/config/initializers/formtastic.rb +0 -13
- data/lib/rademade_admin/model/data_adapter.rb +0 -64
- data/lib/rademade_admin/model/data_adapter/active_record.rb +0 -59
- data/lib/rademade_admin/model/data_adapter/mongoid.rb +0 -54
- data/lib/rademade_admin/model/reflection/data.rb +0 -48
- data/lib/rademade_admin/model/reflection/uploader.rb +0 -18
@@ -17,7 +17,7 @@ initUploader = ->
|
|
17
17
|
bindFileUploader::uploadError = () ->
|
18
18
|
@_hideUploader()
|
19
19
|
|
20
|
-
bindFileUploader::updateUploadProggress = (data) ->
|
20
|
+
bindFileUploader::updateUploadProggress = (e, data) ->
|
21
21
|
progress = parseInt(data.loaded / data.total * 100, 10)
|
22
22
|
@_setUploadProgress(progress)
|
23
23
|
|
@@ -31,8 +31,8 @@ initUploader = ->
|
|
31
31
|
@$wrapper.find('.upload-progress').width(progress + '%')
|
32
32
|
|
33
33
|
bindFileUploader::_appendUploadResult = (result)->
|
34
|
-
@$wrapper.find('.
|
35
|
-
@$wrapper.find('
|
34
|
+
@$wrapper.find('.preview-wrapper').replaceWith(result.html)
|
35
|
+
@$wrapper.find('input[type="hidden"]').val(result.file[@$el.data('column')].url)
|
36
36
|
|
37
37
|
bindFileUploader::init = () ->
|
38
38
|
#todo url take from dom
|
@@ -1,43 +1,30 @@
|
|
1
1
|
class @FormPopup.Initializer extends Backbone.View
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
initialize : () ->
|
10
|
-
@_popups = new FormPopup.Collection
|
11
|
-
|
12
|
-
onRelationAdd : (e) ->
|
13
|
-
e.preventDefault()
|
14
|
-
$button = $ e.currentTarget
|
15
|
-
@showPopup $button.data('class'), $button.data('new')
|
16
|
-
|
17
|
-
onRelationEdit : (e) ->
|
18
|
-
e.preventDefault()
|
19
|
-
$button = $ e.currentTarget
|
20
|
-
@showPopup $button.closest('.select-wrapper').data('rel-class'), $button.data('edit')
|
21
|
-
|
22
|
-
showPopup : (modelClassName, url) ->
|
23
|
-
popupModel = @_popups.getModelWithClass modelClassName
|
24
|
-
if popupModel
|
25
|
-
@_popups.showModel popupModel
|
26
|
-
else
|
27
|
-
@createPopup modelClassName, url
|
28
|
-
|
29
|
-
createPopup : (modelClassName, url) ->
|
30
|
-
popupModel = new FormPopup.Model
|
31
|
-
modelClassName : modelClassName
|
32
|
-
popupView = FormPopup.View.init popupModel, url
|
33
|
-
@_popups.add popupView.model
|
3
|
+
_popupViews : []
|
4
|
+
|
5
|
+
showPopup : (model) ->
|
6
|
+
popupView = FormPopup.View.init model
|
7
|
+
@addPopup popupView
|
34
8
|
@$el.append popupView.$el
|
35
9
|
|
36
|
-
|
10
|
+
addPopup : (popup) ->
|
11
|
+
popup.on 'close', @_onPopupClose
|
12
|
+
@_last().hide() if @_hasPopups()
|
13
|
+
@_popupViews.push popup
|
14
|
+
|
15
|
+
_onPopupClose : () =>
|
16
|
+
@_popupViews.pop()
|
17
|
+
@_last().show() if @_hasPopups()
|
18
|
+
|
19
|
+
_last : () ->
|
20
|
+
_.last @_popupViews
|
21
|
+
|
22
|
+
_hasPopups : () ->
|
23
|
+
@_popupViews.length > 0
|
37
24
|
|
38
|
-
$(document).on 'ready page:load', () =>
|
39
|
-
formPopup = new @FormPopup.Initializer
|
40
|
-
el : document.getElementById 'pad-wrapper'
|
41
25
|
|
42
|
-
|
43
|
-
|
26
|
+
@getInstance : () ->
|
27
|
+
instance = null
|
28
|
+
do () ->
|
29
|
+
instance ||= new @FormPopup.Initializer
|
30
|
+
el : document.getElementById 'pad-wrapper'
|
@@ -3,29 +3,38 @@ class @FormPopup.View extends Backbone.View
|
|
3
3
|
className : 'add_new_popup soft-hide'
|
4
4
|
|
5
5
|
events :
|
6
|
-
'click
|
7
|
-
|
8
|
-
initialize : () ->
|
9
|
-
@model.on 'show', () =>
|
10
|
-
@$el.show()
|
11
|
-
@model.on 'hide', () =>
|
12
|
-
@$el.hide()
|
6
|
+
'click' : 'onClick'
|
7
|
+
'click .cancel-btn' : 'onReset'
|
13
8
|
|
14
9
|
onReset : (e) ->
|
15
10
|
e.preventDefault()
|
16
11
|
@closePopup()
|
17
12
|
|
13
|
+
onClick : (e) ->
|
14
|
+
@closePopup() if $(e.target).closest('.simple_form').length is 0
|
15
|
+
|
16
|
+
show : () =>
|
17
|
+
@$el.show()
|
18
|
+
@_updatePosition()
|
19
|
+
|
20
|
+
hide : () ->
|
21
|
+
@$el.hide()
|
22
|
+
|
18
23
|
closePopup : () ->
|
19
|
-
@
|
24
|
+
@trigger 'close'
|
20
25
|
@undelegateEvents()
|
21
26
|
@$el.remove()
|
22
27
|
|
23
28
|
renderFromUrl : (url) ->
|
24
29
|
$.get url, (html) =>
|
25
30
|
@$el.html html
|
31
|
+
@_updatePosition()
|
26
32
|
@delegateEvents()
|
27
33
|
@_init()
|
28
34
|
|
35
|
+
render : () ->
|
36
|
+
@renderFromUrl @model.get('edit_url')
|
37
|
+
|
29
38
|
_init : () ->
|
30
39
|
$form = @$el.find 'form'
|
31
40
|
if $form.length > 0
|
@@ -36,22 +45,27 @@ class @FormPopup.View extends Backbone.View
|
|
36
45
|
|
37
46
|
_initPlugins : () ->
|
38
47
|
$(document)
|
39
|
-
.trigger('init-select')
|
40
48
|
.trigger('init-uploader')
|
49
|
+
.trigger('init-lang-panel')
|
50
|
+
.trigger('init-plugins') # todo move all custom inits to init-plugins
|
51
|
+
Select2Input.View.initAll @$el
|
41
52
|
|
42
53
|
_initForm : ($form) ->
|
43
|
-
|
44
|
-
$form.on 'ajax-submit-done', (e,
|
45
|
-
|
54
|
+
Form.init $form
|
55
|
+
$form.on 'ajax-submit-done', (e, response) =>
|
56
|
+
@model.update response.data
|
46
57
|
@closePopup()
|
47
58
|
|
48
59
|
_bindButton : () ->
|
49
60
|
@$el.find('button').click (e) =>
|
50
|
-
@
|
61
|
+
@model.set 'edit_url', $(e.currentTarget).data('new')
|
62
|
+
@render()
|
51
63
|
|
64
|
+
_updatePosition : () ->
|
65
|
+
@$el.css top : "#{window.pageYOffset}px"
|
52
66
|
|
53
|
-
@
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
67
|
+
@init : (model) ->
|
68
|
+
popupView = new FormPopup.View
|
69
|
+
model : model
|
70
|
+
popupView.render()
|
71
|
+
popupView
|
@@ -1,6 +1,7 @@
|
|
1
1
|
$(document).on 'ready page:load', ->
|
2
2
|
|
3
3
|
$('.delete-item-form').on
|
4
|
-
'ajax-before-submit': (event, submitStart) ->
|
5
|
-
|
6
|
-
|
4
|
+
'ajax-before-submit' : (event, submitStart) ->
|
5
|
+
submitStart() if confirm I18n.t('rademade_admin.record_remove_confirm')
|
6
|
+
'ajax-submit-done' : ->
|
7
|
+
$(this).closest('tr').fadeOut 300
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class @Select2Input.RelatedCollectionView extends Backbone.View
|
2
|
+
|
3
|
+
initialize : (options) ->
|
4
|
+
@collection.on 'add', @appendRelatedView
|
5
|
+
@_views = options.views
|
6
|
+
|
7
|
+
appendRelatedView : (model) =>
|
8
|
+
view = new Select2Input.RelatedView
|
9
|
+
model : model
|
10
|
+
@$el.append view.render().$el
|
11
|
+
@_views.push view
|
12
|
+
|
13
|
+
initSort : () ->
|
14
|
+
@$el.disableSelection()
|
15
|
+
if @$el.data('sortable')
|
16
|
+
@$el.sortable
|
17
|
+
stop : () =>
|
18
|
+
$children = @$el.children()
|
19
|
+
_.each @_views, (view) =>
|
20
|
+
view.model.set 'position', $children.index(view.$el) + 1
|
21
|
+
@collection.resort()
|
22
|
+
|
23
|
+
@init : ($list) ->
|
24
|
+
views = []
|
25
|
+
collection = new Select2Input.RelatedCollection
|
26
|
+
$list.find('li').each () ->
|
27
|
+
relatedView = Select2Input.RelatedView.init $(this)
|
28
|
+
views.push relatedView
|
29
|
+
collection.add relatedView.model
|
30
|
+
collectionView = new this
|
31
|
+
collection : collection
|
32
|
+
el : $list
|
33
|
+
views : views
|
34
|
+
collectionView.initSort()
|
35
|
+
collectionView
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class @Select2Input.RelatedCollection extends Backbone.Collection
|
2
|
+
|
3
|
+
comparator : 'position'
|
4
|
+
|
5
|
+
initialize : () ->
|
6
|
+
@on 'add', @addPosition
|
7
|
+
@on 'relation-remove', @removeFromCollection
|
8
|
+
|
9
|
+
addPosition : (model) ->
|
10
|
+
model.set 'position', @length
|
11
|
+
|
12
|
+
removeFromCollection : (model) =>
|
13
|
+
@remove model
|
14
|
+
@_triggerChange()
|
15
|
+
|
16
|
+
resort : () ->
|
17
|
+
@sort()
|
18
|
+
@_triggerChange()
|
19
|
+
|
20
|
+
update : (data) ->
|
21
|
+
@add new Select2Input.RelatedModel(data), merge : true
|
22
|
+
@_triggerChange()
|
23
|
+
|
24
|
+
getData : () ->
|
25
|
+
@map (model) -> model.getData()
|
26
|
+
|
27
|
+
_triggerChange : () ->
|
28
|
+
@trigger 'data-change'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class @Select2Input.RelatedModel extends Backbone.Model
|
2
|
+
|
3
|
+
relationRemove : () ->
|
4
|
+
@trigger 'relation-remove', this
|
5
|
+
|
6
|
+
# todo mixin
|
7
|
+
update : (data) ->
|
8
|
+
@set data
|
9
|
+
@_triggerChange()
|
10
|
+
|
11
|
+
getData : () ->
|
12
|
+
@attributes
|
13
|
+
|
14
|
+
_triggerChange : () ->
|
15
|
+
@trigger 'data-change'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class @Select2Input.RelatedView extends Backbone.View
|
2
|
+
|
3
|
+
tagName : 'li'
|
4
|
+
|
5
|
+
events :
|
6
|
+
'click [data-edit]' : 'editRelation'
|
7
|
+
'click [data-remove]' : 'removeRelation'
|
8
|
+
|
9
|
+
initialize : () ->
|
10
|
+
@model.on 'relation-remove', @remove, this
|
11
|
+
@model.on 'change', @render, this
|
12
|
+
|
13
|
+
editRelation : (e) ->
|
14
|
+
e.preventDefault()
|
15
|
+
FormPopup.Initializer.getInstance().showPopup @model
|
16
|
+
|
17
|
+
removeRelation : (e) ->
|
18
|
+
e.preventDefault()
|
19
|
+
@model.relationRemove() if confirm I18n.t('rademade_admin.model_remove_confirm')
|
20
|
+
false
|
21
|
+
|
22
|
+
render : () ->
|
23
|
+
@$el.html @_getTemplateHtml()
|
24
|
+
return this
|
25
|
+
|
26
|
+
_getTemplateHtml : () ->
|
27
|
+
"""
|
28
|
+
<span>#{@model.get('text')}</span>
|
29
|
+
<button data-edit="#{@model.get('edit_url')}">Edit</button>
|
30
|
+
<button data-remove>Delete</button>
|
31
|
+
"""
|
32
|
+
|
33
|
+
@init : ($el) ->
|
34
|
+
model = new Select2Input.RelatedModel
|
35
|
+
id : $el.data('id')
|
36
|
+
text : $el.find('span').text()
|
37
|
+
edit_url : $el.find('[data-edit]').data('edit')
|
38
|
+
new this
|
39
|
+
el : $el
|
40
|
+
model : model
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class @Select2Input.View extends Backbone.View
|
2
|
+
|
3
|
+
events :
|
4
|
+
'click [data-new]' : 'addRelation'
|
5
|
+
|
6
|
+
initItem : () ->
|
7
|
+
@$item = @$el.find('.select-wrapper input[type="hidden"]')
|
8
|
+
@initModel()
|
9
|
+
@initRelated()
|
10
|
+
@initSelect2()
|
11
|
+
|
12
|
+
initModel : () ->
|
13
|
+
@model.set
|
14
|
+
searchUrl : @$item.data('searchUrl')
|
15
|
+
multiple : @$item.data('relMultiple')
|
16
|
+
|
17
|
+
initRelated : () ->
|
18
|
+
if @model.isMultiple()
|
19
|
+
collectionView = Select2Input.RelatedCollectionView.init @$el.find('.select2-items-list')
|
20
|
+
@model.set 'related', collectionView.collection
|
21
|
+
else
|
22
|
+
relatedData = @$el.children('input[type="hidden"]').data()
|
23
|
+
@model.set 'related', new Select2Input.RelatedModel relatedData
|
24
|
+
|
25
|
+
initSelect2 : () ->
|
26
|
+
@$item.select2(
|
27
|
+
multiple : @model.isMultiple()
|
28
|
+
placeholder : I18n.t('rademade_admin.enter_search')
|
29
|
+
allowClear : true
|
30
|
+
ajax :
|
31
|
+
url : @model.get('searchUrl')
|
32
|
+
dataType : 'json'
|
33
|
+
data : (term) -> { q : term }
|
34
|
+
results : (data) -> { results : data }
|
35
|
+
).unbind('change').bind 'change', (e) =>
|
36
|
+
@model.get('related').update(e.added) if e.added
|
37
|
+
@_updateData()
|
38
|
+
@model.get('related').on 'data-change', @_updateData
|
39
|
+
|
40
|
+
addRelation : (e) ->
|
41
|
+
e.preventDefault()
|
42
|
+
relatedModel = @_createRelatedModel $(e.currentTarget).data('new')
|
43
|
+
FormPopup.Initializer.getInstance().showPopup relatedModel
|
44
|
+
|
45
|
+
_createRelatedModel : (url) ->
|
46
|
+
relatedModel = @_relatedModel url
|
47
|
+
relatedModel.on 'data-change', () =>
|
48
|
+
@model.get('related').add(relatedModel) if @model.isMultiple()
|
49
|
+
@_updateData()
|
50
|
+
relatedModel
|
51
|
+
|
52
|
+
_updateData : () =>
|
53
|
+
relatedData = @model.getRelatedData()
|
54
|
+
if @model.isMultiple() or not _.isEmpty(relatedData)
|
55
|
+
@$item.select2('data', relatedData)
|
56
|
+
|
57
|
+
_relatedModel : (url) ->
|
58
|
+
if @model.isMultiple()
|
59
|
+
relatedModel = new Select2Input.RelatedModel
|
60
|
+
else
|
61
|
+
relatedModel = @model.get('related')
|
62
|
+
relatedModel.set 'edit_url', url
|
63
|
+
relatedModel
|
64
|
+
|
65
|
+
@init : ($el) ->
|
66
|
+
view = new this
|
67
|
+
model : new Select2Input.Model
|
68
|
+
el : $el
|
69
|
+
view.initItem()
|
70
|
+
view
|
71
|
+
|
72
|
+
@initAll : (within) ->
|
73
|
+
$('.input-holder:has(.select-wrapper)', within).each (index, select) =>
|
74
|
+
Select2Input.View.init $(select)
|
75
|
+
|
76
|
+
$ ->
|
77
|
+
$(document).on 'ready page:load', () ->
|
78
|
+
Select2Input.View.initAll()
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class @FormAjax extends Backbone.View
|
2
|
+
|
3
|
+
submitHandler : () ->
|
4
|
+
@_prepareForAjax()
|
5
|
+
$.ajax(
|
6
|
+
url : @$el.attr('action')
|
7
|
+
type : @$el.attr('method')
|
8
|
+
data : @_getData()
|
9
|
+
dataType : 'json'
|
10
|
+
).done(@_onDone).fail(@_onFail).always(@_onAlways)
|
11
|
+
|
12
|
+
_prepareForAjax : () ->
|
13
|
+
@trigger 'ajax-start'
|
14
|
+
for instance of CKEDITOR.instances
|
15
|
+
CKEDITOR.instances[instance].updateElement()
|
16
|
+
|
17
|
+
_onDone : (data) =>
|
18
|
+
@trigger 'ajax-done', data
|
19
|
+
@$el.find('.error-message').remove()
|
20
|
+
|
21
|
+
_onFail : (response) =>
|
22
|
+
try
|
23
|
+
@trigger 'ajax-fail', JSON.parse(response.responseText)
|
24
|
+
|
25
|
+
_onAlways : (response) =>
|
26
|
+
data = if (response.responseJSON) then response.responseJSON else response
|
27
|
+
window.notifier.notify(data.message) if data.message
|
28
|
+
@trigger 'ajax-finish', data
|
29
|
+
|
30
|
+
_getData : () ->
|
31
|
+
items = @$el.serializeObject()
|
32
|
+
|
33
|
+
for memb of items.data
|
34
|
+
array = items.data[memb]
|
35
|
+
items.data[memb] = @_cleanArray(array) if $.isArray(array)
|
36
|
+
|
37
|
+
inputMethod = @$el.find('input[name="_method"]')
|
38
|
+
items['_method'] = inputMethod.val() if inputMethod instanceof jQuery
|
39
|
+
|
40
|
+
items
|
41
|
+
|
42
|
+
_cleanArray : (array) ->
|
43
|
+
newArray = []
|
44
|
+
for val in array
|
45
|
+
cleanVal = val.replace(/\s+/g, '')
|
46
|
+
if cleanVal.length > 0
|
47
|
+
newArray = $.merge(newArray, cleanVal.split(','))
|
48
|
+
if newArray.length is 0 then [''] else newArray
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class @FormInitializer extends Backbone.View
|
2
|
+
|
3
|
+
initForms : () ->
|
4
|
+
$('form').each (i, form) ->
|
5
|
+
Form.init $(form)
|
6
|
+
|
7
|
+
setErrorsFormatting : () ->
|
8
|
+
$.validator.setDefaults
|
9
|
+
|
10
|
+
showErrors : (errorMap, errorList) =>
|
11
|
+
$.each errorList, (index, error) =>
|
12
|
+
$error = $(error.element)
|
13
|
+
@_clearErrors($error)
|
14
|
+
@_showErrorMessage($error, error)
|
15
|
+
|
16
|
+
_clearErrors : ($error) ->
|
17
|
+
$error.siblings('.error-message').remove()
|
18
|
+
|
19
|
+
_showErrorMessage : ($error, error) ->
|
20
|
+
$error.after @_getErrorNotifier(error)
|
21
|
+
|
22
|
+
_getErrorMessage : (error) ->
|
23
|
+
if $.isArray(error.message)
|
24
|
+
error.message.join('<br>')
|
25
|
+
else
|
26
|
+
error.message
|
27
|
+
|
28
|
+
_getErrorNotifier : (message) ->
|
29
|
+
$([
|
30
|
+
'<span class="error-message">'
|
31
|
+
@_getErrorMessage(message)
|
32
|
+
'<i class="ico error-buble"></i>'
|
33
|
+
'</span>'
|
34
|
+
].join(''))
|
35
|
+
|
36
|
+
|
37
|
+
FormInitializer.init = () ->
|
38
|
+
formInitializer = new FormInitializer()
|
39
|
+
formInitializer.setErrorsFormatting()
|
40
|
+
formInitializer.initForms()
|
41
|
+
formInitializer
|
42
|
+
|
43
|
+
|
44
|
+
$ ->
|
45
|
+
$(document).on 'ready page:load', FormInitializer.init
|