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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/comable/admin/dispatcher.coffee +12 -2
- data/app/assets/javascripts/comable/admin/navigations.coffee +37 -0
- data/app/assets/javascripts/comable/admin/pages.coffee +0 -3
- data/app/assets/javascripts/comable/admin/products.coffee +35 -0
- data/app/assets/javascripts/comable/admin/search.coffee +6 -6
- data/app/assets/javascripts/comable/admin/themes.coffee +53 -64
- data/app/assets/javascripts/comable/admin/variants.coffee +106 -0
- data/app/assets/stylesheets/comable/admin/_common.scss +9 -0
- data/app/assets/stylesheets/comable/admin/_navigations.scss +13 -0
- data/app/assets/stylesheets/comable/admin/_variants.scss +40 -0
- data/app/assets/stylesheets/comable/admin/application.scss +2 -0
- data/app/controllers/comable/admin/navigations_controller.rb +84 -0
- data/app/controllers/comable/admin/orders_controller.rb +7 -14
- data/app/controllers/comable/admin/products_controller.rb +14 -6
- data/app/controllers/comable/admin/stocks_controller.rb +5 -2
- data/app/controllers/comable/admin/themes_controller.rb +5 -9
- data/app/controllers/comable/admin/variants_controller.rb +59 -0
- data/app/helpers/comable/admin/application_helper.rb +19 -12
- data/app/helpers/comable/admin/navigations_helper.rb +23 -0
- data/app/helpers/comable/admin/themes_helper.rb +1 -1
- data/{config/initializers/awesome_admin_layout.rb → app/navigations/comable/admin/application.rb} +8 -4
- data/app/views/comable/admin/navigations/_form.slim +40 -0
- data/app/views/comable/admin/navigations/_navigation_item_fields.slim +24 -0
- data/app/views/comable/admin/navigations/edit.slim +27 -0
- data/app/views/comable/admin/navigations/index.slim +25 -0
- data/app/views/comable/admin/navigations/new.slim +16 -0
- data/app/views/comable/admin/navigations/search_linkable_ids.coffee +15 -0
- data/app/views/comable/admin/orders/show.slim +1 -1
- data/app/views/comable/admin/products/_form.slim +91 -68
- data/app/views/comable/admin/products/edit.slim +4 -0
- data/app/views/comable/admin/products/index.slim +13 -11
- data/app/views/comable/admin/shared/{_image_fields.slim → _images_fields.slim} +5 -5
- data/app/views/comable/admin/shared/_option_type_fields.slim +13 -0
- data/app/views/comable/admin/shared/_option_types_fields.slim +13 -0
- data/app/views/comable/admin/shared/_variant_form.slim +26 -0
- data/app/views/comable/admin/shared/_variants_fields.slim +14 -0
- data/app/views/comable/admin/stocks/index.slim +16 -11
- data/app/views/comable/admin/variants/_form.slim +34 -0
- data/app/views/comable/admin/variants/edit.slim +31 -0
- data/app/views/comable/admin/variants/index.slim +97 -0
- data/app/views/comable/admin/variants/new.slim +16 -0
- data/app/views/layouts/comable/admin/application.slim +1 -1
- data/config/routes.rb +8 -1
- metadata +166 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21e413e5bc839c0924bfa5d8ffe4b07e996edc6b
|
4
|
+
data.tar.gz: c9e611eeff9a149567730af68720b2b8a36ab43a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
|
@@ -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
|
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
|
-
|
25
|
+
dynamic_field = new DynamicField
|
26
26
|
|
27
|
-
$(document).on('click', '.
|
28
|
-
|
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', '.
|
33
|
-
|
32
|
+
$(document).on('click', '.remove_fields', ->
|
33
|
+
dynamic_field.remove_fields(this)
|
34
34
|
false
|
35
35
|
)
|
@@ -1,64 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
$(
|
53
|
-
|
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
|
+
, [[]])
|
@@ -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
|
+
}
|