comable-backend 0.6.0 → 0.7.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/comable/admin/dispatcher.coffee +12 -2
  3. data/app/assets/javascripts/comable/admin/navigations.coffee +37 -0
  4. data/app/assets/javascripts/comable/admin/pages.coffee +0 -3
  5. data/app/assets/javascripts/comable/admin/products.coffee +35 -0
  6. data/app/assets/javascripts/comable/admin/search.coffee +6 -6
  7. data/app/assets/javascripts/comable/admin/themes.coffee +53 -64
  8. data/app/assets/javascripts/comable/admin/variants.coffee +106 -0
  9. data/app/assets/stylesheets/comable/admin/_common.scss +9 -0
  10. data/app/assets/stylesheets/comable/admin/_navigations.scss +13 -0
  11. data/app/assets/stylesheets/comable/admin/_variants.scss +40 -0
  12. data/app/assets/stylesheets/comable/admin/application.scss +2 -0
  13. data/app/controllers/comable/admin/navigations_controller.rb +84 -0
  14. data/app/controllers/comable/admin/orders_controller.rb +7 -14
  15. data/app/controllers/comable/admin/products_controller.rb +14 -6
  16. data/app/controllers/comable/admin/stocks_controller.rb +5 -2
  17. data/app/controllers/comable/admin/themes_controller.rb +5 -9
  18. data/app/controllers/comable/admin/variants_controller.rb +59 -0
  19. data/app/helpers/comable/admin/application_helper.rb +19 -12
  20. data/app/helpers/comable/admin/navigations_helper.rb +23 -0
  21. data/app/helpers/comable/admin/themes_helper.rb +1 -1
  22. data/{config/initializers/awesome_admin_layout.rb → app/navigations/comable/admin/application.rb} +8 -4
  23. data/app/views/comable/admin/navigations/_form.slim +40 -0
  24. data/app/views/comable/admin/navigations/_navigation_item_fields.slim +24 -0
  25. data/app/views/comable/admin/navigations/edit.slim +27 -0
  26. data/app/views/comable/admin/navigations/index.slim +25 -0
  27. data/app/views/comable/admin/navigations/new.slim +16 -0
  28. data/app/views/comable/admin/navigations/search_linkable_ids.coffee +15 -0
  29. data/app/views/comable/admin/orders/show.slim +1 -1
  30. data/app/views/comable/admin/products/_form.slim +91 -68
  31. data/app/views/comable/admin/products/edit.slim +4 -0
  32. data/app/views/comable/admin/products/index.slim +13 -11
  33. data/app/views/comable/admin/shared/{_image_fields.slim → _images_fields.slim} +5 -5
  34. data/app/views/comable/admin/shared/_option_type_fields.slim +13 -0
  35. data/app/views/comable/admin/shared/_option_types_fields.slim +13 -0
  36. data/app/views/comable/admin/shared/_variant_form.slim +26 -0
  37. data/app/views/comable/admin/shared/_variants_fields.slim +14 -0
  38. data/app/views/comable/admin/stocks/index.slim +16 -11
  39. data/app/views/comable/admin/variants/_form.slim +34 -0
  40. data/app/views/comable/admin/variants/edit.slim +31 -0
  41. data/app/views/comable/admin/variants/index.slim +97 -0
  42. data/app/views/comable/admin/variants/new.slim +16 -0
  43. data/app/views/layouts/comable/admin/application.slim +1 -1
  44. data/config/routes.rb +8 -1
  45. metadata +166 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc13f09174988052b4dac133bb4b2fad27edb360
4
- data.tar.gz: 6da4749c448aa3de6cd592ccfb6b5aac8b24d602
3
+ metadata.gz: 21e413e5bc839c0924bfa5d8ffe4b07e996edc6b
4
+ data.tar.gz: c9e611eeff9a149567730af68720b2b8a36ab43a
5
5
  SHA512:
6
- metadata.gz: fd165e1f0602941a9b79291a90816fd57aa8341358cdc4d576ddf9f8aea39666963487bbf375fa72ca7507a3509f89eeb7e928d15c5451fb472331407d6bde9e
7
- data.tar.gz: 7de02b45f9941793ac7a6b6e8caa4d9d19e121509fe161ad3a07a15c15293ff53e05ac867cfa015fa8a7e0231337d72453086e1cb23cb96b113d35b095e4e1a2
6
+ metadata.gz: 0c7bcfbceaba2d2806a1b42ee422d443908e8a613e6705c9259b30063b48f2548f8eb1f961e06e6ca70a36c9dd59eab2668e30eceb26d0bcbdfd97b82eb26337
7
+ data.tar.gz: 514dd41231eb28738854f4fcb721fe651e46071025b787b4e4ca72807ac6a6324c737adb9679a0eb676cae36ac2df3d3ea191a25d8373d20d13598f9d947eac8
@@ -15,7 +15,17 @@ class Dispatcher
15
15
  action_name = path[1]
16
16
 
17
17
  switch page
18
- when 'orders:edit'
18
+ when 'orders:edit', 'pages:update'
19
19
  new DynamicOrder
20
- when 'pages:new', 'pages:show', 'pages:edit'
20
+ when 'pages:new', 'pages:show', 'pages:edit', 'pages:update', 'pages:create'
21
21
  new Page
22
+ when 'products:new', 'products:show', 'products:edit', 'products:update', 'products:create'
23
+ new Product
24
+ new Variant
25
+ when 'navigations:new', 'navigations:show', 'navigations:edit', 'navigations:update', 'navigations:create'
26
+ new Navigation
27
+ when 'themes:tree'
28
+ new ThemeTree
29
+ when 'themes:show_file'
30
+ new ThemeTree
31
+ new ThemeEditor
@@ -0,0 +1,37 @@
1
+ class @Navigation
2
+ constructor: ->
3
+ @navigation_items = $('#navigation-items')
4
+ @add_fields = $('.add_fields')
5
+ @add_event()
6
+
7
+ # linkable_idの検索
8
+ search_linkable_ids: ->
9
+ $linkable_type = $('#linkable_type')
10
+ $position = $('#position')
11
+ $linkable_type.val($(this).val())
12
+ $position.val($('.linkable_type').index(this))
13
+ $linkable_type.closest('form').submit()
14
+
15
+ # アイテムの追加
16
+ adding_navigation_item_field: ->
17
+ regexp = new RegExp($(this).data('index'), 'g')
18
+ field_tags = $(this).data('fields').replace(regexp, $('.navigation-item').length) # 置換予定文字を添字に置換する
19
+ $field = $(field_tags)
20
+ $field.addClass('js-new-record')
21
+ $('#navigation-items').append($field) # タグを追加
22
+
23
+ # アイテムの削除
24
+ remove_navigation_item_field: ->
25
+ $navigation_item = $(this).closest('.navigation-item')
26
+ if $navigation_item.hasClass('js-new-record')
27
+ $navigation_item.remove()
28
+ else
29
+ $navigation_item.find('.destroy').val(true)
30
+ $navigation_item.addClass('hidden')
31
+
32
+ # イベント設定
33
+ add_event: ->
34
+ @navigation_items.on('change', '.linkable_type', @search_linkable_ids)
35
+ @navigation_items.on('click', '.remove_fields', @remove_navigation_item_field)
36
+ @add_fields.click(@adding_navigation_item_field)
37
+
@@ -1,8 +1,5 @@
1
1
  class @Page
2
2
  constructor: ->
3
- $(document).ready(@ready)
4
-
5
- ready: =>
6
3
  @radio_published = $('#page_published_at_published')
7
4
  @radio_unpublished = $('#page_published_at_unpublished')
8
5
  @published_at = $('#page_published_at')
@@ -19,3 +19,38 @@ initializa_comable_tagit = ->
19
19
  $(document).ready(->
20
20
  initializa_comable_tagit()
21
21
  )
22
+
23
+ class @Product
24
+ constructor: ->
25
+ @radio_published = $('#product_published_at_published')
26
+ @radio_unpublished = $('#product_published_at_unpublished')
27
+ @published_at = $('#product_published_at')
28
+
29
+ @initialize_visibility()
30
+ @add_event_to_set_visibility()
31
+
32
+ # 公開/非公開の制御
33
+ initialize_visibility: ->
34
+ if @radio_published.is(':checked')
35
+ @published()
36
+ if @radio_unpublished.is(':checked')
37
+ @unpublished()
38
+
39
+ # 公開の際の制御
40
+ published: =>
41
+ @published_at.show()
42
+ @published_at.val(moment().format('YYYY-MM-DD HH:mm')) unless @published_at.val()
43
+
44
+ # 非公開の際の制御
45
+ unpublished: =>
46
+ @published_at.hide()
47
+ @published_at.val('')
48
+
49
+ add_event_to_set_visibility: ->
50
+ @radio_published.click(@published)
51
+ @radio_unpublished.click(@unpublished)
52
+
53
+ # 日付を空にされたら非公開にする
54
+ @published_at.blur( =>
55
+ @radio_unpublished.click() unless @published_at.val()
56
+ )
@@ -1,4 +1,4 @@
1
- class Search
1
+ class DynamicField
2
2
  constructor: (@templates = {}) ->
3
3
 
4
4
  remove_fields: (button) ->
@@ -22,14 +22,14 @@ class Search
22
22
  # ---
23
23
  # main
24
24
  # ---
25
- search = new Search()
25
+ dynamic_field = new DynamicField
26
26
 
27
- $(document).on('click', '.ransack.add_fields', ->
28
- search.add_fields(this, $(this).data('fieldType'), $(this).data('content'))
27
+ $(document).on('click', '.add_fields', ->
28
+ dynamic_field.add_fields(this, $(this).data('fieldType'), $(this).data('content'))
29
29
  false
30
30
  )
31
31
 
32
- $(document).on('click', '.ransack.remove_fields', ->
33
- search.remove_fields(this)
32
+ $(document).on('click', '.remove_fields', ->
33
+ dynamic_field.remove_fields(this)
34
34
  false
35
35
  )
@@ -1,64 +1,53 @@
1
- can_use_comable_theme_editor = ->
2
- return false unless $('#comable-theme-editor').length
3
- return false unless $('#comable-theme-editor-form').length
4
- true
5
-
6
- can_use_comable_file_tree = ->
7
- return false unless $('#comable-file-tree').length
8
- true
9
-
10
- comable_theme_editor_window = ->
11
- editor_element = $('#comable-theme-editor').find('.comable-theme-editor-window').get(0)
12
- ace.edit(editor_element)
13
-
14
- initializa_comable_theme_editor = ->
15
- editor = comable_theme_editor_window()
16
- editor.setTheme('ace/theme/monokai')
17
- editor.session.setMode('ace/mode/liquid')
18
- $(window).bind('beforeunload', ->
19
- window.beforeunload_message unless editor.session.getUndoManager().isClean()
20
- )
21
- $(document).on('page:before-change', ->
22
- confirm(window.beforeunload_message) unless editor.session.getUndoManager().isClean()
23
- )
24
-
25
- add_comable_theme_editor_form_event = ->
26
- $form = $('#comable-theme-editor-form')
27
- $form.submit(->
28
- editor = comable_theme_editor_window()
29
- text = editor.getValue()
30
- $(this).find('[name=code]').val(text)
31
- )
32
-
33
- add_comable_file_tree_event = ->
34
- $comable_file_tree = $('#comable-file-tree')
35
- $comable_file_tree.find('a').click((event) ->
36
- event.preventDefault()
37
- path = $(this).attr('href')
38
- page_before_change = jQuery.Event('page:before-change')
39
- $(document).trigger(page_before_change)
40
- Turbolinks.visit(path) unless page_before_change.isDefaultPrevented()
41
- )
42
-
43
- resize_forms_height = ->
44
- header_height = parseInt($('.comable-page-body').css('padding-top'))
45
- footer_height = $('footer').outerHeight(true)
46
- main_height = $(window).height() - header_height - footer_height
47
- $comable_file_tree = $('#comable-file-tree')
48
- $comable_file_tree.css('height', main_height + 'px') if $comable_file_tree.length
49
- $comable_theme_editor = $('#comable-theme-editor')
50
- $comable_theme_editor.css('height', main_height + 'px') if $comable_theme_editor.length
51
-
52
- $(document).ready(->
53
- if can_use_comable_theme_editor()
54
- initializa_comable_theme_editor()
55
- add_comable_theme_editor_form_event()
56
- if can_use_comable_file_tree()
57
- resize_forms_height()
58
- add_comable_file_tree_event()
59
- )
60
-
61
- $(window).resize(->
62
- return unless can_use_comable_file_tree()
63
- resize_forms_height()
64
- )
1
+ class @ThemeTree
2
+ constructor: ->
3
+ $(window).resize(@resize_forms_height)
4
+ @resize_forms_height()
5
+ @add_comable_file_tree_event()
6
+
7
+ add_comable_file_tree_event: ->
8
+ $comable_file_tree = $('#comable-file-tree')
9
+ $comable_file_tree.find('a').click((event) ->
10
+ event.preventDefault()
11
+ path = $(this).attr('href')
12
+ page_before_change = jQuery.Event('page:before-change')
13
+ $(document).trigger(page_before_change)
14
+ Turbolinks.visit(path) unless page_before_change.isDefaultPrevented()
15
+ )
16
+
17
+ resize_forms_height: ->
18
+ header_height = parseInt($('.comable-page-body').css('padding-top'))
19
+ footer_height = $('footer').outerHeight(true)
20
+ main_height = $(window).height() - header_height - footer_height
21
+ $comable_file_tree = $('#comable-file-tree')
22
+ $comable_file_tree.css('height', main_height + 'px') if $comable_file_tree.length
23
+ $comable_theme_editor = $('#comable-theme-editor')
24
+ $comable_theme_editor.css('height', main_height + 'px') if $comable_theme_editor.length
25
+
26
+ class @ThemeEditor
27
+ constructor: ->
28
+ @initializa_comable_theme_editor()
29
+ @add_comable_theme_editor_form_event()
30
+
31
+ initializa_comable_theme_editor: ->
32
+ editor = @comable_theme_editor_window()
33
+ editor.setTheme('ace/theme/monokai')
34
+ editor.session.setMode('ace/mode/liquid')
35
+ $(window).bind('beforeunload', ->
36
+ window.beforeunload_message unless editor.session.getUndoManager().isClean()
37
+ )
38
+ $(document).on('page:before-change', ->
39
+ confirm(window.beforeunload_message) unless editor.session.getUndoManager().isClean()
40
+ )
41
+
42
+ add_comable_theme_editor_form_event: ->
43
+ _this = @
44
+ $form = $('#comable-theme-editor-form')
45
+ $form.submit( ->
46
+ editor = _this.comable_theme_editor_window()
47
+ text = editor.getValue()
48
+ $(this).find('[name=code]').val(text)
49
+ )
50
+
51
+ comable_theme_editor_window: ->
52
+ editor_element = $('#comable-theme-editor').find('.comable-theme-editor-window').get(0)
53
+ ace.edit(editor_element)
@@ -0,0 +1,106 @@
1
+ class @Variant
2
+ initialized: false
3
+
4
+ constructor: ->
5
+ @initialize_tagits()
6
+ @register_click_event_to_add_option_button()
7
+ @register_click_event_to_remove_option_button()
8
+ @initialized = true
9
+
10
+ initialize_tagits: ->
11
+ _this = @
12
+ $('.js-tagit-option-values').each( ->
13
+ _this.initialize_tagit(this)
14
+ )
15
+
16
+ initialize_tagit: (element) ->
17
+ $element = $(element)
18
+ index = $element.data('index')
19
+ $element.tagit({
20
+ fieldName: 'product[option_types_attributes][' + index + '][values][]',
21
+ caseSensitive: false,
22
+ removeConfirmation: true,
23
+ readOnly: $element.hasClass('tagit-readonly'),
24
+ afterTagAdded: @rebuild_variants,
25
+ afterTagRemoved: @rebuild_variants
26
+ })
27
+
28
+ register_click_event_to_add_option_button: ->
29
+ $('.js-add-option').click( =>
30
+ @change_from_master()
31
+ setTimeout( =>
32
+ @initialize_tagits()
33
+ , 1)
34
+ )
35
+
36
+ register_click_event_to_remove_option_button: ->
37
+ $(document).on('click', '.js-remove-option', ->
38
+ $(this).closest('.js-new-variants').remove()
39
+ @change_to_master()
40
+ )
41
+
42
+ rebuild_variants: (event, ui) =>
43
+ return unless @initialized
44
+ @remove_variants()
45
+ @build_variants()
46
+
47
+ build_variants: ->
48
+ _this = @
49
+ options = []
50
+ $('.js-tagit-option-values').each( ->
51
+ return unless $(this).hasClass('tagit')
52
+ name = $(this).closest('.comable-option').find('input:first-child').val()
53
+ values = $(this).tagit('assignedTags')
54
+ option = jQuery.map(values, (value) -> { name: name, value: value })
55
+ options.push(option)
56
+ )
57
+ options_for_variants = _product(_compact(options))
58
+ options_for_variants.forEach((options_for_variant) ->
59
+ _this.build_variant(options_for_variant)
60
+ )
61
+
62
+ build_variant: (options) ->
63
+ $variant = @new_variant()
64
+
65
+ $variant.find('[data-name="options"] > input').val(JSON.stringify(options))
66
+ options.forEach((option) ->
67
+ $variant.find('[data-name="options"]').append('<span class="comable-variant-name">' + option.value + '</span> ')
68
+ )
69
+
70
+ $('.js-variants-table').find('tbody').append($variant)
71
+
72
+ remove_variants: ->
73
+ $('.js-new-variants:not(.hidden)').remove()
74
+
75
+ new_variant: ->
76
+ new_id = new Date().getTime()
77
+ $('.js-add-variant').click()
78
+ $variant = $('.js-new-variants').last()
79
+ $variant.removeClass('hidden')
80
+ $variant.html($variant.html().replace(/new_variant/g, new_id))
81
+ $variant
82
+
83
+ change_from_master: ->
84
+ $('.js-variants-table').removeClass('hidden')
85
+ $('#product_variants_attributes_0__destroy').val(1)
86
+
87
+ change_to_master: ->
88
+ $('.js-variants-table').removeClass('hidden')
89
+ $('.js-variants-table').addClass('hidden')
90
+ $('#product_variants_attributes_0__destroy').val(0) if $('.js-new-variants').length == 0
91
+
92
+ # refs http://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript/2843625#2843625
93
+ _compact = (arrays) ->
94
+ $.grep(arrays, (n) -> n if n && n.length != 0)
95
+
96
+ # refs http://cwestblog.com/2011/05/02/cartesian-product-of-multiple-arrays/
97
+ _product = (arrays) ->
98
+ Array.prototype.reduce.call(arrays, (a, b) ->
99
+ ret = []
100
+ a.forEach((a) ->
101
+ b.forEach((b) ->
102
+ ret.push(a.concat([b]))
103
+ )
104
+ )
105
+ ret
106
+ , [[]])
@@ -151,3 +151,12 @@ footer {
151
151
  cursor: inherit;
152
152
  display: block;
153
153
  }
154
+
155
+ // for Tag-it
156
+ ul.tagit {
157
+ @include border-radius($input-border-radius);
158
+
159
+ &.tagit-readonly {
160
+ background-color: #eee;
161
+ }
162
+ }
@@ -0,0 +1,13 @@
1
+ #comable-navigation {
2
+ .add_fields {
3
+ margin-right: 30px;
4
+ }
5
+
6
+ .remove_fields {
7
+ margin-top: 25px;
8
+ }
9
+
10
+ .linkable_id select {
11
+ margin-top: 25px;
12
+ }
13
+ }
@@ -0,0 +1,40 @@
1
+ $comable-colors: #ffa000 #5dd39e #d81159 #06aed5 #8f2d56;
2
+
3
+ @for $i from 1 through length($comable-colors) {
4
+ $color: nth($comable-colors, $i);
5
+
6
+ .comable-variant-name:nth-of-type(#{$i}) {
7
+ color: darken($color, 5%);
8
+
9
+ &:after {
10
+ display: inline;
11
+ margin: 0 5px;
12
+ color: #444;
13
+ content: '·';
14
+ }
15
+
16
+ &:last-child:after {
17
+ display: none;
18
+ }
19
+ }
20
+
21
+ .comable-option:nth-of-type(#{$i}) {
22
+ .comable-option-name {
23
+ color: darken($color, 5%);
24
+ }
25
+
26
+ ul.comable-option-values li:not(.tagit-new) {
27
+ background-color: $color;
28
+ border-color: $color;
29
+
30
+ & > span, & > a, & > a > span {
31
+ color: #fff;
32
+ }
33
+
34
+ &.remove {
35
+ background-color: darken($color, 10%);
36
+ border-color: darken($color, 10%);
37
+ }
38
+ }
39
+ }
40
+ }
@@ -22,5 +22,7 @@
22
22
  @import 'comable/admin/orders';
23
23
  @import 'comable/admin/products';
24
24
  @import 'comable/admin/pages';
25
+ @import 'comable/admin/navigations';
25
26
  @import 'comable/admin/user_sessions';
26
27
  @import 'comable/admin/themes';
28
+ @import 'comable/admin/variants';