character 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.rspec +1 -0
  4. data/README.md +185 -14
  5. data/Rakefile +8 -1
  6. data/app/assets/images/character/logo.jpg +0 -0
  7. data/app/assets/javascripts/character.coffee +134 -0
  8. data/app/assets/javascripts/character/dashboard/_visitors.coffee +27 -0
  9. data/app/assets/javascripts/character/dashboard/layout.coffee +156 -0
  10. data/app/assets/javascripts/character/dashboard/module.coffee +51 -0
  11. data/app/assets/javascripts/character/generic/details.coffee +233 -0
  12. data/app/assets/javascripts/character/generic/helpers/compact_object.coffee +7 -0
  13. data/app/assets/javascripts/character/generic/helpers/data_inputs.coffee +21 -0
  14. data/app/assets/javascripts/character/generic/helpers/date_select.coffee +45 -0
  15. data/app/assets/javascripts/character/generic/helpers/editor.coffee +11 -0
  16. data/app/assets/javascripts/character/generic/helpers/redactor.coffee +38 -0
  17. data/app/assets/javascripts/character/generic/helpers/reorder.coffee +36 -0
  18. data/app/assets/javascripts/character/generic/layout.coffee +40 -0
  19. data/app/assets/javascripts/character/generic/list.coffee +214 -0
  20. data/app/assets/javascripts/character/generic/model.coffee +135 -0
  21. data/app/assets/javascripts/character/generic/module.coffee +157 -0
  22. data/app/assets/javascripts/character/images/module.coffee +148 -0
  23. data/app/assets/javascripts/character/pages/module.coffee +43 -0
  24. data/app/assets/javascripts/character/posts/module.coffee +113 -0
  25. data/app/assets/javascripts/character/settings/_admins.coffee +61 -0
  26. data/app/assets/javascripts/character/settings/_authors.coffee +56 -0
  27. data/app/assets/javascripts/character/settings/_categories.coffee +61 -0
  28. data/app/assets/javascripts/character/settings/_layout.coffee +7 -0
  29. data/app/assets/javascripts/character/settings/_redirects.coffee +56 -0
  30. data/app/assets/javascripts/character/settings/_website.coffee +7 -0
  31. data/app/assets/javascripts/character/settings/details.coffee +16 -0
  32. data/app/assets/javascripts/character/settings/layout.coffee +46 -0
  33. data/app/assets/javascripts/character/settings/module.coffee +78 -0
  34. data/app/assets/stylesheets/character.scss +37 -0
  35. data/app/assets/stylesheets/character/_admins.scss +30 -0
  36. data/app/assets/stylesheets/character/_authors.scss +30 -0
  37. data/app/assets/stylesheets/character/_categories.scss +32 -0
  38. data/app/assets/stylesheets/character/_dashboard.scss +143 -0
  39. data/app/assets/stylesheets/character/_posts.scss +93 -0
  40. data/app/assets/stylesheets/character/_redirects.scss +35 -0
  41. data/app/assets/stylesheets/character/base.scss +967 -0
  42. data/app/assets/stylesheets/character/typography.scss +29 -0
  43. data/app/controllers/character/api_controller.rb +170 -0
  44. data/app/controllers/character/application_controller.rb +37 -0
  45. data/app/controllers/character/settings_controller.rb +72 -0
  46. data/app/controllers/concerns/character/auth_concern.rb +41 -0
  47. data/app/controllers/concerns/character/instance_concern.rb +31 -0
  48. data/app/controllers/concerns/character/json_object_concern.rb +32 -0
  49. data/app/controllers/concerns/character/model_class_concern.rb +28 -0
  50. data/app/controllers/concerns/character/params_concern.rb +33 -0
  51. data/app/controllers/concerns/character/templates_concern.rb +32 -0
  52. data/app/controllers/concerns/not_found.rb +18 -0
  53. data/app/controllers/concerns/website_settings.rb +18 -0
  54. data/app/controllers/pages_controller.rb +8 -0
  55. data/app/controllers/posts_controller.rb +43 -0
  56. data/app/helpers/character_helper.rb +8 -0
  57. data/app/helpers/page_helper.rb +67 -0
  58. data/app/inputs/foundation_string_input.rb +44 -0
  59. data/app/inputs/foundation_switch_input.rb +35 -0
  60. data/app/models/character/image.rb +12 -0
  61. data/app/models/character/page.rb +21 -0
  62. data/app/models/character/post.rb +32 -12
  63. data/app/models/character/post_author.rb +22 -0
  64. data/app/models/character/post_category.rb +21 -0
  65. data/app/models/character/redirect.rb +15 -0
  66. data/app/models/character/settings/variable.rb +23 -0
  67. data/app/models/character/sitemap/sitemap_generator_helper.rb +15 -0
  68. data/app/models/character/user.rb +29 -0
  69. data/app/models/concerns/created_ago.rb +12 -0
  70. data/app/models/concerns/hideable.rb +27 -0
  71. data/app/models/concerns/orderable.rb +8 -0
  72. data/app/models/concerns/report.rb +11 -0
  73. data/app/models/concerns/report_daily.rb +32 -0
  74. data/app/models/concerns/report_monthly.rb +18 -0
  75. data/app/models/concerns/report_weekly.rb +19 -0
  76. data/app/models/concerns/updated_ago.rb +12 -0
  77. data/app/models/reports/analytics_daily.rb +26 -0
  78. data/app/models/reports/analytics_monthly.rb +16 -0
  79. data/app/models/reports/analytics_weekly.rb +16 -0
  80. data/app/services/google_analytics.rb +43 -0
  81. data/app/uploaders/character/image_uploader.rb +22 -0
  82. data/app/uploaders/character/settings/file_uploader.rb +5 -0
  83. data/app/views/character/character.html.erb +67 -0
  84. data/app/views/character/generic/form.html.erb +8 -0
  85. data/app/views/character/pages/form.html.erb +28 -0
  86. data/app/views/character/posts/form.html.erb +38 -0
  87. data/app/views/character/settings/admins.html.erb +29 -0
  88. data/app/views/character/settings/post_authors.html.erb +28 -0
  89. data/app/views/character/settings/post_categories.html.erb +31 -0
  90. data/app/views/character/settings/redirects.html.erb +30 -0
  91. data/app/views/character/settings/settings_group.html.erb +67 -0
  92. data/app/views/errors/not_found.html.erb +157 -0
  93. data/app/views/pages/_default.html.erb +3 -0
  94. data/app/views/pages/_redactor.html.erb +3 -0
  95. data/app/views/pages/show.html.erb +5 -0
  96. data/app/views/posts/_post.html.erb +17 -0
  97. data/app/views/posts/author.html.erb +18 -0
  98. data/app/views/posts/category.html.erb +18 -0
  99. data/app/views/posts/index.html.erb +18 -0
  100. data/app/views/posts/rss.builder +19 -0
  101. data/app/views/posts/show.html.erb +14 -0
  102. data/app/views/shared/_google_analytics.html.erb +13 -0
  103. data/character.gemspec +48 -5
  104. data/doc/README_old.md +161 -0
  105. data/doc/generic_app.md +19 -0
  106. data/doc/img/demo-1.jpg +0 -0
  107. data/doc/img/demo-2.jpg +0 -0
  108. data/doc/img/demo-3.jpg +0 -0
  109. data/doc/img/demo-4.jpg +0 -0
  110. data/doc/img/demo-5.jpg +0 -0
  111. data/doc/instances.md +39 -0
  112. data/doc/settings.md +1 -0
  113. data/lib/character.rb +29 -1
  114. data/lib/character/engine.rb +33 -1
  115. data/lib/character/generators/bootstrap_generator.rb +51 -0
  116. data/lib/character/instance.rb +59 -0
  117. data/lib/character/routing.rb +42 -5
  118. data/lib/character/settings.rb +101 -0
  119. data/lib/character/templates/admin.coffee +15 -0
  120. data/lib/character/templates/admin.scss +3 -0
  121. data/lib/character/templates/application.html.erb +44 -0
  122. data/lib/character/templates/application.scss +12 -0
  123. data/lib/character/templates/assets.rb +1 -0
  124. data/lib/character/templates/initializer.rb +5 -0
  125. data/lib/character/templates/settings.scss +11 -0
  126. data/lib/character/templates/settings.yml +67 -0
  127. data/lib/character/templates/typography.scss +13 -0
  128. data/lib/character/version.rb +2 -2
  129. data/lib/mongoid/carrierwave_serialization_patch.rb +9 -0
  130. data/lib/tasks/analytics.rake +52 -0
  131. data/test/config/application.rb +65 -0
  132. data/test/config/mongoid.yml +12 -0
  133. data/test/config/secrets.yml +22 -0
  134. data/test/controllers/character/api_controller_test.rb +94 -0
  135. data/test/factories/product_factory.rb +5 -0
  136. data/test/lib/character/engine_test.rb +33 -0
  137. data/test/lib/character/routing_test.rb +31 -0
  138. data/test/test_helper.rb +48 -0
  139. data/vendor/assets/javascripts/backbone.js +944 -794
  140. data/vendor/assets/javascripts/jquery.fileupload.js +1426 -0
  141. data/vendor/assets/javascripts/jquery.form.js +1278 -0
  142. data/vendor/assets/javascripts/jquery.iframe-transport.js +214 -0
  143. data/vendor/assets/javascripts/raphael.js +8117 -0
  144. data/vendor/assets/javascripts/raphael.morris.js +1885 -0
  145. data/vendor/assets/javascripts/underscore.inflection.js +177 -0
  146. data/vendor/assets/javascripts/underscore.string.js +1 -1
  147. data/vendor/assets/stylesheets/csspinner.css +361 -0
  148. data/vendor/assets/stylesheets/normalize.css +423 -0
  149. metadata +499 -49
  150. data/app/controllers/character/posts_controller.rb +0 -27
  151. data/lib/generators/character/install_generator.rb +0 -42
  152. data/lib/generators/character/templates/README +0 -1
  153. data/lib/generators/character/templates/admin/character.rb +0 -3
  154. data/vendor/assets/fonts/general_foundicons.eot +0 -0
  155. data/vendor/assets/fonts/general_foundicons.svg +0 -15
  156. data/vendor/assets/fonts/general_foundicons.ttf +0 -0
  157. data/vendor/assets/fonts/general_foundicons.woff +0 -0
  158. data/vendor/assets/javascripts/character/index.js.coffee +0 -53
  159. data/vendor/assets/javascripts/character/models/post.js.coffee +0 -39
  160. data/vendor/assets/javascripts/character/views/app.js.coffee +0 -81
  161. data/vendor/assets/javascripts/character/views/editor.js.coffee +0 -231
  162. data/vendor/assets/javascripts/character/views/editor_settings.js.coffee +0 -44
  163. data/vendor/assets/javascripts/character/views/index.js.coffee +0 -116
  164. data/vendor/assets/javascripts/character/views/preview.js.coffee +0 -49
  165. data/vendor/assets/javascripts/jquery.smartresize.js +0 -30
  166. data/vendor/assets/javascripts/lodash.js +0 -4258
  167. data/vendor/assets/javascripts/showdown.js +0 -62
  168. data/vendor/assets/stylesheets/character/_base.css.scss +0 -84
  169. data/vendor/assets/stylesheets/character/_icons.css.scss.erb +0 -96
  170. data/vendor/assets/stylesheets/character/_view_editor.css.scss +0 -115
  171. data/vendor/assets/stylesheets/character/_view_index.css.scss +0 -73
  172. data/vendor/assets/stylesheets/character/_view_preview.css.scss +0 -49
  173. data/vendor/assets/stylesheets/character/index.css.scss +0 -32
@@ -0,0 +1,51 @@
1
+ #= require raphael
2
+ #= require raphael.morris
3
+
4
+ #= require_self
5
+ #= require ./layout
6
+
7
+ @Character.Dashboard ||= {}
8
+
9
+ #
10
+ # Marionette.js Router Documentation
11
+ # https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.router.md
12
+ #
13
+ @Character.Dashboard.Router = Backbone.Marionette.AppRouter.extend
14
+ initialize: (options) ->
15
+ @appRoutes ||= {}
16
+ @appRoutes["#{ options.path }(/:scope)"] = "index"
17
+
18
+ #
19
+ # Marionette.js Controller Documentation
20
+ # https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.controller.md
21
+ #
22
+ @Character.Dashboard.Controller = Backbone.Marionette.Controller.extend
23
+ initialize: ->
24
+ @module = @options.module
25
+
26
+ index: (scope, callback) ->
27
+ chr.execute('showModule', @module)
28
+
29
+ path = @options.moduleName + ( if scope then "/#{ scope }" else '' )
30
+ if chr.currentPath != path
31
+ chr.currentPath = path
32
+ @module.layout.setDateRange()
33
+ @module.layout.updateScope(scope, callback)
34
+ else
35
+ callback?()
36
+
37
+ chr.dashboardModule = ->
38
+ moduleName = 'dashboard'
39
+
40
+ chr.module moduleName, (module) ->
41
+ module = _(module).extend(Character.Dashboard)
42
+
43
+ options =
44
+ module: module
45
+ moduleName: moduleName
46
+
47
+ module.on 'start', ->
48
+ @controller = new @Controller(options)
49
+ @layout = new @Layout(options)
50
+ @router = new @Router({ path: moduleName, controller: @controller })
51
+ chr.execute('addMenuItem', moduleName, 'bar-chart-o', 'Dashboard')
@@ -0,0 +1,233 @@
1
+
2
+ #
3
+ # Marionette.js Item View Documentation
4
+ # https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.itemview.md
5
+ #
6
+ @Character.Generic.DetailsHeaderView = Backbone.Marionette.ItemView.extend
7
+ template: -> "<button id=save class='save invert' title='Save changes'>Save</button>
8
+ <button id=cancel class=cancel title='Cancel changes'>Cancel</button>
9
+ <span id=published class=published><i class='fa fa-eye'></i><i class='fa fa-eye-slash'></i></span>
10
+ <div id=details_title class=title></div>
11
+ <a id=delete class=delete href='#' title='Delete this item'>
12
+ <i class='fa fa-trash-o'></i>
13
+ </a>
14
+ <span id=details_meta class=meta></span>"
15
+
16
+ ui:
17
+ title: '#details_title'
18
+ meta: '#details_meta'
19
+ actionSave: '#save'
20
+ actionCancel: '#cancel'
21
+ actionPublished: '#published'
22
+ actionDelete: '#delete'
23
+
24
+ initialize: ->
25
+ if @model
26
+ @listenTo(@model, 'change', @render, @)
27
+
28
+ togglePublished: ($input) ->
29
+ @ui.actionPublished.toggleClass 'off'
30
+ $input.val @ui.actionPublished.hasClass('off')
31
+
32
+ onRender: ->
33
+ if @model
34
+ title = @model.getTitle()
35
+ updatedFromNow = moment(@model.get('updated_at')).fromNow()
36
+ @ui.meta.html("updated #{ updatedFromNow }")
37
+
38
+ if @model.has('hidden')
39
+ @ui.actionPublished.show()
40
+ @ui.actionPublished.addClass 'off' if @model.get('hidden')
41
+
42
+ else
43
+ title = @options.title
44
+
45
+ @ui.title.html(title)
46
+
47
+ if not @options.deletable
48
+ @ui.actionDelete.hide()
49
+
50
+ updateState: (state) ->
51
+ if @ui
52
+ if state == 'saving'
53
+ @ui.actionSave.addClass('disabled')
54
+ @ui.actionSave.html 'Saving...'
55
+ else
56
+ setTimeout ( =>
57
+ # need these checks when create new object, view is recreated
58
+ @ui.actionSave.removeClass?('disabled')
59
+ @ui.actionSave.html?('Save')
60
+ ), 500
61
+
62
+
63
+ #
64
+ # Marionette.js Layout Documentation
65
+ # https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.layout.md
66
+ #
67
+ @Character.Generic.DetailsLayout = Backbone.Marionette.LayoutView.extend
68
+ className: 'chr-details'
69
+ template: -> "<header id=details_header class='chr-details-header'></header>
70
+ <section id=details_content class='chr-details-content'></section>"
71
+
72
+ regions:
73
+ header: '#details_header'
74
+
75
+ ui:
76
+ content: '#details_content'
77
+
78
+ events:
79
+ 'click #cancel': '_cancel'
80
+ 'click #save': '_save'
81
+ 'click #delete': '_delete'
82
+ 'click #published': '_togglePublished'
83
+
84
+ initialize: ->
85
+ @module = @options.module
86
+ @DetailsHeaderView = @module.DetailsHeaderView
87
+
88
+ _togglePublished: ->
89
+ hiddenInput = _.find @ui.form.find('input[type=hidden]'), (input) -> _( $(input).attr('name') ).endsWith '[hidden]'
90
+ if hiddenInput
91
+ @headerView.togglePublished($(hiddenInput))
92
+
93
+ _save: ->
94
+ @beforeSave?()
95
+
96
+ if @ui.form.length
97
+ Character.Generic.Helpers.serializeDataInputs(@ui.content, @ui.form)
98
+
99
+ if @collection
100
+ # include fields to properly update item in a list and sort
101
+ params = _.clone(@collection.options.constantParams)
102
+ if @collection.sortField
103
+ params.f = _([ params.f, @collection.sortField ]).uniq().join(',')
104
+
105
+ @ui.form.ajaxSubmit
106
+ data: params
107
+ beforeSubmit: (arr, $form, options) =>
108
+ @beforeFormSubmit?(arr, $form, options)
109
+ @headerView.updateState('saving')
110
+ return true
111
+ error: (xhr) =>
112
+ chr.execute('showError', xhr)
113
+ @headerView.updateState()
114
+ success: (responseText, statusText, xhr, $form) =>
115
+ @headerView.updateState()
116
+ @_updateModel(responseText)
117
+ @afterFormSubmitSuccess?(responseText, statusText, xhr, $form)
118
+
119
+ return false
120
+
121
+ _updateModel: (resp) ->
122
+ # string means form errors returned
123
+ if typeof(resp) == 'string'
124
+ return @_renderContent(resp)
125
+
126
+ # assuming response is json
127
+ if @model
128
+ @model.set(resp)
129
+ @collection.sort()
130
+ else
131
+ @collection.fetchPage 1, ->
132
+ Backbone.history.navigate("#/#{chr.currentPath}/edit/#{resp._id}", { trigger: true })
133
+
134
+ _delete: ->
135
+ if confirm("""Delete "#{ @model.getTitle() }"?""")
136
+ # @close()
137
+ #@destroy()
138
+ @model.destroy
139
+ success: ->
140
+ Backbone.history.navigate("#/#{chr.currentPath}", { trigger: true })
141
+ error: (model, response, options) ->
142
+ chr.execute('error', response)
143
+ return false
144
+
145
+ _cancel: ->
146
+ Backbone.history.navigate("#/#{chr.currentPath}", { trigger: true })
147
+
148
+ _toggleFullscreen: ->
149
+ @$el.parent().toggleClass('fullscreen')
150
+
151
+ _bindReorderableItems: ->
152
+ @ui.reorderableItems = @ui.form.find('.sortable')
153
+ options =
154
+ delay: 150
155
+ items: '> .fields'
156
+ update: (e, ui) =>
157
+ # # TODO: seems like this could be done much simpler with regex
158
+ positionFields = _.select @ui.reorderableItems.find("input[type=hidden]"), (f) ->
159
+ _( $(f).attr('name') ).endsWith('[_position]')
160
+ _.each positionFields, (el, index, list) ->
161
+ $(el).val(positionFields.length - index)
162
+
163
+ @ui.reorderableItems.sortable(options).disableSelection()
164
+
165
+ _renderContent: (html) ->
166
+ if @ui
167
+ @beforeRenderContent?()
168
+
169
+ @ui.content.html(html)
170
+ @ui.form = @ui.content.find('form.simple_form')
171
+
172
+ beforeFormHelpersStart?()
173
+
174
+ if @ui.form.length
175
+ # form related helpers
176
+ Character.Generic.Helpers.startDateSelect(@ui.form)
177
+ Character.Generic.Helpers.startEditor(@ui.content, @options.editorOptions)
178
+ Character.Generic.Helpers.startRedactor(@ui.content, @options.redactorOptions)
179
+ @_bindReorderableItems()
180
+
181
+ $(document).trigger("chr-details-content.rendered", [ @ui.content ])
182
+ $(document).trigger("chr-#{ @module.moduleName }-details-content.rendered", [ @ui.content ])
183
+
184
+ @afterRenderContent?()
185
+
186
+ onRender: ->
187
+ window.shortcuts.register_combo { keys: 'meta s', is_exclusive: true, on_keyup: (event) => @_save() }
188
+
189
+ if @options.fullscreen
190
+ window.shortcuts.register_combo { keys: 'meta e', is_exclusive: true, on_keyup: (event) => @_toggleFullscreen() }
191
+
192
+ @headerView = new @DetailsHeaderView
193
+ model: @model
194
+ title: "New #{ @options.objectName }"
195
+ deletable: @options.deletable
196
+
197
+ @header.show(@headerView)
198
+
199
+ if @model then @$el.addClass('update')
200
+
201
+ @beforeContentRequest?()
202
+
203
+ $.ajax
204
+ type: 'get'
205
+ url: @options.formUrl
206
+ success: (data) =>
207
+ @_renderContent(data)
208
+ error: (xhr, ajaxOptions, thrownError) =>
209
+ chr.execute('showError', xhr)
210
+
211
+ onDestroy: ->
212
+ window.closeDetailsView = null
213
+ if @ui
214
+ @beforeOnClose?()
215
+
216
+ # unbind save
217
+ window.shortcuts.unregister_combo 'meta s'
218
+
219
+ # unbind fullscreen
220
+ @$el.parent().removeClass('fullscreen')
221
+ window.shortcuts.unregister_combo 'meta e'
222
+
223
+ if @ui.form
224
+ # form related helpers
225
+ Character.Generic.Helpers.stopDateSelect(@ui.form)
226
+ Character.Generic.Helpers.stopEditor(@ui.content)
227
+ Character.Generic.Helpers.stopRedactor(@ui.content)
228
+ @ui.reorderableItems.sortable('destroy') if @ui.reorderableItems
229
+
230
+ $(document).trigger("chr-details-content.closed", [ @ui.content ])
231
+ $(document).trigger("chr-#{ @module.moduleName }-details-content.closed", [ @ui.content ])
232
+
233
+ @afterOnClose?()
@@ -0,0 +1,7 @@
1
+ # ---------------------------------------------------------
2
+ # COMPACT OBJECT (used in generic model)
3
+ # ---------------------------------------------------------
4
+
5
+ _.mixin
6
+ compactObject: (o) ->
7
+ _.each o, (v, k) -> if !v then delete o[k] else o
@@ -0,0 +1,21 @@
1
+ # ---------------------------------------------------------
2
+ # SERIALIZE INPUTS
3
+ # ---------------------------------------------------------
4
+
5
+ @Character.Generic.Helpers.serializeDataInputs = ($content, $form) ->
6
+ if $content and $form
7
+ $content.find('[data-input-name]').each (i, el) ->
8
+ dataInputName = $(el).attr('data-input-name')
9
+ if dataInputName
10
+ if $(el).hasClass('character-editor')
11
+ value = $(el).data('editor').serialize()
12
+ else
13
+ value = $(el).html().trim()
14
+
15
+ $hiddenInput = $form.find("input[name='#{ dataInputName }']")
16
+
17
+ if $hiddenInput.length == 0
18
+ $hiddenInput = $("<input type='hidden' name='#{ dataInputName }'>")
19
+ $hiddenInput.appendTo($form)
20
+
21
+ $hiddenInput.val(value)
@@ -0,0 +1,45 @@
1
+ # ---------------------------------------------------------
2
+ # DATE SELECT (rails fix)
3
+ # ---------------------------------------------------------
4
+
5
+ @Character.Generic.Helpers.startDateSelect = ($form)->
6
+ updateDateValue = ($wrapper, $input) ->
7
+ selects = $wrapper.children('select')
8
+
9
+ day = $(selects[0]).val()
10
+ month = $(selects[1]).val()
11
+ year = $(selects[2]).val()
12
+
13
+ $input.val("#{ year }-#{ month }-#{ day }")
14
+
15
+
16
+ # initialize hiddin input and start value
17
+ $form.find('.chr-date-dmy').each (i, el) ->
18
+
19
+ $el = $(this)
20
+ $hiddenInput = $el.children('input[type="hidden"]')
21
+
22
+ if $hiddenInput.length == 0
23
+ dateFieldName = $el.children('select').first()
24
+ .attr('name').replace('(3i)', '')
25
+ .replace('(2i)', '')
26
+ .replace('(1i)', '')
27
+ $hiddenInput = $("<input type='hidden' name='#{ dateFieldName }' />").appendTo($el)
28
+
29
+ updateDateValue($el, $hiddenInput)
30
+
31
+
32
+ # remove bad field names
33
+ $form.find('.chr-date-dmy select').attr('name', '')
34
+
35
+
36
+ # update date on select change
37
+ $form.find('.chr-date-dmy select').on 'change', (e) ->
38
+ $parentDiv = $(this).parent()
39
+ $hiddenInput = $parentDiv.children('input[type="hidden"]').first()
40
+
41
+ updateDateValue($parentDiv, $hiddenInput)
42
+
43
+
44
+ @Character.Generic.Helpers.stopDateSelect = ($form) ->
45
+ $form.find('.chr-date-dmy select').off 'change'
@@ -0,0 +1,11 @@
1
+ # ---------------------------------------------------------
2
+ # EDITOR
3
+ # ---------------------------------------------------------
4
+
5
+ @Character.Generic.Helpers.startEditor = ($content, editorOptions) ->
6
+ options = { viewSelector: '#details_content' }
7
+ _(options).extend(editorOptions)
8
+ $content.find('.character-editor').editor options
9
+
10
+ @Character.Generic.Helpers.stopEditor = ($content) ->
11
+ $content.find('.character-editor').each (i, el) -> $(el).data('editor').destroy()
@@ -0,0 +1,38 @@
1
+ # ---------------------------------------------------------
2
+ # REDACTOR
3
+ # ---------------------------------------------------------
4
+
5
+ window.RedactorPlugins ||= {}
6
+
7
+ RedactorPlugins.gallery =
8
+ init: ->
9
+ @buttonAddBefore('video', 'image', 'Insert Images', @insertImages)
10
+
11
+ insertImages: ->
12
+ @selectionSave()
13
+ chr.execute 'showImages', true, (images) =>
14
+ _.each images.reverse(), (model) =>
15
+ # HACK: this workaround sometimes Rails includes image mount_uploader
16
+ image = model.get('image')
17
+ image = image.image if image.image
18
+ data = { filelink: image.regular.url, filename: '' }
19
+ @imageInsert(data, false)
20
+ @observeImages()
21
+
22
+ @Character.Generic.Helpers.startRedactor = ($content, redactorOptions) ->
23
+ if $.fn.redactor
24
+ $('#details_header').prepend "<div id='redactor_toolbar' class='chr-redactor-toolbar'></div>"
25
+ options =
26
+ formattingPre: false
27
+ convertLinks: false
28
+ cleanup: false
29
+ pastePlainText: true
30
+ plugins: [ 'gallery' ]
31
+ buttons: ['html', 'formatting', 'bold', 'italic', 'deleted', 'unorderedlist', 'orderedlist', 'outdent', 'indent', 'video', 'file', 'table', 'link', 'alignment', 'horizontalrule']
32
+ _(options).extend(redactorOptions)
33
+ $content.find('.character-redactor').redactor(options)
34
+
35
+ @Character.Generic.Helpers.stopRedactor = ($content) ->
36
+ if $.fn.redactor
37
+ $content.find('.character-redactor').redactor('destroy')
38
+ $('#redactor_toolbar').remove()
@@ -0,0 +1,36 @@
1
+ # ---------------------------------------------------------
2
+ # REORDER LIST ITEMS
3
+ # ---------------------------------------------------------
4
+
5
+ @Character.Generic.Helpers.stopReorder = (el) ->
6
+ el.sortable( "destroy" )
7
+
8
+ @Character.Generic.Helpers.startReorder = (el, collection) ->
9
+ updateModelPosition = ($el, position) ->
10
+ object_id = $el.attr('data-id')
11
+ object = collection.get(object_id)
12
+ object.save({ _position: position }, { patch: true })
13
+
14
+ options =
15
+ delay: 150
16
+ placeholder: 'placeholder'
17
+ update: (e, ui) =>
18
+ prev = ui.item.prev()
19
+ next = ui.item.next()
20
+
21
+ if prev.length > 0 and next.length > 0
22
+ prevPosition = parseFloat prev.attr('data-position')
23
+ nextPosition = parseFloat next.attr('data-position')
24
+ newPosition = (prevPosition + nextPosition) / 2
25
+
26
+ else if prev.length > 0 # bottom of the list
27
+ lastPosition = parseFloat prev.attr('data-position')
28
+ newPosition = lastPosition - 10
29
+
30
+ else if next.length > 0 # top of the list
31
+ firstPosition = parseFloat next.attr('data-position')
32
+ newPosition = firstPosition + 10
33
+
34
+ updateModelPosition(ui.item, newPosition)
35
+
36
+ el.sortable(options).disableSelection()