comable_backend 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/comable/admin/application.coffee +53 -99
  3. data/app/assets/javascripts/comable/admin/categories.coffee +59 -0
  4. data/app/assets/javascripts/comable/admin/dashboard.coffee +32 -0
  5. data/app/assets/javascripts/comable/admin/dispatcher.coffee +21 -0
  6. data/app/assets/javascripts/comable/admin/orders.coffee +44 -0
  7. data/app/assets/javascripts/comable/admin/pages.coffee +69 -0
  8. data/app/assets/javascripts/comable/admin/products.coffee +21 -0
  9. data/app/assets/javascripts/comable/admin/search.coffee +35 -0
  10. data/app/assets/javascripts/comable/admin/themes.coffee +64 -0
  11. data/app/assets/stylesheets/comable/admin/_common.scss +1 -163
  12. data/app/assets/stylesheets/comable/admin/_overrides.scss +1 -0
  13. data/app/assets/stylesheets/comable/admin/_pages.scss +30 -0
  14. data/app/assets/stylesheets/comable/admin/_themes.scss +71 -0
  15. data/app/assets/stylesheets/comable/admin/_user_sessions.scss +4 -4
  16. data/app/assets/stylesheets/comable/admin/_variables.scss +16 -19
  17. data/app/assets/stylesheets/comable/admin/application.scss +6 -1
  18. data/app/assets/stylesheets/comable/admin/overrides/awesome_admin_layout.scss +25 -0
  19. data/app/assets/stylesheets/comable/admin/overrides/bootstrap.scss +5 -12
  20. data/app/controllers/comable/admin/orders_controller.rb +5 -1
  21. data/app/controllers/comable/admin/pages_controller.rb +72 -0
  22. data/app/controllers/comable/admin/themes_controller.rb +101 -0
  23. data/app/controllers/comable/admin/user_sessions_controller.rb +1 -0
  24. data/app/controllers/comable/admin/users_controller.rb +5 -0
  25. data/app/helpers/comable/admin/application_helper.rb +4 -4
  26. data/app/helpers/comable/admin/pages_helper.rb +6 -0
  27. data/app/helpers/comable/admin/themes_helper.rb +69 -0
  28. data/app/views/comable/admin/categories/index.slim +1 -52
  29. data/app/views/comable/admin/dashboard/show.slim +3 -23
  30. data/app/views/comable/admin/orders/_google_map.slim +26 -9
  31. data/app/views/comable/admin/orders/edit.slim +62 -4
  32. data/app/views/comable/admin/pages/_form.slim +69 -0
  33. data/app/views/comable/admin/pages/edit.slim +31 -0
  34. data/app/views/comable/admin/pages/index.slim +55 -0
  35. data/app/views/comable/admin/pages/new.slim +16 -0
  36. data/app/views/comable/admin/products/_form.slim +0 -16
  37. data/app/views/comable/admin/shared/_advanced_search.slim +0 -1
  38. data/app/views/comable/admin/shared/_notifier.slim +2 -2
  39. data/app/views/comable/admin/themes/_editor.slim +8 -0
  40. data/app/views/comable/admin/themes/_form.slim +31 -0
  41. data/app/views/comable/admin/themes/edit.slim +35 -0
  42. data/app/views/comable/admin/themes/index.slim +37 -0
  43. data/app/views/comable/admin/themes/new.slim +16 -0
  44. data/app/views/comable/admin/themes/show_file.slim +93 -0
  45. data/app/views/layouts/comable/admin/application.slim +19 -11
  46. data/config/initializers/awesome_admin_layout.rb +110 -0
  47. data/config/routes.rb +13 -0
  48. data/lib/comable/backend/engine.rb +8 -1
  49. metadata +117 -11
  50. data/app/assets/javascripts/comable/admin/products.js +0 -2
  51. data/app/views/comable/admin/shared/_header.slim +0 -31
  52. data/app/views/comable/admin/shared/_setup_search_form.slim +0 -14
  53. data/app/views/comable/admin/shared/_sidebar.slim +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76ffc0c5bdb8d0ae0bc2883bbd4229e3e461ebbf
4
- data.tar.gz: 8997356a6594946a0d5098faedb16321a0b79516
3
+ metadata.gz: 9bdd2edb034308a6bc812f4a06109a26bee2ff8c
4
+ data.tar.gz: 948e6c9193232ec37d4f67b460b6532b6a541e83
5
5
  SHA512:
6
- metadata.gz: 78992e36428c8afafee468b37d8f2ea8931ca2fc1f573e29209a622c9f776f56f5094e6f4d39b1299482a0f820fdcb288a70b4abb8dc125bd3d136df6fb9e08a
7
- data.tar.gz: a68ef71f0aeccb6b228740c6e48a6e668d449aa93173d80149899d10fed731344395cf1401778e13c12e2a3d5fbbc239bb411f39c2b00f415b158f7e86680281
6
+ metadata.gz: ad23074515a6cdf440643c06dee046d1bd563b2dbc1765ed9104158a744a7fdfb2a571263749e4c68c11de62dc4edcddf8cfed1908142da70bc05718dccaf950
7
+ data.tar.gz: 0e132b7df921b5c48df21dd10fd4ad5d26fb16bfd88b199322789da16d8e792ee2422e66c3eb55c062422752889a9f089c245d2f2a539a09155abe5fd971a9b8
@@ -1,122 +1,76 @@
1
1
  #= require jquery
2
+ #= require jquery.turbolinks
2
3
  #= require jquery_ujs
3
4
  #= require jquery-ui
4
5
  #= require bootstrap-sprockets
5
6
  #= require raphael
6
7
  #= require morris
7
- #= require pace/pace
8
+ #= require nprogress
9
+ #= require nprogress-turbolinks
8
10
  #= require gritter
11
+ #= require awesome_admin_layout
12
+ #= require ace/ace
13
+ #= require ace/worker-html
14
+ #= require ace/mode-liquid
15
+ #= require moment
16
+ #= require bootstrap-datetimepicker
17
+ #= require comable/admin/dispatcher
9
18
  #= require_tree .
19
+ #= require_self
20
+ #= require turbolinks
10
21
 
11
- $( ->
12
- # ---
13
- # functions
14
- # ---
22
+ # ---
23
+ # variables
24
+ # ---
15
25
 
16
- initialize_beforeunload_event = ->
17
- $form = $('form[method!="get"]')
18
- $form.change(->
19
- $(window).on('beforeunload', (event) ->
20
- # TODO: Install 'i18n-js' gem
21
- confirmation_message = 'The changes not saved. Are you sure you want to move from this page?'
22
- (event || window.event).returnValue = confirmation_message # for Gecko and Trident
23
- confirmation_message # for Gecko and WebKit
24
- )
25
- )
26
- $form.submit(->
27
- $(window).off('beforeunload')
28
- )
26
+ # TODO: Install 'i18n-js' gem
27
+ window.beforeunload_message = 'The changes not saved. Are you sure you want to move from this page?'
29
28
 
30
- initialize_vertical_navigation = ->
31
- $vnavigation = $('.vnavigation').find('ul')
29
+ # ---
30
+ # functions
31
+ # ---
32
32
 
33
- $('.vnavigation ul li ul').each( ->
34
- $target_navitem = $(this).parent()
35
- $target_navitem.addClass('parent')
33
+ add_beforeunload_event = ->
34
+ $form = $('form[method!="get"]')
35
+ $form.change(->
36
+ $(window).bind('beforeunload', ->
37
+ window.beforeunload_message
36
38
  )
37
-
38
- $('.vnavigation ul li ul li.active').each( ->
39
- $target_navitem_children = $(this).parent()
40
- $target_navitem_children.css(display: 'block')
41
- $target_navitem_children.parent().addClass('open')
39
+ $(document).on('page:before-change', ->
40
+ confirm(window.beforeunload_message)
42
41
  )
42
+ )
43
+ remove_beforeunload_function = ->
44
+ $(window).unbind('beforeunload')
45
+ $(document).off('page:before-change')
46
+ $form.submit(remove_beforeunload_function)
47
+ $(document).on('page:change', remove_beforeunload_function)
43
48
 
44
- $vnavigation.delegate('.parent > a', 'click', (event) ->
45
- $target_navitem = $(this).parent()
46
- $target_navitem_children = $target_navitem.find('ul')
47
-
48
- $vnavigation.find('.parent.open > ul').not($target_navitem_children).slideUp(300, 'swing', ->
49
- $target_navitem.removeClass('open')
50
- )
51
-
52
- $target_navitem_children.slideToggle(300, 'swing', ->
53
- $target_navitem.toggleClass('open')
54
- #$('#cl-wrapper .nscroller').nanoScroller(preventPageScrolling: true)
55
- )
56
-
57
- event.preventDefault()
58
- )
59
-
60
- initialize_comable_affix = ->
61
- $affix = $('#comable-affix')
62
- $affix_top = $affix.offset().top
63
- $affix.affix({
64
- offset: {
65
- top: ->
66
- if $affix.hasClass('affix-top')
67
- $affix_top - $('header').height() - 20
68
- else
69
- $affix_top
70
- }
71
- })
72
-
73
- resize_comable_affix = ->
74
- $affix = $('#comable-affix')
75
- $affix.css('width', $affix.parent().width())
76
-
77
- window.add_fields = (_this, association, content) ->
78
- new_id = new Date().getTime()
79
- regexp = new RegExp('new_' + association, 'g')
80
- $(_this).parent().before(content.replace(regexp, new_id))
81
-
82
- # ---
83
- # main
84
- # ---
85
-
86
- initialize_beforeunload_event()
87
- initialize_vertical_navigation()
49
+ window.add_fields = (_this, association, content) ->
50
+ new_id = new Date().getTime()
51
+ regexp = new RegExp('new_' + association, 'g')
52
+ $(_this).parent().before(content.replace(regexp, new_id))
88
53
 
89
- if $('#comable-affix').length != 0
90
- initialize_comable_affix()
91
- resize_comable_affix()
92
- $(window).on('resize', resize_comable_affix)
54
+ # ---
55
+ # main
56
+ # ---
93
57
 
94
- $('[data-toggle="tooltip"]').tooltip()
58
+ $(document).ready(->
59
+ add_beforeunload_event()
95
60
 
96
- $(document).on('change', '.btn-file :file', ->
61
+ $('.btn-file :file').change(->
97
62
  $(this).closest('form').submit()
98
63
  )
99
- )
100
- # Place all the behaviors and hooks related to the matching controller here.
101
- # All this logic will automatically be available in application.js.
102
- # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
103
- class @Search
104
- constructor: (@templates = {}) ->
105
64
 
106
- remove_fields: (button) ->
107
- $(button).closest('.fields').remove()
65
+ # datetimepicker setting
66
+ $('.datetimepicker').datetimepicker(format: 'YYYY-MM-DD HH:mm')
108
67
 
109
- add_fields: (button, type, content) ->
110
- new_id = new Date().getTime()
111
- regexp = new RegExp('new_' + type, 'g')
112
- $(button).before(content.replace(regexp, new_id))
68
+ $('[data-toggle="tooltip"]').tooltip()
69
+ )
113
70
 
114
- nest_fields: (button, type) ->
115
- new_id = new Date().getTime()
116
- id_regexp = new RegExp('new_' + type, 'g')
117
- template = @templates[type]
118
- object_name = $(button).closest('.fields').attr('data-object-name')
119
- sanitized_object_name = object_name.replace(/\]\[|[^-a-zA-Z0-9:.]/g, '_').replace(/_$/, '')
120
- template = template.replace(/new_object_name\[/g, object_name + "[")
121
- template = template.replace(/new_object_name_/, sanitized_object_name + '_')
122
- $(button).before(template.replace(id_regexp, new_id))
71
+ NProgress.configure(
72
+ showSpinner: false,
73
+ ease: 'ease',
74
+ speed: 500,
75
+ parent: '#wrapper'
76
+ )
@@ -0,0 +1,59 @@
1
+ window.add_comable_jstree_node = ($node = '#') ->
2
+ jstree = $('#comable-jstree').jstree(true)
3
+ new_node = jstree.create_node($node)
4
+ jstree.open_node($node) unless jstree.is_open($node)
5
+ jstree.rename_node(new_node, comable_new_node_label)
6
+ jstree.set_icon(new_node, 'fa fa-bars')
7
+
8
+ can_comable_jstree = ->
9
+ return false unless comable_jstree_json?
10
+ return false unless comable_new_node_label?
11
+ return false unless comable_action_new?
12
+ return false unless comable_action_edit?
13
+ return false unless comable_action_destroy?
14
+ return false unless comable_destroied_nodes?
15
+ return false unless $('#comable-jstree').length
16
+ true
17
+
18
+ initializa_comable_jstree = ->
19
+ return unless can_comable_jstree()
20
+
21
+ $comable_jstree = $('#comable-jstree')
22
+ $comable_jstree.jstree({
23
+ core: {
24
+ check_callback: true,
25
+ data: comable_jstree_json,
26
+ strings : { new_node: comable_new_node_label, icon: 'fa fa-bars' }
27
+ },
28
+ contextmenu: {
29
+ items: ($node) ->
30
+ _this = $comable_jstree.jstree(true)
31
+ {
32
+ create: {
33
+ label: comable_action_new,
34
+ action: -> create_new_node($node)
35
+ }
36
+ edit: {
37
+ label: comable_action_edit,
38
+ action: -> _this.edit($node)
39
+ }
40
+ destory: {
41
+ label: comable_action_destroy,
42
+ action: ->
43
+ comable_destroied_nodes.push { _destroy: $node.id }
44
+ _this.delete_node($node)
45
+ }
46
+ }
47
+ },
48
+ plugins: ['dnd', 'wholerow', 'contextmenu']
49
+ })
50
+
51
+ $('form').submit(->
52
+ json = $comable_jstree.jstree(true).get_json().concat(comable_destroied_nodes)
53
+ json_string = JSON.stringify(json)
54
+ $(this).find('#jstree_json').val(json_string)
55
+ )
56
+
57
+ $(document).ready(->
58
+ initializa_comable_jstree()
59
+ )
@@ -0,0 +1,32 @@
1
+ can_comable_tagit = ->
2
+ return false unless comable_morris_data?
3
+ return false unless comable_morris_keys?
4
+ return false unless comable_morris_labels?
5
+ return false unless $('#comable-morris').length
6
+ true
7
+
8
+ initializa_comable_morris = ->
9
+ return unless can_comable_tagit()
10
+
11
+ new Morris.Line({
12
+ # ID of the element in which to draw the chart.
13
+ element: 'comable-morris',
14
+ # Chart data records -- each entry in this array corresponds to a point on
15
+ # the chart.
16
+ data: comable_morris_data,
17
+ # The name of the data record attribute that contains x-values.
18
+ xkey: 'date',
19
+ # A list of names of data record attributes that contain y-values.
20
+ ykeys: comable_morris_keys,
21
+ # Labels for the ykeys -- will be displayed when you hover over the
22
+ # chart.
23
+ labels: comable_morris_labels,
24
+ xLabelAngle: 45,
25
+ xLabels: ['day'],
26
+ lineColors: ['#00acac', '#348fe2'],
27
+ hideHover: 'auto'
28
+ })
29
+
30
+ $(document).ready(->
31
+ initializa_comable_morris()
32
+ )
@@ -0,0 +1,21 @@
1
+ $(->
2
+ new Dispatcher
3
+ )
4
+
5
+ class Dispatcher
6
+ constructor: ->
7
+ @initialize_page_scripts()
8
+
9
+ initialize_page_scripts: ->
10
+ page = $('body').attr('data-page')
11
+ return false unless page
12
+
13
+ path = page.split(':')
14
+ contoller_name = path[0]
15
+ action_name = path[1]
16
+
17
+ switch page
18
+ when 'orders:edit'
19
+ new DynamicOrder
20
+ when 'pages:new', 'pages:show', 'pages:edit'
21
+ new Page
@@ -0,0 +1,44 @@
1
+ class @DynamicOrder
2
+ @refresh_trigger_attributes = ['price', 'quantity', 'payment_fee', 'shipment_fee']
3
+
4
+ constructor: (@options = {}) ->
5
+ @options['order_item_selector'] = '.comable-order-items' unless @options['order_item_selector']
6
+ @listen_events()
7
+
8
+ listen_events: ->
9
+ self = this
10
+ $('input').on('change', ->
11
+ attribute_name = $(this).attr('data-name')
12
+ return unless jQuery.inArray(attribute_name, self.refresh_trigger_attributes)
13
+ self.refresh_order_item_prices_for(this)
14
+ )
15
+
16
+ refresh_order_item_prices_for: (element) ->
17
+ $group = $(element).closest(@options['order_item_selector'])
18
+
19
+ $price = $group.find('[data-name="price"]')
20
+ $quantity = $group.find('[data-name="quantity"]')
21
+ $subtotal_price = $group.find('[data-name="subtotal_price"]')
22
+
23
+ price = Number($price.val())
24
+ quantity = Number($quantity.val())
25
+ $subtotal_price.val(price * quantity)
26
+
27
+ @refresh_order_prices()
28
+
29
+ refresh_order_prices: ->
30
+ item_total_price = 0
31
+ $('[data-name="subtotal_price"]').each( ->
32
+ item_total_price += Number($(this).val())
33
+ )
34
+
35
+ $item_total_price = $('[data-name="item_total_price"]')
36
+ $payment_fee = $('[data-name="payment_fee"]')
37
+ $shipment_fee = $('[data-name="shipment_fee"]')
38
+ $total_price = $('[data-name="total_price"]')
39
+
40
+ payment_fee = Number($payment_fee.val())
41
+ shipment_fee = Number($shipment_fee.val())
42
+
43
+ $item_total_price.val(item_total_price)
44
+ $total_price.val(item_total_price + payment_fee + shipment_fee)
@@ -0,0 +1,69 @@
1
+ class @Page
2
+ constructor: ->
3
+ $(document).ready(@ready)
4
+
5
+ ready: =>
6
+ @radio_published = $('#page_published_at_published')
7
+ @radio_unpublished = $('#page_published_at_unpublished')
8
+ @published_at = $('#page_published_at')
9
+
10
+ @initialize_visibility()
11
+ @add_event_to_set_visibility()
12
+ @add_event_to_set_page_title()
13
+ @add_event_to_set_meta_description()
14
+
15
+ # 公開/非公開の制御
16
+ initialize_visibility: ->
17
+ if @radio_published.is(':checked')
18
+ @published()
19
+ if @radio_unpublished.is(':checked')
20
+ @unpublished()
21
+
22
+ # 公開の際の制御
23
+ published: =>
24
+ @published_at.show()
25
+ @published_at.val(moment().format('YYYY-MM-DD HH:mm')) unless @published_at.val()
26
+
27
+ # 非公開の際の制御
28
+ unpublished: =>
29
+ @published_at.hide()
30
+ @published_at.val('')
31
+
32
+ add_event_to_set_visibility: ->
33
+ @radio_published.click(@published)
34
+ @radio_unpublished.click(@unpublished)
35
+
36
+ # 日付を空にされたら非公開にする
37
+ @published_at.blur( =>
38
+ @radio_unpublished.click() unless @published_at.val()
39
+ )
40
+
41
+ # ページタイトルの制御
42
+ add_event_to_set_page_title: ->
43
+ $title = $('#page_title')
44
+ $page_title = $('#page_page_title')
45
+
46
+ # タイトルを入力した時にページタイトルが空だったらタイトルの値を入れる
47
+ $title.blur( ->
48
+ $page_title.val($(this).val()) unless $page_title.val()
49
+ )
50
+
51
+ # ページタイトルが空にされたらタイトルの値を入れる
52
+ $page_title.blur( ->
53
+ $(this).val($title.val()) unless $(this).val()
54
+ )
55
+
56
+ # メタディスクリプションの制御
57
+ add_event_to_set_meta_description: ->
58
+ $content = $('#page_content')
59
+ $meta_description = $('#page_meta_description')
60
+
61
+ # 内容を入力した時にメタディスクリプションが空だったら内容の値を入れる
62
+ $content.blur( ->
63
+ $meta_description.val($($(this).val()).text()) unless $meta_description.val()
64
+ )
65
+
66
+ # メタディスクリプションが空にされたら内容の値を入れる
67
+ $meta_description.blur( ->
68
+ $(this).val($($content.val()).text()) unless $(this).val()
69
+ )
@@ -0,0 +1,21 @@
1
+ can_comable_tagit = ->
2
+ return false unless comable_tagit_available_tags?
3
+ return false unless $("#comable-tagit").length
4
+ true
5
+
6
+ initializa_comable_tagit = ->
7
+ return unless can_comable_tagit()
8
+
9
+ $("#comable-tagit").tagit({
10
+ fieldName: 'product[category_path_names][]',
11
+ availableTags: comable_tagit_available_tags,
12
+ autocomplete: { delay: 0, minLength: 0 },
13
+ showAutocompleteOnFocus: true,
14
+ removeConfirmation: true,
15
+ # Only allow available tags
16
+ beforeTagAdded: (event, ui) -> (comable_tagit_available_tags.indexOf(ui.tagLabel) != -1)
17
+ })
18
+
19
+ $(document).ready(->
20
+ initializa_comable_tagit()
21
+ )
@@ -0,0 +1,35 @@
1
+ class Search
2
+ constructor: (@templates = {}) ->
3
+
4
+ remove_fields: (button) ->
5
+ $(button).closest('.fields').remove()
6
+
7
+ add_fields: (button, type, content) ->
8
+ new_id = new Date().getTime()
9
+ regexp = new RegExp('new_' + type, 'g')
10
+ $(button).before(content.replace(regexp, new_id))
11
+
12
+ nest_fields: (button, type) ->
13
+ new_id = new Date().getTime()
14
+ id_regexp = new RegExp('new_' + type, 'g')
15
+ template = @templates[type]
16
+ object_name = $(button).closest('.fields').attr('data-object-name')
17
+ sanitized_object_name = object_name.replace(/\]\[|[^-a-zA-Z0-9:.]/g, '_').replace(/_$/, '')
18
+ template = template.replace(/new_object_name\[/g, object_name + "[")
19
+ template = template.replace(/new_object_name_/, sanitized_object_name + '_')
20
+ $(button).before(template.replace(id_regexp, new_id))
21
+
22
+ # ---
23
+ # main
24
+ # ---
25
+ search = new Search()
26
+
27
+ $(document).on('click', '.ransack.add_fields', ->
28
+ search.add_fields(this, $(this).data('fieldType'), $(this).data('content'))
29
+ false
30
+ )
31
+
32
+ $(document).on('click', '.ransack.remove_fields', ->
33
+ search.remove_fields(this)
34
+ false
35
+ )