module Gluttonberg module Helpers module FormBuilder include ActionView::Helpers def publisable_dropdown ActiveSupport::Deprecation.warn "f.publisable_dropdown is deprecated and will be removed in Gluttonberg 4.0, use submit_and_publish_controls(form, object, can_publish, schedule_field=true, revisions=true, opts={}) instead." object = self.object val = object.state if val == "not_ready" val = "ready" end @@workflow_states = [ ['Published' , "published" ] ,[ 'Draft' , 'ready' ] , [ "Archived" , 'archived' ] ] object.published_at = Time.zone.now if object.published_at.blank? html = "
" html.html_safe end def publishing_schedule(schedule_field) object = self.object object.published_at = Time.zone.now if object.published_at.blank? html = "" html += schedule_field ? datetime_field("published_at") : hidden_field("published_at") html.html_safe end def datetime_field(field_name,date_field_html_opts = {},time_field_html_opts = {}) date_field_html_opts["data-datepicker"] = "bsdatepicker" unique_field_name = "#{field_name}_#{Gluttonberg::Member.generateRandomString}" date_field_html_opts[:onblur] = "checkDateFormat(this,'.#{unique_field_name}_error');combine_datetime('#{unique_field_name}');" date_field_html_opts[:class] = "" if date_field_html_opts[:class].blank? date_field_html_opts[:class] += " small span2 datefield" time_field_html_opts[:class] = "" if time_field_html_opts[:class].blank? time_field_html_opts[:class] += " small span2 timefield" time_field_html_opts[:onblur] = "checkTimeFormat(this,'.#{unique_field_name}_error');combine_datetime('#{unique_field_name}');" date = time = "" unless self.object.send(field_name).blank? date = self.object.send(field_name).strftime("%d/%m/%Y") time = self.object.send(field_name).strftime("%I:%M %p") end _render "/gluttonberg/admin/shared/datetime_field", { :date_field_html_opts => date_field_html_opts, :time_field_html_opts => time_field_html_opts, :date => date, :time => time, :form => self, :unique_field_name => unique_field_name, :field_name => field_name } end # Assets def asset_browser( field_name , opts = {} ) opts[:asset_id] = asset_id = self.object.send(field_name.to_s) filter = opts[:filter] || "all" opts[:id] = "#{field_name}_#{asset_id}" if opts[:id].blank? asset = if asset_id.blank? nil else Gluttonberg::Asset.where(:id => asset_id).first end locals = { :opts => opts, :asset => asset, :field_name => field_name, :form => self } _render("/gluttonberg/admin/asset_library/shared/asset_browser", locals) end def asset_tag(asset , thumbnail_type = nil) unless asset.blank? path = thumbnail_type.blank? ? asset.url : asset.url_for(thumbnail_type) tag(:img , :class => asset.name , :alt => asset.name , :src => path) end end def clear_asset( field_name , opts = {} ) asset_id = self.object.send(field_name.to_s) opts[:id] = "#{field_name}_#{asset_id}" if opts[:id].blank? view = ActionView::Base.new(ActionController::Base.view_paths) view.extend ApplicationHelper view.clear_asset_tag(field_name, opts) end private def _render(partial, assigns) view = ActionView::Base.new(ActionController::Base.view_paths, assigns) view.extend ApplicationHelper view.render(:partial => partial, :locals => assigns) end end #FormBuilder ActionView::Helpers::FormBuilder.send(:include , Gluttonberg::Helpers::FormBuilder) end end