Skip to content

Commit

Permalink
Merge branch 'edit_date_field' of github.com:cedrics/infopark_kicksta…
Browse files Browse the repository at this point in the history
…rter into cedrics-edit_date_field

# By Cedric Sohrauer
# Via Cedric Sohrauer
* 'edit_date_field' of github.com:cedrics/infopark_kickstarter:
  Add inline editing for date

Conflicts:
	lib/generators/cms/kickstart/templates/app/assets/javascripts/editing.js
	tmp/test_app/app/assets/javascripts/editing.js
  • Loading branch information
Falk Köppe committed Aug 26, 2013
2 parents 8a99770 + 8af94ba commit 74e4724
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# v3.1.0
* Added inline editing for CMS date attributes. (Thanks @cedrics)
* Bugfix: Made slideshare widget more robust against invalid slideshare API responses.
* Removed `.widget` and `.editing` CSS classes in the `show.html.haml` and `edit.html.haml` of
widgets. They were not needed and we switched to use the public API provided by the
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org'

gemspec
gemspec
1 change: 1 addition & 0 deletions lib/generators/cms/kickstart/kickstart_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def install_gems

gem_group(:assets) do
gem('less-rails-bootstrap', '~> 2.3')
gem('bootstrap-datepicker-rails')
end

Bundler.with_clean_env do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
//= require jquery_ujs
//= require twitter/bootstrap
//= require infopark_rails_connector
//= require_tree .
//= require bootstrap-datepicker
//= require_tree .
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
jQuery ->
infopark.on 'new_content', ->
cmsEditEnums = $('[data-ip-field-type=enum], [data-ip-field-type=multienum]')

for cmsEditEnum in cmsEditEnums
$(cmsEditEnum).on 'focusout', ->
cmsEditEnum.infopark('save', $(cmsEditEnum).val())


cmsEditDates = $('[data-ip-field-type=date]')

for cmsEditDate in cmsEditDates
dateField = $(cmsEditDate).find('input[type=text]')

$(dateField).datepicker(format: 'yyyy-mm-dd').on 'hide', (event) ->
date = event.date

# Set date hour to 12 to work around complex time zone handling.
date.setHours(12)

$(cmsEditDate).infopark('save', date)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
*= require_self
*= require infopark_rails_connector
*= require bootstrap_and_override
*= require bootstrap-datepicker
*= require_tree .
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ def cms_edit_multienum(object, attribute_name)
def cms_edit_date(object, attribute_name)
value = object.send(attribute_name)

if value
cms_tag(:div, object, attribute_name) do
I18n.l(value)
end
value_string = if value.present?
value.strftime("%Y-%m-%d")
else
''
end

cms_tag(:div, object, attribute_name) do
tag(:input, type: 'text', value: value_string)
end
end


def cms_edit_linklist(object, attribute_name)
linklist = object.send(attribute_name)

Expand Down Expand Up @@ -65,4 +70,4 @@ def cms_options_for_select(obj, attribute)

options_for_select(attribute_definition['values'], obj.send(attribute))
end
end
end
1 change: 1 addition & 0 deletions tmp/test_app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ gem "cells"
gem "utf8-cleaner"
group :assets do
gem "less-rails-bootstrap", "~> 2.3"
gem "bootstrap-datepicker-rails"
end

group :test, :development do
Expand Down
5 changes: 4 additions & 1 deletion tmp/test_app/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ GEM
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-datepicker-rails (1.1.1.7)
railties (>= 3.0)
builder (3.0.4)
cells (3.8.8)
cells (3.8.7)
actionpack (>= 3.0)
railties (>= 3.0)
coderay (1.0.9)
Expand Down Expand Up @@ -221,6 +223,7 @@ DEPENDENCIES
airbrake
better_errors
binding_of_caller
bootstrap-datepicker-rails
cells
coffee-rails (~> 3.2.1)
gravatar_image_tag
Expand Down
3 changes: 2 additions & 1 deletion tmp/test_app/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
//= require infopark_rails_connector
//= require projekktor
//= require projekktor.config
//= require_tree .
//= require bootstrap-datepicker
//= require_tree .
21 changes: 21 additions & 0 deletions tmp/test_app/app/assets/javascripts/editing.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
jQuery ->
infopark.on 'new_content', ->
cmsEditEnums = $('[data-ip-field-type=enum], [data-ip-field-type=multienum]')

for cmsEditEnum in cmsEditEnums
$(cmsEditEnum).on 'focusout', ->
cmsEditEnum.infopark('save', $(cmsEditEnum).val())


cmsEditDates = $('[data-ip-field-type=date]')

for cmsEditDate in cmsEditDates
dateField = $(cmsEditDate).find('input[type=text]')

$(dateField).datepicker(format: 'yyyy-mm-dd').on 'hide', (event) ->
date = event.date

# Set date hour to 12 to work around complex time zone handling.
date.setHours(12)

$(cmsEditDate).infopark('save', date)
3 changes: 2 additions & 1 deletion tmp/test_app/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
*= require infopark_rails_connector
*= require projekktor
*= require bootstrap_and_override
*= require bootstrap-datepicker
*= require_tree .
*/
*/
15 changes: 10 additions & 5 deletions tmp/test_app/app/helpers/editing_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ def cms_edit_multienum(object, attribute_name)
def cms_edit_date(object, attribute_name)
value = object.send(attribute_name)

if value
cms_tag(:div, object, attribute_name) do
I18n.l(value)
end
value_string = if value.present?
value.strftime("%Y-%m-%d")
else
''
end

cms_tag(:div, object, attribute_name) do
tag(:input, type: 'text', value: value_string)
end
end


def cms_edit_linklist(object, attribute_name)
linklist = object.send(attribute_name)

Expand Down Expand Up @@ -65,4 +70,4 @@ def cms_options_for_select(obj, attribute)

options_for_select(attribute_definition['values'], obj.send(attribute))
end
end
end

0 comments on commit 74e4724

Please sign in to comment.