class Admin::PagesController < Admin::ItemsController # helper Admin::PagePartsHelper # include Admin::FrontendWidgetInterface def create @item = Page.new(params[:page]) if @item.module_app && @item.module_app.key == 'page_content' @item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id ) end if @item.save render 'admin/items/reload_items' else @error = error_messages_for(@item) render 'admin/items/form_error' end end def update @item = Page.find(params[:id]) if @item.module_app && @item.module_app.key == 'page_content' && @item.page_contexts.blank? @item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id ) end if @item.update_attributes(params[:page]) render 'admin/items/reload_items' else @error = error_messages_for(@item) render 'admin/items/form_error' end end def get_display_style @item = Page.find(params[:id]) rescue nil @module_app = ModuleApp.find(params[:module_id]) rescue nil if @module_app if params[:val].eql?("default_widget") @checked_style = @item.frontend_style.present? ? @item.frontend_style : nil if @item && @item.app_frontend_url.eql?("default_widget") @enabled_styles = @module_app.get_default_widget["enabled_styles"] @widget_fields = @module_app.widget_fields.collect do |widget_field| label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}") [label, widget_field[0], class: widget_field[2]] end @class_options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]} @partial = 'default_front' else @frontend_styles = @module_app.app_pages[params[:val]]["style"] rescue nil @partial = 'custom_front' if @frontend_styles.present? end end end def get_page_setting_json begin page = Page.find(params[:id]) design = {main: page.design_id.to_s, sub: page.theme_id.to_s} m = {} m["main"] = page.module_app_id.to_s m["sub"] = page.app_frontend_url m["category"] = page.category.present? ? [0, page.category.map{|c| c.to_s}] : [1] m["tags"] = page.tag.present? ? [0, page.tag.map{|c| c.to_s}] : [1] m["public"] = page.is_published ? 1 : 0 m["link"] = @site_valid_locales.inject([]) do |link, locale| link << [locale, (page.enabled_for && page.enabled_for.include?(locale)) ? 1 : 0, (page.menu_enabled_for && page.menu_enabled_for[locale]) ? 1 :0] end m["count"] = page.frontend_data_count render json: JSON.pretty_generate({design: design, module: m}) rescue render :json => {error: ''}, status: 422 end end end