');
@@ -969,11 +1013,14 @@ var orbitDesktop = function(dom){
bindSecondaryHandlers();
}
- $.getJSON("/desktop/journal_pages/get_journals_json",function(journals){
- journalData = eval(journals);
- journalview();
- bindHandlers();
- })
+ var getData = function(){
+ $.getJSON("/desktop/journal_pages/get_journals_json",function(journals){
+ journalData = eval(journals);
+ journalview();
+ bindHandlers();
+ })
+ }
+ getData();
}
this.initializeJournalPapers.addpaper = function(){ // to open add pages in journal papers page
diff --git a/app/assets/stylesheets/member.css b/app/assets/stylesheets/member.css
index add8774a..031b271c 100644
--- a/app/assets/stylesheets/member.css
+++ b/app/assets/stylesheets/member.css
@@ -280,7 +280,7 @@
margin-top: 8px;
}
.nav-tabs li a {
- padding-right: 32px;
+ /*padding-right: 32px;*/
}
.user-role {
@@ -314,7 +314,8 @@
float: left;
}
.role-block .nav-pills {
- margin-bottom: 0;g
+ margin-bottom: 0;
+ margin-left: 10px;
}
.role-block .nav-pills > li > a {
margin-top: 0;
@@ -345,7 +346,13 @@
-moz-border-radius: 0 3px 3px 0;
border-radius: 0 3px 3px 0;
}
+.input-append > .active {
+ display: inline-block;
+}
+.input-append .active {
+ background-color: transparent;
+ border-color: transparent;
+}
.language-swich .tab-pane {
- margin-bottom: 5px;
- margin-right: 10px;
+ /*margin-bottom: 5px;*/
}
\ No newline at end of file
diff --git a/app/assets/stylesheets/site-map.css b/app/assets/stylesheets/site-map.css
index 53e94c1f..c7a95b45 100644
--- a/app/assets/stylesheets/site-map.css
+++ b/app/assets/stylesheets/site-map.css
@@ -111,7 +111,7 @@
.role-block .form-horizontal .controls {
margin-left: 120px;
}
-.role-block .form-horizontal .controls>.input-append {
+.role-block .form-horizontal .controls .input-append {
margin-bottom: 10px;
}
.role-block .form-horizontal legend .onoff {
diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb
index 7f49faf2..cae3f19c 100644
--- a/app/controllers/admin/ad_banners_controller.rb
+++ b/app/controllers/admin/ad_banners_controller.rb
@@ -1,7 +1,7 @@
class Admin::AdBannersController < OrbitBackendController
- layout "new_admin"
+
before_filter :force_order_for_visitor,:only=>[:index]
- #before_filter :force_order_for_user,:except => [:index]
+ before_filter :force_order_for_user,:except => [:index]
before_filter :for_app_sub_manager,:except => [:index]
before_filter :for_app_manager,:except => [:index,:show,:update,:realtime_preview]
diff --git a/app/controllers/admin/ad_images_controller.rb b/app/controllers/admin/ad_images_controller.rb
index e4749ade..fc25c5d5 100644
--- a/app/controllers/admin/ad_images_controller.rb
+++ b/app/controllers/admin/ad_images_controller.rb
@@ -1,7 +1,13 @@
-class Admin::AdImagesController < OrbitBackendController
- layout 'new_admin'
- before_filter :authenticate_user!
- before_filter :for_app_sub_manager
+class Admin::AdImagesController < Admin::AdBannersController
+
+ # before_filter :force_order_for_user
+ # before_filter :for_app_sub_manager
+ # before_filter :for_app_manager
+
+ def initialize
+ super
+ @app_title = "ad_banner"
+ end
def edit
@ad_banner = AdBanner.find params[:ad_banner_id]
diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb
index 0b94317e..a3824950 100644
--- a/app/controllers/admin/designs_controller.rb
+++ b/app/controllers/admin/designs_controller.rb
@@ -52,7 +52,7 @@ class Admin::DesignsController < OrbitBackendController
case params[:type]
when 'layout', 'css_default', 'css_reset'
@object = @design.send(params[:type])
- when 'image', 'javascript', 'theme'
+ when 'javascripts', 'themes'#, 'images'
@object = @design.send(params[:type]).find(params[:object_id])
end
diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb
index 7c7b4030..5eece0ca 100644
--- a/app/controllers/admin/links_controller.rb
+++ b/app/controllers/admin/links_controller.rb
@@ -1,10 +1,4 @@
-class Admin::LinksController < ApplicationController
-
- layout "site_editor"
-
- before_filter :authenticate_user!
- before_filter :find_parent_item
- before_filter :is_admin?
+class Admin::LinksController < Admin::ItemsController
def show
@item ||= Link.find(params[:id])
diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb
index ed2748c2..f78c6ae3 100644
--- a/app/controllers/admin/page_parts_controller.rb
+++ b/app/controllers/admin/page_parts_controller.rb
@@ -5,6 +5,8 @@ class Admin::PagePartsController < ApplicationController
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :set_current_item
+
+ helper 'admin/items'
def show
@part = PagePart.find(params[:id])
diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb
index cf935a09..0e58a00f 100644
--- a/app/controllers/admin/pages_controller.rb
+++ b/app/controllers/admin/pages_controller.rb
@@ -1,11 +1,4 @@
-class Admin::PagesController < ApplicationController
-
- layout "site_editor"
-
- before_filter :authenticate_user!
- before_filter :find_parent_item
- before_filter :is_admin?
- before_filter :set_current_item
+class Admin::PagesController < Admin::ItemsController
def show
@item = Page.find(params[:id])
@@ -40,7 +33,7 @@ class Admin::PagesController < ApplicationController
@frontend_path = @item.app_frontend_url ? @item.app_frontend_url : @module_app.widgets.keys[0]
- if @module_app.widgets.any?{|b| b.class == Array}
+ if @module_app && @module_app.widgets && @module_app.widgets.any?{|b| b.class == Array}
@frontend_style = @module_app.widgets[@frontend_path] if !@frontend_path.blank? && !@module_app.widgets.blank?
end
diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb
index a277c2e1..8c5ec93a 100644
--- a/app/controllers/admin/users_new_interface_controller.rb
+++ b/app/controllers/admin/users_new_interface_controller.rb
@@ -78,7 +78,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
# @user.attribute_values.build(value)
# }
# @user.rebuild_sub_roles_from_attribute_values!(attribute_values)
- binding.pry
+ # binding.pry
if @user.save
flash[:notice] = t('create.success.user')
redirect_to :action => :index
@@ -103,6 +103,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
def update
@user = User.find(params[:id])
+
@user.update_attributes(params[:user])
attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_values_key)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e82365e5..23474c5c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -8,6 +8,8 @@ class ApplicationController < ActionController::Base
helper :admin
before_filter :set_locale, :set_site
+ helper_attr :site_valid_locales
+
def set_current_user
User.current = current_or_guest_user
end
diff --git a/app/controllers/desktop/journal_pages_controller.rb b/app/controllers/desktop/journal_pages_controller.rb
index c9d71e64..ee7a7167 100644
--- a/app/controllers/desktop/journal_pages_controller.rb
+++ b/app/controllers/desktop/journal_pages_controller.rb
@@ -21,6 +21,7 @@ class Desktop::JournalPagesController < ApplicationController
respond_to do |format|
format.html { render :layout => false}
end
+
end
def edit
@@ -39,14 +40,19 @@ class Desktop::JournalPagesController < ApplicationController
@writing_journal = WritingJournal.new(params[:writing_journal])
if @writing_journal.save
- respond_to do |format|
- format.html { redirect_to desktop_journal_pages_url, :layout => false, notice: 'User was successfully created.'}
- # format.json { render json: @writing_journal, status: :created, location: @writing_journal}
- # format.js
- end
+ # respond_to do |format|
+ # format.html { redirect_to desktop_journal_pages_url, :layout => false, notice: 'User was successfully created.'}
+ # # format.json { render json: @writing_journal, status: :created, location: @writing_journal}
+ # # format.js
+ # end
+ render :json => {"success"=>true,"msg"=>"Paper successfully saved!"}.to_json
else
+ render :json => {"success"=>false,"msg"=>"Saving failed!"}
end
- end
+
+ end
+ render :json => {"success"=>true,"msg"=>"Paper successfully saved!"}.to_json
+
end
def update
@@ -74,19 +80,19 @@ class Desktop::JournalPagesController < ApplicationController
if not file.nil?
file_type = MIME::Types.type_for(file).first.to_s.split("/")[1]
- case file_type
- when "jpg", "jpeg"
- type = "jpg"
- when "text", "txt"
- type = "txt"
- when "pdf"
- type = "pdf"
- when "png"
- type = "png"
- else "readme"
- end
+ # case file_type
+ # when "jpg", "jpeg"
+ # type = "jpg"
+ # when "text", "txt"
+ # type = "txt"
+ # when "pdf"
+ # type = "pdf"
+ # when "png"
+ # type = "png"
+ # else "readme"
+ # end
- file_type = "/assets/ft-icons/#{type}/#{type}-48_32.png"
+ file_type = "/assets/ft-icons/#{file_type}/#{file_type}-48_32.png"
else
file_type = ""
end
diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb
index 8f78ea62..530415ba 100644
--- a/app/controllers/orbit_backend_controller.rb
+++ b/app/controllers/orbit_backend_controller.rb
@@ -11,7 +11,7 @@ class OrbitBackendController < ApplicationController
layout 'new_admin'
def setup_vars
- @app_title = controller_path.split('/')[1].singularize
+ @app_title ||= controller_path.split('/')[1].singularize
@module_app ||= ModuleApp.first(conditions: {:key => @app_title} )
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 76f0f933..07d6b577 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -15,8 +15,11 @@ module ApplicationHelper
end
def create_guest_user
- u = User.create(:name => "guest", :email => "guest_#{Time.now.to_i}#{rand(99)}@example.com")
- u.admin = false
+ u = nil
+ User.without_callback(:create, :before, :initialize_desktop) do
+ u = User.create(:name => "guest", :email => "guest_#{Time.now.to_i}#{rand(99)}@example.com")
+ end
+ u.admin = false
u.save(:validate => false)
u
end
diff --git a/app/helpers/attribute_fields_helper.rb b/app/helpers/attribute_fields_helper.rb
index c35c7370..ded899ad 100644
--- a/app/helpers/attribute_fields_helper.rb
+++ b/app/helpers/attribute_fields_helper.rb
@@ -1,12 +1,12 @@
#encoding: utf-8
-# require ActionView::Helpers::FormTagHelper
-
module AttributeFieldsHelper
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormOptionsHelper
include ActionView::Helpers::DateHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::RenderingHelper
+ include ActionView::Context
+ include OrbitBasis::RenderAnywhere
def block_helper(user,index,disable = false)
unless self.disabled
@@ -28,37 +28,25 @@ module AttributeFieldsHelper
end
def render_address
- #NP
control_group_wrapper do |key,value|
- result = '
'.html_safe
+ value = (can_muti_lang_input? ? @prefiled_value[key] : @prefiled_value) rescue nil
+ key_field = can_muti_lang_input? ? "[#{key}]" : ""
+ place_holder= @panel_setting["placeholder"][key] rescue ''
+ result = text_area_tag(get_field_name_base + key_field, value,@markup_options.merge({:placeholder=>place_holder,:for=>key}))
- if(add_more and value.is_a?(Array))
- values = value
- result << values.each_with_index.collect do |value,index|
- text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options)
- end.join.html_safe
- else
- result << text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,@markup_options)
- end
-
- result << ('').html_safe
- result << ''.html_safe
- result << '
'.html_safe
- result << gen_modal_dialog
+ add_ext= @attribute_value.address_ext[key] rescue {}
+
+ result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][county]",add_ext["county"],:class=>"county_#{key}")
+ result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][street_address]",add_ext["street_address"],:class=>"street_address_#{key}")
+ result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][city]",add_ext["city"],:class=>"city_#{key}")
+ result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][zip]",add_ext["zip"],:class=>"zip_#{key}")
+ result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][country]",add_ext["country"],:class=>"country_#{key}")
+ result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][indicator]",add_ext["indicator"],:class=>"indicator_#{key}")
end
end
def render_checkbox
-
@prefiled_value ||=[]
- # begin
- # markup_value = eval(self.markup_value)
- # rescue
- # markup_value = self.markup_value
- # ensure
- # markup_value ||= {}
- # end
-
control_group_wrapper do
a = self[:option_list].collect do |key,value|
label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", true , (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
@@ -67,23 +55,15 @@ module AttributeFieldsHelper
end
def render_date
- #NP
control_group_wrapper{date_select(get_field_name_base,nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")}
end
def render_date_durnation #Need re-write low priority
-
+
end
def render_radio_button
@prefiled_value ||=[]
- # begin
- # markup_value = eval(self.markup_value)
- # rescue
- # markup_value = self.markup_value
- # ensure
- # markup_value ||= {}
- # end
control_group_wrapper do
self[:option_list].collect do |key,value|
label_tag(key,radio_button_tag(get_field_name_base, key , (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
@@ -92,106 +72,148 @@ module AttributeFieldsHelper
end
def render_select
-
- prompt = @panel_setting[:prompt][I18n.locale] rescue nil
+ prompt = @panel_setting["initial"][I18n.locale.to_s] rescue nil
@markup_options.merge!(:prompt => prompt) unless prompt.nil?
- # markup_value = (self.markup_value.is_a?(Hash) ? self.markup_value : eval(self.markup_value) )rescue {}
- # check self[:option_list].collect{|p| [p[1][I18n.locale.to_s],p[0]]}
control_group_wrapper{select_tag( get_field_name_base,options_for_select(self.option_list.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),@markup_options)} rescue ""
end
def render_text_area
control_group_wrapper do |key,value|
- if(add_more and value.is_a?(Hash))
- values = value
- values.each_with_index.collect do |value,index|
- place_holder= @panel_setting["placeholder"][key]
- text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
- end.join.html_safe
- else
- value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value
- key = can_muti_lang_input ? "[#{key}]" : ""
+ value = can_muti_lang_input? ? @prefiled_value[key] : @prefiled_value
+ key = can_muti_lang_input? ? "[#{key}]" : ""
place_holder= @panel_setting["placeholder"][I18n.locale.to_s] rescue ''
text_area_tag(get_field_name_base + key, value,@markup_options.merge(:placeholder=>place_holder))
- end
end
end
def render_text_field
- control_group_wrapper do |key,value|
- if(add_more)
- values = value
- result = ""
- unless values.nil?
- result = values.each_with_index.collect do |value,index|
- place_holder= @panel_setting["placeholder"][key]
- text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
- end.join.html_safe
- end
- result
- else
- value = (can_muti_lang_input ? @prefiled_value[key] : @prefiled_value) rescue nil
- key_field = can_muti_lang_input ? "[#{key}]" : ""
- place_holder= @panel_setting["placeholder"][key] rescue ''
- text_field_tag(get_field_name_base + key_field, value,@markup_options.merge(:placeholder=>place_holder))
- end
- end
+ control_group_wrapper do |key,value|
+ add_more_blank = can_add_more ? "[]" : ""
+ key_field = can_muti_lang_input? ? "[#{key}]" : ""
+ place_holder= @panel_setting["placeholder"][key] rescue ''
+ text_field_tag([get_field_name_base,add_more_blank,key_field].join, value,@markup_options.merge(:placeholder=>place_holder))
+ end
end
protected
- def lang_panel_control_wrapper(&block)
- result = '
'
- result << '
'
- result << controls_wrapper{yield}
- result << '
'
- result << '
'
- result.html_safe
+
+ def lang_panel_tabbable_wrapper(add_more_params,&block)
+ add_more_counter = ''
+ content_tag :div,:class=>"tabbable" do
+ tmp = content_tag :div,:class=> (add_more || self.markup=='address') ? "tab-content input-append" : "tab-content" do
+ buff = VALID_LOCALES.collect do |key|
+ value = @prefiled_value[key] rescue nil
+ div_class_ary = ["tab-pane" ,"fade",key,get_pairing_tab_class({})]
+
+
+ if can_add_more
+ add_more_value = add_more_params[0][:value]
+ add_more_counter = add_more_params[0][:counter]
+ value = add_more_value[key] rescue nil
+ div_class_ary << "add_more_item_#{add_more_counter}"
+ end
+
+ div_class = div_class_ary.join(" ")
+ div_class << (key == I18n.locale.to_s ? " active in" : '')
+ content_tag(:div,yield(key,value),:class=>div_class)
+ end# of VALID_LOCALES.collect for tabed input
+ buff << link_to((content_tag :i,'',:class=>'icon-edit'),"##{get_pairing_tab_class({})}_m_window",:class=>'btn edit-btn',:type=>'button',:data=>{:toggle=>"modal"}) if self.markup == 'address'
+ buff << link_to((content_tag :i,'',:class=>'icon-trash'),"#") if self.add_more
+
+
+ # buff << '' if self.add_more
+ buff.join("\n").html_safe
+ end
+ tmp << content_tag(:ul,:class=> 'nav nav-pills') do
+ VALID_LOCALES.each.collect do |key|
+ # link_entry = self.add_more ? "#{add_more_tab(:tab_btn,loop_counter,key)}" : "#tab"+id.to_s+"_#{key}"
+ link_entry_ary = [".#{get_pairing_tab_class({})}",".#{key}"]
+ # link_entry_ary << ".add_more_item_#{add_more_counter}" if can_add_more
+ link_entry = link_entry_ary.join
+ content_tag(:li,link_to(I18n.t("langs."+key),link_entry,:data=>{:toggle=>"tab"}),:class=>(key == I18n.locale.to_s ? "active" : nil),:for=>key)
+ end.join.html_safe # of VALID_LOCALES.collect for tabs
+ end # of content ul
+ end
end
- def controls_wrapper(&block)
- result = "
"
- if can_muti_lang_input
- result << "
"
- result << "
"
-
- VALID_LOCALES.collect do |key|
- value = @prefiled_value[key.to_s] rescue nil
- div_class = ["tab-pane" ,"fade"].join(" ")
- div_class << (key == I18n.locale.to_s ? " active in" : '')
- result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}")
- end
- result << "
"
- result << "
"
- VALID_LOCALES.each do |key|
- result << content_tag(:li,link_to(I18n.t(:_locale, :locale => key),"#tab"+id.to_s+"_#{key}",:data=>{:toggle=>"tab"}),:class=>(key == I18n.locale.to_s ? "active" : nil))
+ def controls_wrapper(*add_more_params,&block)
+ content_tag :div,:class=>'controls' do
+ result = ''
+ add_more_counter = ""
+
+ if can_add_more
+ add_more_counter = add_more_params[0][:counter]
+ add_more_value = add_more_params[0][:value]
end
- result << "
"
- result << "
"
- # @prefiled_value.collect do |key,value|
- # result << yield(key,value)
- # end
+
+
+
+ if can_muti_lang_input?
+ result << lang_panel_tabbable_wrapper(add_more_params,&block)
+ result << gen_modal_dialog if self.markup == "address"
else
- result << yield
+
+ value = case can_add_more
+ when true
+ add_more_params[0]
+ else
+ @prefiled_value
+ end
+
+ result << yield(nil,value)
end
- if can_add_more
- result << ''
- result << ' Add'
- result << ''
- end
- result << "
"
- result.html_safe
- end
+
+ result.html_safe
+ end # of controls div
+ end # of def controls_wrapper(&block)
def control_group_wrapper(&block)
- div_class = can_muti_lang_input ? "control-group language-swich" : "control-group"
- temp = label + controls_wrapper(&block)
+ div_class = can_muti_lang_input? ? "control-group language-swich" : "control-group"
+ result =""
+ case self.markup
+ when "text_field"
+ if can_add_more
+ multipleInput_ary = %w{multipleInput editMore}
+ add_more_seri = "add_more_group_#{id}"
+ multipleInputs = content_tag :div,:class=> multipleInput_ary.join(' ') ,:ext_class=>get_pairing_tab_class({}) do
+ @attribute_value.add_more_counter.times.collect do |t|
+ controls_wrapper(:value=>(@prefiled_value[t] rescue nil),:counter=>t,&block)
+ end.join("\n").html_safe # of add_more fields
+ end # of div multipleInput editMore
+ result = label + multipleInputs + add_more_unt
+ # result = label + 一堆的輸入框(要用 multipleInput editMore 包起來) + add_more btn + hidden_fields
+ else
+ temp = label + controls_wrapper(&block)
+ result = content_tag(:div,temp,:class=>div_class)
+ end
+ when "address"
- result = content_tag(:div,temp,:class=>div_class)
- result << end_block
+ address = content_tag :div,:class=>"multipleInput editMore" do
+ controls_wrapper(&block)
+ end # of div multipleInput editMore
+ result = label + address
+ else
+ temp = label + controls_wrapper(&block)
+ result = content_tag(:div,temp,:class=>div_class)
+ end
+ result << end_block
result.html_safe
end
+
+ def add_more_unt
+ temp_field_name = get_basic_field_name_base + '[temp]'
+ add_more = content_tag :div,:class=> 'controls' do
+ content_tag :span,:class=> 'help-block' do
+ content = link_to (content_tag :i,I18n.t("admin.infos.add"),:class=>"icon-plus-sign"),"#",:class=>'addinput'
+ content << hidden_field_tag("#{temp_field_name}[count]",@attribute_value.add_more_counter ,:class=>"list_count")
+ content << hidden_field_tag("#{temp_field_name}[count]",get_basic_field_name_base,:class=>"field_name")
+ content
+ end # of span
+ end # of div
+ end
+
def end_block
if @new_attribute
hidden_field_tag(get_basic_field_name_base+"[attribute_field_id]",id,:for=>"field_#{@index}")
@@ -200,6 +222,23 @@ protected
end
end
+ def add_more_tab(mode,counter,key)
+ case mode
+ when :input_field
+ get_pairing_tab_class(:suffix=>['','tab'+counter.to_s,key].join('-'))
+ when :tab_btn
+ ".#{get_pairing_tab_class(:suffix=>['','tab'+counter.to_s,key].join('-'))}"
+ end
+ end
+
+ def get_pairing_tab_class(opts)
+ prefix = opts[:prefix]
+ suffix = opts[:suffix]
+ str = get_basic_field_name_base.gsub("[","-").gsub("]",'')
+ str = prefix.nil? ? str : prefix+ str
+ suffix.nil? ? str : str + suffix
+ end
+
def get_basic_field_name_base
if @new_attribute
"user[new_attribute_values][#{@index}]"
@@ -216,36 +255,30 @@ protected
label_tag(key,title,:class=>"control-label",:func => "field_label")
end
- def can_muti_lang_input
- LIST[:markups][markup]["muti_lang_input_supprt"] #and locale
+ def can_muti_lang_input?
+ if self.markup == "address"
+ return true
+ else
+ LIST[:markups][markup]["muti_lang_input_supprt"] and !(get_data["cross_lang"] == "true")
+ end
end
def can_add_more
- locale and LIST[:markups][markup]["ext_support"] && add_more
+ if self.markup == "address"
+ return false
+ else
+ locale and LIST[:markups][markup]["ext_support"] && add_more
+ end
end
-def render_anywhere(partial, assigns)
- view = ActionView::Base.new(Rails::Configuration.new.view_path, assigns)
- ActionView::Base.helper_modules.each { |helper| view.extend helper }
- view.extend ApplicationHelper
- view.render(:partial => partial)
-end
-
-def gen_modal_dialog
- result = '
'
- result << '
'
- result << ''
- result << '
'+title+'
'
- result << '
'
- result << '
'
- result << '
One fine body…
'
- result << '
'
- result << ''
- result << '
'
- result.html_safe
-end
+ def gen_modal_dialog
+ render_anywhere("shared/attribute_field/address_modal_dialog",{
+ :field_name=>title,
+ :html_id=>"#{get_pairing_tab_class({})}_m_window",
+ :btn_class => "#{get_pairing_tab_class({})}",
+ :field_name_basic => get_basic_field_name_base
+ }
+ )
+ end
end
\ No newline at end of file
diff --git a/app/helpers/attribute_values_helper.rb b/app/helpers/attribute_values_helper.rb
new file mode 100644
index 00000000..f2ea0832
--- /dev/null
+++ b/app/helpers/attribute_values_helper.rb
@@ -0,0 +1,68 @@
+module AttributeValuesHelper
+ def show_west_calender
+ date = get_date
+ case self.attribute_field["typeC"]["format"]
+ when 'format1' # Y/M/D h:m
+ date.strftime("%Y/%m/%d %H:%M")
+ when 'format2' # Y/M/D
+ date.strftime("%Y/%m/%d")
+ when 'format3' # Y/M
+ date.strftime("%Y/%m")
+ when 'format4' # Y
+ date.strftime("%Y")
+ end # of case west cal format
+ end
+
+ def show_minguo_calendar
+ get_minguo
+ date = get_date
+ year_str = ""
+ unless date.year == 1912
+ m_year = (date.year - 1912).abs.to_s + I18n.t("admin.infos.date.minguo_calendar.year")
+ year_str = minguo_format_year(m_year)
+ end
+ get_minguo_year + minguo_m_y_d_time
+ end
+
+ def get_minguo_year
+ date = get_date
+ m_year = (date.year - 1911).abs
+ year_end = I18n.t("admin.infos.date.minguo_calendar.year")
+ case
+ when date.year <1912
+ I18n.t("admin.infos.date.minguo_calendar.before") + (m_year+1).to_s + year_end
+ when date.year ==1912
+ I18n.t("admin.infos.date.minguo_calendar.first_year")
+ when date.year >1912
+ I18n.t("admin.infos.date.minguo_calendar.after")+ (m_year).to_s + year_end
+ end # of case tw_claendar year
+ end
+
+ def minguo_m_y_d_time
+ date = get_date
+ case self.attribute_field["typeC"]["format"]
+ when 'format1' # Y/M/D h:m
+ date.strftime(" %m/%d %H:%M")
+ when 'format2' # Y/M/D
+ date.strftime(" %m/%d")
+ when 'format3' # Y/M
+ date.strftime(" %m#{I18n.t("admin.infos.date.minguo_calendar.month")}")
+ when 'format4' # Y
+ ''
+ end # of case
+ end
+
+ def get_date_by_format
+ case I18n.locale
+ when :zh_tw
+ case
+ when self.attribute_field["typeC"]["claendar"] == "west_claendar"
+ show_west_calender
+ when self.attribute_field["typeC"]["claendar"] == "tw_claendar"
+ show_minguo_calendar
+ end #case self.attribute_field["typeC"]["claendar"]
+ when :en
+ show_west_calender
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/models/design/design.rb b/app/models/design/design.rb
index 0013082d..aa43368a 100644
--- a/app/models/design/design.rb
+++ b/app/models/design/design.rb
@@ -11,10 +11,10 @@ class Design
has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
has_one :layout, :autosave => true, :dependent => :destroy
has_one :css_reset, :autosave => true, :dependent => :destroy
- has_many :images,as: :imgs, :autosave => true, :dependent => :destroy
+ has_many :images, as: :imgs, :autosave => true, :dependent => :destroy
has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
has_many :pages
- has_many :themes, as: :css, :autosave => true, :dependent => :destroy
+ has_many :themes, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
accepts_nested_attributes_for :javascripts, :allow_destroy => true
diff --git a/app/models/design/stylesheet.rb b/app/models/design/stylesheet.rb
index 5e9a5775..76fdff78 100644
--- a/app/models/design/stylesheet.rb
+++ b/app/models/design/stylesheet.rb
@@ -7,7 +7,12 @@ class Stylesheet < DesignFile
# self.remove_file!
# self.remove_file_orig!
names = {}
- images = self.css.images
+ case self._type
+ when 'Theme'
+ images = self.design.images
+ when 'CssDefault'
+ images = self.css.images
+ end
content.scan(/(?<=url)(.*?)(?=\))/){
css_name = $1.gsub(' ','').gsub('(','')
unless names.has_key?(css_name)
diff --git a/app/models/design/theme.rb b/app/models/design/theme.rb
index 61a621c0..0935fe12 100644
--- a/app/models/design/theme.rb
+++ b/app/models/design/theme.rb
@@ -1,6 +1,6 @@
class Theme < Stylesheet
- belongs_to :css, polymorphic: true
+ belongs_to :design
protected
diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb
index a94a38a2..9442deac 100644
--- a/app/models/user/attribute_field.rb
+++ b/app/models/user/attribute_field.rb
@@ -1,5 +1,4 @@
class AttributeField
-
include Mongoid::Document
include Mongoid::Timestamps
include ::AttributeFieldsHelper
@@ -8,28 +7,24 @@ class AttributeField
field :markup ,:default=>"text_field"
field :option_list ,:type => Hash,:default => {}
field :markup_options,:type => Hash
- # field :locale, :type => Boolean, :default => true
- # field :list_options, :type => Array
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :to_delete,:type=> Boolean,:default => false
- field :typeA,:type=> Hash,:default=>{}
+ field :typeA,:type=> Hash,:default=>{:cross_lang=>false}
field :typeB,:type=> Hash,:default=>{}
- field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar"}
- field :typeD,:type=> Hash,:default=>{}
+ field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar",:format=>"format3"}
+ field :typeD,:type=> Hash,:default=>{:cross_lang=>false}
field :typeE,:type=> Hash,:default=>{}
-
-
- #field :title, localize: true
-
field :title, localize: true
-
belongs_to :attribute
- # belongs_to :role
has_many :attribute_values,:autosave => true, :dependent => :destroy
before_save :check_option_list
- # validates_uniqueness_of :key
+
+ def markup_value
+ get_data["option_list"]
+ end
+
def add_more
(get_data["add_more"] == "true" ? true : false) rescue false
end
@@ -47,12 +42,6 @@ class AttributeField
(self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false
end
- def markup_value=(var)
- if !self_defined_markup_options?
- self[:markup_value] = (eval(var) rescue {})
- end
- end
-
def option_list
if self_defined_markup_options?
#Class need to have corresponding field and value agent
@@ -66,8 +55,6 @@ class AttributeField
end
end
-
-
def markup_options=(var)
self[:markup_options] = (eval(var) rescue {})
end
@@ -82,7 +69,7 @@ class AttributeField
end
def role
- self.attribute.role
+ self.attribute.role
end
def panel
@@ -94,51 +81,18 @@ class AttributeField
end
- # def title_translations
- # if locale
- # return self.locale_title_translations
- # else
- # return self[:neutral_title] #Hash[VALID_LOCALES.map{|d| [d,neutral_title]}]
- # end
- # end
- # def title_translations=(var)
- # if locale
- # self.locale_title_translations = var
- # end
- # end
+ def typeA=(var)
+ check_add_more_convert(var)
+ check_cross_lang_convert(var,"typeA")
+ self["typeA"] = var
+ end
- # def title
- # if locale
- # return self.locale_title
- # else
- # return self.neutral_title
- # end
- # end
+ def typeD=(var)
+ check_cross_lang_convert(var,"typeD")
+ self["typeD"] = var
+ end
- # def check_title
- # if locale
- # self.locale_title_translations = self[:temp_title]
- # else
- # self.neutral_title = self[:temp_title]
- # end
- # self.unset("temp_title")
- # end
-
- # def title=(var)
- # self["temp_title"] = var
- # end
-
- # # Convert the string list_options into an array
- # def select_list_options=(var)
- # self.list_options = var.gsub(' ', '').split(',')
- # end
-
- # # Convert the array list_options into a string
- # def select_list_options
- # self.list_options.to_a.join(', ')
- # end
-
def is_built_in?
self.built_in
end
@@ -149,7 +103,82 @@ class AttributeField
protected
def check_option_list
- self[:option_list] = self[panel]["option_list"]
+ self[:option_list] = self[panel]["option_list"] rescue nil
+ end
+
+ def add_more_convert(opt)
+ case opt
+ when :to_add_more
+ self.attribute_values.each do |av|
+ VALID_LOCALES.each do |loc|
+ splited_str = av[loc].split(",") rescue []
+ av["val"] = [] if av["val"].nil?
+ splited_str.each_with_index{|value,index| av["val"][index] = av["val"][index].nil? ? {loc=>value} : av["val"][index].merge(loc=>value) }
+ end
+ av.unset_all_lang_values
+ av.save
+ end #of self.attribute_values.each
+ when :to_no_add_more
+ self.attribute_values.each do |av|
+ VALID_LOCALES.each do |loc|
+ if av["val"].kind_of? Array
+ av[loc] = av["val"].collect{|t| t[loc]}.join(",")
+ else
+ av[loc] = av["val"]
+ end
+ end
+ av.unset("val")
+ av.save
+ end #of self.attribute_values.each
+ end
+ end
+
+ def cross_lang_convert(opt)
+ case opt
+ when :to_cross_lang
+ self.attribute_values.each do |av|
+ if add_more
+ av["val"] = av["val"].collect{|t| t.invert.keys.join(",")}
+ else
+ av["val"] = VALID_LOCALES.collect{|t| av[t]}.join(",")
+ av.unset_all_lang_values
+ end
+ av.save
+ end #of self.attribute_values.each
+ when :to_no_cross_lang
+ default_locale = I18n.default_locale.to_s
+ self.attribute_values.each do |av|
+ if add_more
+ av["val"] = av["val"].collect{|t| {default_locale => t} } #unless av["val"].nil?
+ else
+ av[default_locale] = av["val"]
+ av.unset("val")
+ end
+ av.save
+ end #of self.attribute_values.each
+ end
+ end
+
+ def check_add_more_convert(var)
+ if self["typeA"]["add_more"] != var["add_more"]
+ case var["add_more"]
+ when "true" #from no-add_more to add_more
+ add_more_convert(:to_add_more)
+ else #from add_more to no-add_more
+ add_more_convert(:to_no_add_more)
+ end # of case
+ end # of if
+ end
+
+ def check_cross_lang_convert(var,field)
+ if self[field]["cross_lang"] != var["cross_lang"]
+ case var["cross_lang"]
+ when "true" #from no-add_more to add_more
+ cross_lang_convert(:to_cross_lang)
+ else #from add_more to no-add_more
+ cross_lang_convert(:to_no_cross_lang)
+ end # of case
+ end # of if
end
end
diff --git a/app/models/user/attribute_value.rb b/app/models/user/attribute_value.rb
index d6500fbf..256fe072 100644
--- a/app/models/user/attribute_value.rb
+++ b/app/models/user/attribute_value.rb
@@ -1,11 +1,12 @@
class AttributeValue
-
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
-
+ include AttributeValuesHelper
field :key
+ field :address_ext
+
belongs_to :attribute_field
belongs_to :user
@@ -13,52 +14,110 @@ class AttributeValue
before_save :data_proc
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
+
- def data_proc
- # binding.pry
- # binding.pry if self.attribute_field.markup == 'radio_button'
- # if self.attribute_field
- case self.attribute_field.markup
- when 'text_field','text_area'
- # binding.pry
- self[:temp_data].each{|key,val|
- self[key] = val
- } unless self[:temp_data].nil?
- when 'select','date','radio_button'
- self["val"] = self[:temp_data]
- when 'checkbox'
- self["val"] = self[:temp_data].keys rescue {}
- end #end of case
- else # if not locale
- case self.attribute_field.markup
- when 'text_field','text_area'
- self["val"] = self[:temp_data]
- when 'select','date','radio_button'
- self["val"] = self[:temp_data]
- when 'checkbox'
- self["val"] = self[:temp_data].keys rescue {}
- end #end of case
- # end #of if self.attribute_field
- self.unset('temp_data')
+ def add_more_counter
+ index_max = self["val"].count rescue 0
+ index_max == 0 ? 1 : index_max
end
- def value
-
- result=""
- if self.attribute_field.locale && (self.attribute_field.markup == "text_field" || self.attribute_field.markup == "text_area")
- result= Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
- else
- result = self["val"]
- end
- result
+ def value(index = nil)
+ result = case self.attribute_field.markup
+ when 'text_field','text_area'
+ if self.attribute_field.add_more and (self.attribute_field.markup == "text_field")
+ index.nil? ? self["val"] : self["val"][index]
+ # self.attribute_field.get_data[:cross_lang] ? Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}] : self["val"] #if !self.attribute_field.get_data[:cross_lang]
+ else
+ self.attribute_field.get_data["cross_lang"] =="true" ? self["val"] : Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
+ end
+ when 'select','date','radio_button','address'
+ self["val"]
+ when 'checkbox'
+ self["val"]
+ end #end of case self.attribute_field.markup
end
def value=(value)
#save everything to temp_data waiting for futher process
- # binding
self[:temp_data] = value
end
+
+ def get_value_by_locale(locale,add_more_index=nil)
+
+ case self.attribute_field.markup
+ when "text_field"
+ case self.attribute_field.add_more
+ when true
+ add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale]
+ when false
+ self.attribute_field.locale ? self[locale.to_s] : self.value
+ end
+
+ when "select"
+ markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : self.attribute_field.markup_value
+ markup_values[self.value][locale.to_s] rescue 'NoData'
+
+ when "text_area"
+ self.attribute_field.locale ? self[locale.to_s] : self.value
+
+ when "date"
+ get_date_by_format
+
+ when "address"
+ self.value[locale.to_s]
+
+ when "radio_button"
+ markup_values = self.attribute_field.markup_value
+ markup_values[self.value][locale.to_s]
+
+ when "checkbox"
+ markup_values = self.attribute_field.markup_value
+ self.value.collect{|key| markup_values[key][locale.to_s]}.join(",")
+
+ when "date_durnation"
+ self.value
+
+ else
+ self.attribute_field.locale ? self[locale.to_s] : self.value
+ end
+ end
+
+
+protected
+
+def unset_all_lang_values
+ VALID_LOCALES.each{|t| self.unset t}
+ end
+
+ def data_proc
+ unless self[:temp_data].nil?
+ case self.attribute_field.markup
+ when "address"
+ self["val"] = self["temp_data"]
+ when 'text_field','text_area'
+ if self.attribute_field.add_more
+ self["val"] = self["temp_data"]
+ else # if not add_more
+ if self.attribute_field.can_muti_lang_input?
+ self[:temp_data].each do |key,val|
+ self[key] = val
+ end if(!self.attribute_field.get_data[:cross_lang])
+ else
+ self["val"] = self[:temp_data]
+ end
+ end # of self.attribute_field.add_more
+
+ when 'select','date','radio_button'
+ self["val"] = self[:temp_data]
+ when 'checkbox'
+ self["val"] = self[:temp_data].keys
+ end #end of case self.attribute_field.markup
+ end # of self[:temp_data].nil?
+ self.unset('temp_data')
+ self.unset('temp')
+ end #of data_proc
+
def check_key
self.key = attribute_field.key
end
@@ -70,48 +129,10 @@ class AttributeValue
self[(field[0].to_s.delete "=")] = field[1]
end
end
-
- def get_value_by_locale(locale)
- case self.attribute_field.markup
- when "text_field"
- self.attribute_field.locale ? self[locale.to_s] : self.value
- when "select"
- markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : eval(self.attribute_field.markup_value)
- markup_values[self.value][locale.to_s] rescue 'NoData'
- when "text_area"
- self.attribute_field.locale ? self[locale.to_s] : self.value
- when "date"
- Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil
- when "addr"
- self.value
- when "radio_button"
- markup_values = eval(self.attribute_field.markup_value)
- markup_values[:value][locale.to_s]
- when "checkbox"
- markup_values = self.attribute_field.markup_value
- self[:value].keys.collect{|key| markup_values[key][locale.to_s]}.join(",")
- when "date_durnation"
- self.value
- else
- self.attribute_field.locale ? self[locale.to_s] : self.value
- end
+
+ def get_date
+ Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil
end
- # def get_values
- # unless ['select','checkbox','radio_button'].include?(self.attribute_field.markup )
- # if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"]
- # return Hash[VALID_LOCALES.collect{|lang| [lang,get_value_by_locale(lang.to_sym)]}]
- # else
- # return get_value_by_locale("")
- # end
- # else
- # if self.attribute_field.markup == "select"
- # self[:value]
- # else
- # self[:value].keys rescue self[:value]
- # end
- # end
- # end
-
end
diff --git a/app/views/admin/attributes/edit.html.erb b/app/views/admin/attributes/edit.html.erb
index da159134..90f0c750 100644
--- a/app/views/admin/attributes/edit.html.erb
+++ b/app/views/admin/attributes/edit.html.erb
@@ -42,14 +42,6 @@
var NewNode;
$(document).ready(function(){
- // function mas(){
- // $('.site-map').masonry({
- // itemSelector: '.map-block',
- // columnWidth: 450,
- // isAnimated: true
- // });
- // }
-
function checkSwitch() {
$(".groups").addClass('disabled').has('.groups > .form-horizontal > div:not(.hide)').removeClass('disabled');
}
diff --git a/app/views/admin/designs/edit.html.erb b/app/views/admin/designs/edit.html.erb
index c49c5fb4..2a710dd0 100644
--- a/app/views/admin/designs/edit.html.erb
+++ b/app/views/admin/designs/edit.html.erb
@@ -34,10 +34,10 @@