diff --git a/Guardfile b/Guardfile new file mode 100644 index 00000000..4f561da0 --- /dev/null +++ b/Guardfile @@ -0,0 +1,22 @@ +guard 'livereload' do + watch(%r{app/.+\.(erb|haml)}) + watch(%r{app/helpers/.+\.rb}) + watch(%r{public/.+\.(css|js|html)}) + watch(%r{config/locales/.+\.yml}) +end + +guard 'rspec', :version => 2 do + watch(%r{^spec/.+_spec\.rb}) + watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } + + # Rails example + watch('spec/spec_helper.rb') { "spec" } + watch('config/routes.rb') { "spec/routing" } + watch('app/controllers/application_controller.rb') { "spec/controllers" } + watch(%r{^spec/.+_spec\.rb}) + watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] } + watch(%r{^app/views/(.+)/}) { |m| "spec/requests/#{m[1]}_spec.rb" } +end \ No newline at end of file diff --git a/app/assets/javascripts/ajax_form.js.erb b/app/assets/javascripts/ajax_form.js.erb index 917c352d..80abe23f 100644 --- a/app/assets/javascripts/ajax_form.js.erb +++ b/app/assets/javascripts/ajax_form.js.erb @@ -1,111 +1,7 @@ -<%#= encoding: utf-8 %> -$(document).on('click', '#ajax_form_submit', function(){ - // $('#ajaxForm').ajaxSubmit({ - // beforeSubmit: function(a,f,o) { - // o.dataType = 'script'; - // if (o.dataType == 'script') { - // o.url = o.url.split('?'); // split on GET params - // if (o.url[0].substr(-3) != '.js') o.url[0] += '.js'; // force rails to respond to respond to the request with :format = js - // o.url = o.url.join('?'); // join on GET params - // } - // }, - // success: function(response,status,xhr){ - // alert(response); - // alert(status); - // alert(xhr); - // }, - // error:function(){ - // alert("error"); - // } - // }); - - - var o = { - // dataType: 'script', - dataType: 'html', - url:$("#ajaxForm").attr("action"), - beforeSubmit: function(){ - var sub = true; - $("span.error").remove(); - $("#dyn_error").empty(); - $("#ajaxForm input").each(function(){ - if($(this).val() == ""){ - $(" *").insertAfter($(this)); - sub = false; - } - }) - if(!sub){ - $("#dyn_error").text("Cannot be empty."); - $("#dyn_error").text("<%= I18n.t('cant_empty_star') %>"); - return false; - } - }, - success: function(response,status,xhr){ - if(typeof tinyMCEPopup != "undefined"){ - var x = response.split("#"); - var returnurl = x[0], - returntitle = x[1], - returndescription = x[2]; - var win = tinyMCEPopup.getWindowArg("window"); - win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = returnurl; - win.document.getElementById(tinyMCEPopup.getWindowArg("alt")).value = returndescription; - win.document.getElementById(tinyMCEPopup.getWindowArg("title")).value = returntitle; - if (typeof(win.ImageDialog) != "undefined") { - // we are, so update image dimensions... - if (win.ImageDialog.getImageData) - win.ImageDialog.getImageData(); - - // ... and preview if necessary - if (win.ImageDialog.showPreviewImage) - win.ImageDialog.showPreviewImage(returnurl); - } - tinyMCEPopup.close(); - }else{ - //incase if we want to do something for quick edit file upload - // var modalvalues = ""; - // var r = ""; - // if(rcom.getInternetExplorerVersion() > -1){ - // r = "" + response + ""; - // r = r.replace("**",""); - // r = r.replace("**",""); - // r = $(r); - // modalvalues = r.find("span").attr("data-content").split("#"); - // r.attr("id",r.find("span").attr("for")); - // var table=document.getElementById(modalvalues[0]); - // //var tbody = table.getElementsByTagName("tbody"); - // var row = table.insertRow(table.rows.length-1); - // var c1 = row.insertCell(0), - // c2 = row.insertCell(1), - // c3 = row.insertCell(2); - // c1.innerHTML = r.find("td").eq(0).html(); - // c2.innerHTML = r.find("td").eq(1).html(); - // c3.innerHTML = r.find("td").eq(2).html(); - // var trow = $("#bulletin_files tfoot").find("tr").eq(0); - // $("#bulletin_files tbody").append(trow); - // }else{ - - // response = response.replace("**",""); - // response = response.replace("**",""); - // r = $(response); - // modalvalues = r.find("span").attr("data-content").split("#"); - // $('#' + modalvalues[0]+ ' tbody').append(r); - // } - // console.log(modalvalues[1]); - // $("#"+modalvalues[1]).modal('hide'); - //$('#bulletin_files tbody').append(r); - //$(response).fadeIn(); - } - }, - error:function(){ - alert("error"); - } - } - - if (o.dataType == 'script') { - o.url = o.url.split('?'); // split on GET params - if (o.url[0].substr(-3) != '.js') o.url[0] += '.js'; // force rails to respond to respond to the request with :format = js - o.url = o.url.join('?'); // join on GET params +$('#ajaxForm').ajaxForm({ + beforeSubmit: function(a,f,o) { + o.dataType = 'script'; + }, + success: function(data) { } - $('#ajaxForm').ajaxSubmit(o); - }); \ No newline at end of file diff --git a/app/assets/stylesheets/orbitTimeline.css b/app/assets/stylesheets/orbitTimeline111.css similarity index 100% rename from app/assets/stylesheets/orbitTimeline.css rename to app/assets/stylesheets/orbitTimeline111.css diff --git a/app/assets/stylesheets/style.css.erb b/app/assets/stylesheets/style.css.erb index c1d6bdc9..5a8635d3 100644 --- a/app/assets/stylesheets/style.css.erb +++ b/app/assets/stylesheets/style.css.erb @@ -267,6 +267,12 @@ #post-body-content { padding: 8px 0 8px 6px; } +#post-body-content .middle { + width: 100%; + padding: 0; + border: none; + box-shadow: none; +} .filter .accordion-group { margin-bottom: 0; border: none; diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index 9d434ff8..0b94317e 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.rb @@ -34,14 +34,37 @@ class Admin::DesignsController < OrbitBackendController def update @design = Design.find(params[:id]) - if @design.update_attributes(params[:design]) - flash[:notice] = "Successfully updated design and tasks." - redirect_to admin_designs_url(@design) - else - render :action => 'edit' + @design.update_attributes(params[:design]) + # if @design.update_attributes(params[:design]) + # flash[:notice] = "Successfully updated design and tasks." + # redirect_to admin_designs_url(@design) + # else + # render :action => 'edit' + # end + + respond_to do |format| + format.js {nil} end end + def update_file + @design = Design.find(params[:id]) + case params[:type] + when 'layout', 'css_default', 'css_reset' + @object = @design.send(params[:type]) + when 'image', 'javascript', 'theme' + @object = @design.send(params[:type]).find(params[:object_id]) + end + + Dir.mktmpdir('f_path') { |dir| + temp_file = File.new(dir + '/' + File.basename(@object.file.url), 'w+') + temp_file.write(params[:file][:content].force_encoding('UTF-8')) + @object.remove_file! + @object.file = temp_file + @object.save + } + end + def edit_file @design = Design.find(params[:id]) filename = params[:filename] @@ -91,6 +114,13 @@ class Admin::DesignsController < OrbitBackendController end redirect_to admin_designs_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) end + + def upload_image + @design = Design.find(params[:id]) + @image = @design.images.build(params[:image]) + @image.save + render :layout => false + end protected @@ -98,7 +128,6 @@ class Admin::DesignsController < OrbitBackendController Zip::ZipFile.open(file) { |zip_file| design = Design.new.from_json(zip_file.read("#{zip_name}/info.json")) Dir.mktmpdir('f_path') { |dir| - design.build_layout themes_entries = [] javascripts_entries = [] images_entries = [] @@ -106,25 +135,11 @@ class Admin::DesignsController < OrbitBackendController zip_file.entries.each do |entry| case (path = entry.to_s) when /\A(#{zip_name})\/(default\.css)\z/ #for default css - filename = File.basename(entry.to_s) - temp_file = File.new(dir + '/' + filename, 'w+') - temp_file.write (zip_file.read entry ).force_encoding('UTF-8') - default_css = design.build_default_css - default_css.file = temp_file - default_css.to_save = true + design.build_css_default(:file => get_temp_file(zip_file, dir, entry)) when /\A(#{zip_name})\/(reset\.css)\z/ #for reset css - filename = File.basename(entry.to_s) - temp_file = File.new(dir + '/' + filename, 'w+') - temp_file.write (zip_file.read entry ).force_encoding('UTF-8') - reset_css = design.build_reset_css - reset_css.file = temp_file - reset_css.to_save = true + design.build_css_reset(:file => get_temp_file(zip_file, dir, entry)) when /\A(#{zip_name})\/(layout\.html)\z/ #for layout html - filename = File.basename(entry.to_s) - temp_file = File.new(dir + '/' + filename, 'w+') - temp_file.write (zip_file.read entry ).force_encoding('UTF-8') - design.layout.file = temp_file - design.layout.to_save=true + design.build_layout(:file => get_temp_file(zip_file, dir, entry)) when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/ #for themes css themes_entries << entry when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ #for js @@ -136,12 +151,7 @@ class Admin::DesignsController < OrbitBackendController ['themes', 'javascripts', 'images'].each do |type| eval("#{type}_entries").each do |entry| - filename = File.basename entry.to_s - temp_file = File.new(dir + '/' + filename, 'w+') - temp_file.write (zip_file.read entry).force_encoding('UTF-8') - build_and_store = eval("design.#{type}").build - build_and_store.file = temp_file - build_and_store.to_save = true + eval("design.#{type}").build(:file => get_temp_file(zip_file, dir, entry)) end end } @@ -149,4 +159,11 @@ class Admin::DesignsController < OrbitBackendController } end + def get_temp_file(zip_file, dir, entry) + filename = File.basename(entry.to_s) + temp_file = File.new(dir + '/' + filename, 'w+') + temp_file.write (zip_file.read entry ).force_encoding('UTF-8') + temp_file + end + end diff --git a/app/controllers/admin/purchases_controller.rb b/app/controllers/admin/purchases_controller.rb index ab5b047d..b259c12f 100644 --- a/app/controllers/admin/purchases_controller.rb +++ b/app/controllers/admin/purchases_controller.rb @@ -71,8 +71,8 @@ class Admin::PurchasesController < ApplicationController Dir.mktmpdir('f_path') { |dir| build_file(orig_zip, zip_name, dir, design.layout) if design.layout - build_file(orig_zip, zip_name, dir, design.default_css) if design.default_css - build_file(orig_zip, zip_name, dir, design.reset_css) if design.reset_css + build_file(orig_zip, zip_name, dir, design.css_default) if design.css_default + build_file(orig_zip, zip_name, dir, design.css_reset) if design.css_reset ['themes', 'javascripts', 'images'].each do |type| design.send(type).each do |object| diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 32315aa5..929c316a 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -7,7 +7,7 @@ class SessionsController < Devise::SessionsController # login_password = params[:user][:password] # login_uid = params[:user][:nccu_ldap_uid] login_password = params[:user][:password] - login_email = params[:user][:login] + login_email = params[:user][:email] result = false resource = User.first(conditions:{ email: login_email }) set_flash_message(:notice, :signed_in) if is_navigational_format? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b9522368..14103d00 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -181,13 +181,13 @@ module ApplicationHelper stylesheets << "\n" stylesheets << "\n" end - stylesheets << "\n" if page.design.reset_css + stylesheets << "\n" if page.design.css_reset stylesheets << "\n" stylesheets << "\n" stylesheets << "\n" stylesheets << "\n" stylesheets << "\n" - stylesheets << "\n" if page.design.default_css + stylesheets << "\n" if page.design.css_default theme = page.design.themes.detect{ |d| d.id == page.theme_id } stylesheets << "\n" if theme stylesheets diff --git a/app/models/design/css_default.rb b/app/models/design/css_default.rb new file mode 100644 index 00000000..3ee5a58c --- /dev/null +++ b/app/models/design/css_default.rb @@ -0,0 +1,5 @@ +class CssDefault < Stylesheet + + belongs_to :design + +end diff --git a/app/models/design/css_reset.rb b/app/models/design/css_reset.rb new file mode 100644 index 00000000..b2a14b60 --- /dev/null +++ b/app/models/design/css_reset.rb @@ -0,0 +1,5 @@ +class CssReset < Stylesheet + + belongs_to :design + +end diff --git a/app/models/design/design.rb b/app/models/design/design.rb index 58f95bd4..c9d87982 100644 --- a/app/models/design/design.rb +++ b/app/models/design/design.rb @@ -3,25 +3,27 @@ class Design include Mongoid::Timestamps include ParserLayout - field :title, :type => String field :author, :type => String field :intro, :type => String + field :title, :type => String field :version, :type => String + has_one :css_default, :autosave => true, :dependent => :destroy + has_one :layout, :autosave => true, :dependent => :destroy + has_one :css_reset, :autosave => true, :dependent => :destroy + has_many :images, :autosave => true, :dependent => :destroy + has_many :javascripts, :autosave => true, :dependent => :destroy has_many :pages - - embeds_one :layout, :cascade_callbacks => true - embeds_one :default_css, :class_name => "Stylesheet", :cascade_callbacks => true - embeds_one :reset_css, :class_name => "Stylesheet", :cascade_callbacks => true - embeds_many :themes, :cascade_callbacks => true - embeds_many :javascripts, :cascade_callbacks => true - embeds_many :images, :as => :design_image, :cascade_callbacks => true - # embeds_many :custom_images, :class_name => 'Image', :cascade_callbacks => true - - validates_presence_of :title - validates_presence_of :author + has_many :themes, :autosave => true, :dependent => :destroy + + accepts_nested_attributes_for :images, :allow_destroy => true + accepts_nested_attributes_for :javascripts, :allow_destroy => true + accepts_nested_attributes_for :themes, :allow_destroy => true + + validates_presence_of :author, :title after_save :parse_css_for_images + def new_files=(*attrs) attrs[0].map do |key,items_ary| #Loop by JSs,Themes,Imgs @@ -66,13 +68,9 @@ class Design protected def parse_css_for_images - if (self.default_css && self.default_css.changed) - self.default_css.parse_urls - end + self.css_default.parse_urls self.themes.each do |theme| - if theme.changed? - theme.parse_urls - end + theme.parse_urls end parse_body_for_images(self) end diff --git a/app/models/design/design_file.rb b/app/models/design/design_file.rb index 3aec9a0c..973313c4 100644 --- a/app/models/design/design_file.rb +++ b/app/models/design/design_file.rb @@ -4,7 +4,14 @@ class DesignFile mount_uploader :file, AssetUploader - field :to_save, :type => Boolean - field :to_destroy, :type => Boolean + field :name + + before_save :set_name + + protected + + def set_name + self.name = self.file_identifier + end end diff --git a/app/models/design/image.rb b/app/models/design/image.rb index 939095e8..91c4a733 100644 --- a/app/models/design/image.rb +++ b/app/models/design/image.rb @@ -1,11 +1,23 @@ -class Image < DesignFile +class Image + include Mongoid::Document + include Mongoid::Timestamps - field :in_css, :type => Boolean - field :name field :html_id field :html_class - - embedded_in :design_image, polymorphic: true + field :in_css, :type => Boolean, :default => false + field :in_html, :type => Boolean, :default => false + field :name mount_uploader :file, ImageUploader -end + + belongs_to :design + + before_save :set_name + + protected + + def set_name + self.name = self.file_identifier + end + +end \ No newline at end of file diff --git a/app/models/design/javascript.rb b/app/models/design/javascript.rb index 7bfd2c5a..439e3b98 100644 --- a/app/models/design/javascript.rb +++ b/app/models/design/javascript.rb @@ -1,3 +1,3 @@ class Javascript < DesignFile - embedded_in :design + belongs_to :design end diff --git a/app/models/design/layout.rb b/app/models/design/layout.rb index bf48415c..a782894d 100644 --- a/app/models/design/layout.rb +++ b/app/models/design/layout.rb @@ -6,7 +6,7 @@ class Layout < DesignFile field :body embeds_one :menu - embedded_in :design + belongs_to :design embeds_many :layout_parts before_save :parse_layout diff --git a/app/models/design/stylesheet.rb b/app/models/design/stylesheet.rb index bb2ec85e..525e40f3 100644 --- a/app/models/design/stylesheet.rb +++ b/app/models/design/stylesheet.rb @@ -1,5 +1,5 @@ class Stylesheet < DesignFile - embedded_in :design + belongs_to :design mount_uploader :file_orig, AssetUploader def parse_urls @@ -11,7 +11,9 @@ class Stylesheet < DesignFile content.scan(/(?<=url)(.*?)(?=\))/){ css_name = $1.gsub(' ','').gsub('(','') name = File.basename(css_name).gsub(/[\\\"]/, '') - file_name = images.detect{ |i| i.file_identifier.eql?(name) }.file_url rescue nil + image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil + image.update_attribute(:in_css, true) if image + file_name = image.file_url rescue nil names << [css_name, file_name] } names.each do |name| diff --git a/app/models/design/theme.rb b/app/models/design/theme.rb index 8aca324b..0935fe12 100644 --- a/app/models/design/theme.rb +++ b/app/models/design/theme.rb @@ -1,14 +1,11 @@ class Theme < Stylesheet - field :name - embedded_in :design - - before_save :set_name + belongs_to :design protected def set_name - self.name = File.basename(self.file_identifier,".css") + self.name = File.basename(self.file_identifier, ".css") end end diff --git a/app/models/page.rb b/app/models/page.rb index 32a205f7..bee0700b 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -29,7 +29,7 @@ class Page < Item protected def create_parts - if self.new_record? || self.design.changed? + if self.new_record? || self.design_id_changed? page_design = self.design parent = self.parent menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 41480fd5..748bac16 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -24,7 +24,7 @@ class ImageUploader < CarrierWave::Uploader::Base # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: def store_dir - "image/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + "#{model.id}" end # Provide a default URL as a default if there hasn't been a file uploaded: @@ -48,7 +48,7 @@ class ImageUploader < CarrierWave::Uploader::Base # end version :thumb do - process :resize_to_fit => [200, 200] + process :resize_to_limit => [200, 200] end # Add a white list of extensions which are allowed to be uploaded. diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb index d787a58d..27f45f5f 100644 --- a/app/views/admin/designs/_form.html.erb +++ b/app/views/admin/designs/_form.html.erb @@ -1,60 +1,24 @@ -<% content_for :page_specific_css do %> - <%= stylesheet_link_tag "design" %> -<% end %> -<% content_for :page_specific_javascript do %> - <%= javascript_include_tag "design" %> +<%= form_for @design, :url => admin_design_path(@design), :html => {:class => 'form-horizontal'}, :remote => true do |f| %> + <%= f.error_messages %> +
+ <%= f.label :title, t('admin.title'), :class => "control-label" %> +
+ <%= f.text_field :title %> +
+
+
+ <%= f.label :author, t('admin.author'), :class => "control-label" %> +
+ <%= f.text_field :author %> +
+
+
+ <%= f.label :intro, t('admin.intro'), :class => "control-label" %> +
+ <%= f.text_field :intro %> +
+
+ <%= f.submit t('update') %> <% end %> -

- <%= f.label :title, t('admin.title') %> - <%= f.text_field :title, :class => 'text' %> -

-

- <%= f.label :author, t('admin.author') %> - <%= f.text_field :author, :class => 'text' %> -

-

- <%= f.label :intro, t('admin.intro') %> - <%= f.text_field :intro, :class => 'text' %> -

- -

- <%= f.label "layout", t('admin.layout') %> - <% if @design.layout.blank? %> - <%= fields_for 'design[layout]' do |f| %> - <%= f.file_field :file %> - <%#= f.hidden_field :to_save, :value => true %> - <% end %> - <% else %> - <%= File.basename (@design.layout.file.url) %> - <% end %> -

-

- <%= f.label "default_css", t('admin.default_css') %> - <% if @design.default_css.blank? %> - <%= fields_for 'design[default_css]' do |f| %> - <%= f.file_field :file %> - <%#= f.hidden_field :to_save, :value => true %> - <% end %> - <% else %> - <%= File.basename (@design.default_css.file.url) rescue "" %> - <% end %> -

-

- <%= f.label :themes, t('admin.themes') %> -

- <%= render :partial => 'new_design_file', :object => @design.themes.build, :locals => { :field_name => "themes", :f => f, :classes => "r_destroy" } %> -

- -

- <%#= render :partial => 'design_file', :locals => { :object => @design, :field_name => "javascripts", :f => f, :classes => "r_destroy, r_edit" } %> -

- -

- <%#= render :partial => 'design_file', :locals => { :object => @design, :field_name => "images", :f => f, :classes => "r_destroy, r_snapshot" } %> -

diff --git a/app/views/admin/designs/_image.html.erb b/app/views/admin/designs/_image.html.erb new file mode 100644 index 00000000..03482991 --- /dev/null +++ b/app/views/admin/designs/_image.html.erb @@ -0,0 +1,6 @@ + + <%= image.name %> + <%= image_tag image.file.thumb %> + <%= number_to_human_size(image.file.file.file_length) %> + <%= image.file.url %> + \ No newline at end of file diff --git a/app/views/admin/designs/_images.html.erb b/app/views/admin/designs/_images.html.erb new file mode 100644 index 00000000..67d25b17 --- /dev/null +++ b/app/views/admin/designs/_images.html.erb @@ -0,0 +1,40 @@ + + + + + + + + + + + <%= render :partial => 'image', :collection => @design.images %> + +
<%= t(:name) %><%= t(:image) %><%= t(:size) %><%= t(:url) %>
+ + + + + +
+ +
diff --git a/app/views/admin/designs/_tab_form.html.erb b/app/views/admin/designs/_tab_form.html.erb new file mode 100644 index 00000000..e46428ab --- /dev/null +++ b/app/views/admin/designs/_tab_form.html.erb @@ -0,0 +1,8 @@ +<%= form_for :file, :url => update_file_admin_design_path(:type => type, :object_id => object.id), :remote => true, :method => :post do |f| %> +
+ <%= f.text_area :content, :class => 'middle', :value => object.file.read.force_encoding('UTF-8') %> +
+
+ +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/designs/edit.html.erb b/app/views/admin/designs/edit.html.erb index 6ed2287e..7e275111 100644 --- a/app/views/admin/designs/edit.html.erb +++ b/app/views/admin/designs/edit.html.erb @@ -4,10 +4,40 @@

<%= t('admin.editing_design') %>

-<%= form_for @design, :url => admin_design_path(@design),:html => {:multipart => true} do |f| %> - <%= f.error_messages %> - <%= render :partial => "form", :locals => { :f => f } %> -

- <%= f.submit t('update') %> <%= link_back %> -

-<% end %> + + +
+
<%= render :partial => 'form' %>
+
<%= render :partial => 'tab_form', :locals => {:type => :layout, :object => @design.layout} %>
+
<%= render :partial => 'tab_form', :locals => {:type => :css_default, :object => @design.css_default} %>
+
<%= render :partial => 'tab_form', :locals => {:type => :css_reset, :object => @design.css_reset} %>
+ <% @design.themes.each do |theme| %> +
<%= render :partial => 'tab_form', :locals => {:type => :css_reset, :object => theme} %>
+ <% end %> + <% @design.javascripts.each do |js| %> +
<%= render :partial => 'tab_form', :locals => {:type => :css_reset, :object => js} %>
+ <% end %> +
<%= render :partial => 'images' %>
+
\ No newline at end of file diff --git a/app/views/admin/designs/update_file.js.erb b/app/views/admin/designs/update_file.js.erb new file mode 100644 index 00000000..012aa8a6 --- /dev/null +++ b/app/views/admin/designs/update_file.js.erb @@ -0,0 +1 @@ +// $('.modal').modal('hide') \ No newline at end of file diff --git a/app/views/admin/designs/upload_image.html.erb b/app/views/admin/designs/upload_image.html.erb new file mode 100644 index 00000000..4fb75b8e --- /dev/null +++ b/app/views/admin/designs/upload_image.html.erb @@ -0,0 +1,9 @@ +<% if !request.xhr? %> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/users_new_interface/tag_helpers/_address.html.erb b/app/views/admin/users_new_interface/tag_helpers/_address.html.erb new file mode 100644 index 00000000..23dbff7a --- /dev/null +++ b/app/views/admin/users_new_interface/tag_helpers/_address.html.erb @@ -0,0 +1,8 @@ + + address + + + + + other's options +
markup_value markup_options
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/tag_helpers/_checkbox.html.erb b/app/views/admin/users_new_interface/tag_helpers/_checkbox.html.erb new file mode 100644 index 00000000..8690d316 --- /dev/null +++ b/app/views/admin/users_new_interface/tag_helpers/_checkbox.html.erb @@ -0,0 +1,8 @@ + + checkbox + + + + + other's options +
markup_value markup_options
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/tag_helpers/_date.html.erb b/app/views/admin/users_new_interface/tag_helpers/_date.html.erb new file mode 100644 index 00000000..36b88fa3 --- /dev/null +++ b/app/views/admin/users_new_interface/tag_helpers/_date.html.erb @@ -0,0 +1,8 @@ + + date + + + + + other's options +
markup_value markup_options
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/tag_helpers/_date_durnation.html.erb b/app/views/admin/users_new_interface/tag_helpers/_date_durnation.html.erb new file mode 100644 index 00000000..9da099b9 --- /dev/null +++ b/app/views/admin/users_new_interface/tag_helpers/_date_durnation.html.erb @@ -0,0 +1,8 @@ + + date durnation + + + + + other's options +
markup_value markup_options
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/tag_helpers/_radio_button.html.erb b/app/views/admin/users_new_interface/tag_helpers/_radio_button.html.erb new file mode 100644 index 00000000..9a510cf5 --- /dev/null +++ b/app/views/admin/users_new_interface/tag_helpers/_radio_button.html.erb @@ -0,0 +1,8 @@ + + radio_button + + + + + other's options +
markup_value markup_options
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/tag_helpers/_select.html.erb b/app/views/admin/users_new_interface/tag_helpers/_select.html.erb new file mode 100644 index 00000000..58d9ce8d --- /dev/null +++ b/app/views/admin/users_new_interface/tag_helpers/_select.html.erb @@ -0,0 +1,8 @@ + + select + + + + + other's options +
markup_value markup_options
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/tag_helpers/_text_area.html.erb b/app/views/admin/users_new_interface/tag_helpers/_text_area.html.erb new file mode 100644 index 00000000..349ad499 --- /dev/null +++ b/app/views/admin/users_new_interface/tag_helpers/_text_area.html.erb @@ -0,0 +1,8 @@ + + text_area + + + + + other's options +
markup_value markup_options
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/tag_helpers/_text_field.html.erb b/app/views/admin/users_new_interface/tag_helpers/_text_field.html.erb new file mode 100644 index 00000000..93b23550 --- /dev/null +++ b/app/views/admin/users_new_interface/tag_helpers/_text_field.html.erb @@ -0,0 +1,8 @@ + + text_field + + + + + other's options +
markup_value markup_options
\ No newline at end of file diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 8f2be3e9..1ab2e89b 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -11,8 +11,8 @@

You need to sign in or sign up before continuing.

- <%= f.label :login ,t("admin.user_new_interface.email")%> - <%= f.text_field :login, :placeholder => t("admin.user_new_interface.email"), :style => "width: 330px;" %> + <%= f.label :email ,t("admin.user_new_interface.email")%> + <%= f.text_field :email, :placeholder => t("admin.user_new_interface.email"), :style => "width: 330px;" %> Please correct the error
diff --git a/app/views/shared/_address_modal_dialog.html.erb b/app/views/shared/_address_modal_dialog.html.erb new file mode 100644 index 00000000..6e241074 --- /dev/null +++ b/app/views/shared/_address_modal_dialog.html.erb @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 525d6808..88a39f42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,6 +58,8 @@ Orbit::Application.routes.draw do end member do post 'edit_file' => 'designs#edit_file' + post 'update_file' => 'designs#update_file' + post 'upload_image' => 'designs#upload_image' end end resources :infos do diff --git a/lib/parsers/parser_layout.rb b/lib/parsers/parser_layout.rb index 3379c487..817bf327 100644 --- a/lib/parsers/parser_layout.rb +++ b/lib/parsers/parser_layout.rb @@ -22,7 +22,7 @@ module ParserLayout body.css('.page_image').each do |page_image| image = design.images.where( file: File.basename(page_image['src']))[0] - image.update_attributes(:name => File.basename(page_image['src']), :html_id => page_image['id'], :html_class => page_image['class']) if image + image.update_attributes(:html_id => page_image['id'], :html_class => page_image['class'], :in_html => true) if image end end diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 70776ed9..60a7ec93 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -71,7 +71,7 @@ namespace :dev do design = Design.new(:title => "Fraisier", :author => "Paul", :intro => "Strawberry cake") - design.build_default_css(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) + design.build_css_default(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) # image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif")) # @@ -89,7 +89,7 @@ namespace :dev do design_1 = Design.new(:title => "Bob", :author => "Me", :intro => "Moran") - design_1.build_default_css(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) + design_1.build_css_default(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) # image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif")) # diff --git a/lib/tasks/pages.rake b/lib/tasks/pages.rake index 8a43f420..598d4b53 100644 --- a/lib/tasks/pages.rake +++ b/lib/tasks/pages.rake @@ -13,7 +13,7 @@ namespace :pages do design = Design.new(:title => "Fraisier", :author => "Paul", :intro => "Strawberry cake") - design.build_default_css(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) + design.build_css_default(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) # image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif")) # @@ -37,7 +37,7 @@ namespace :pages do design_1 = Design.new(:title => "Bob", :author => "Me", :intro => "Moran") - design_1.build_default_css(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) + design_1.build_css_default(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) # image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif")) # diff --git a/spec/models/attribute_field_spec.rb b/spec/models/attribute_field_spec.rb new file mode 100644 index 00000000..6fb01ba8 --- /dev/null +++ b/spec/models/attribute_field_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' +describe AttributeField do + describe "#list field" do + context "when field is in type text_field(without add more)" do + before(:each) do + @attribute_field = AttributeField.new(:key=>'test',:markup=>"text_field") + + + end + end + end +end \ No newline at end of file diff --git a/spec/models/attribute_value_spec.rb b/spec/models/attribute_value_spec.rb new file mode 100644 index 00000000..9488121e --- /dev/null +++ b/spec/models/attribute_value_spec.rb @@ -0,0 +1,63 @@ +#encoding: UTF-8 +require 'spec_helper' + +describe AttributeValue do + describe "#attribute_value" do + context "Data should be able to input and out put as aspect" + + before(:each) do + @af = AttributeField.find '5052cf9f2b5c49a742000005' + @user = User.where(email:'chris@rulingcom.com').first + @av = AttributeValue.last + end #end before + + + [true,false].each do |locale_sat| + LIST[:markups].each do |markup| + @av = nil + it "[#{markup[0]}]Input: should save data at right way when local is set to #{locale_sat}" do + @af.markup = markup[0] + @av = nil + @input_value = assume_result = case markup[0] + when 'text_field','text_area' + (locale_sat ? {"en"=> "lalala","zh_tw"=>"拉拉拉"} : "hahaha") + when 'select','radio_button' + "1" + when 'date' + {"(1i)"=>Date.today.year.to_s,"(2i)"=>Date.today.month.to_s,"(3i)"=>Date.today.day.to_s} + when 'checkbox' + {"1"=>"true", "3"=>"true"} + end #end of case + assume_result = ["1","3"] if markup[0] == 'checkbox' + @af.locale = locale_sat + @af.save + @data_hash = {"attribute_field_id" => @af.id,"value" => @input_value} + @av = @user.attribute_values.build(@data_hash) + @av.save + @av.value.should == assume_result + # @av.destroy + end + + it "[#{markup[0]}]Output(just for show): should output data at right way when local is set to #{locale_sat}" do + locale = I18n.locale + assume_result = case markup[0] + when 'text_area' + (locale_sat ? "拉拉拉" : "hahaha") + when 'text_field' + (locale_sat ? "拉拉拉" : "hahaha") + when 'select','radio_button' + (locale_sat ? "男性" : "男性") + when 'date' + Date.today + when 'checkbox' + (locale_sat ? "男性,不公開" : "男性,不公開") + end #end of case + + @av.get_value_by_locale(locale).should == assume_result + end + + end #end of LIST loop + end + + end +end \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb b/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb index 64eb8f8a..d023a0fa 100644 --- a/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb +++ b/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb @@ -27,6 +27,13 @@ Date.prototype.getWeek = function (dowOffset) { return weeknum; }; +Date.prototype.daysInMonth = function(){ + var daysArray = [31,28,31,30,31,30,31,31,30,31,30,31]; + if(this.getFullYear()%4 == 0) + daysArray[1] = 29; + + return daysArray[this.getMonth()]; +} var calendarAPI = function(){ c = this; @@ -36,17 +43,20 @@ var calendarAPI = function(){ this.cur_month = c.today.getMonth()+1; this.cur_year = c.today.getFullYear(); this.cur_week = c.today.getWeek(); + this.cur_date = c.today.getDate(); this.view = null; this.monthlist = ["","January","February","March","April","May","June","July","August","September","October","November","December"]; this.initialize = function(){ $(window).load(function(){ // c.loadMonthView(c.cur_month,c.cur_year); - c.loadWeekView(c.cur_week,c.cur_year); + // c.loadWeekView(c.cur_week,c.cur_year); + c.loadDayView(c.cur_date,c.cur_month,c.cur_year); bindHandlers(); }) var bindHandlers = function(){ - $(".event").live("click",function(){ - c.displayEvent($(this)); + $(".event").live("click",function(e){ + var pos = {"x":e.clientX,"y":e.clientY}; + c.displayEvent($(this),pos); }) $("#create_event_btn").click(function(){ @@ -73,7 +83,7 @@ var calendarAPI = function(){ c.loadWeekView(c.cur_week,c.cur_year); break; case 'day': - c.loadDayView(); + c.loadDayView(c.cur_date,c.cur_month,c.cur_year); break; case 'agenda': c.loadAgendaView(); @@ -104,6 +114,22 @@ var calendarAPI = function(){ } c.loadWeekView(w,y); break; + case "day": + var d,w,y; + d = c.cur_date - 1; + m = c.cur_month; + y = c.cur_year; + if(d == 0){ + var dx = new Date(c.cur_year,c.cur_month-2); + d = dx.daysInMonth(); + m--; + } + if(m == 0){ + m = 12; + y = y - 1; + } + c.loadDayView(d,m,y); + break; } }) @@ -132,10 +158,40 @@ var calendarAPI = function(){ } c.loadWeekView(w,y); break; + case "day": + var d,w,y; + var dx = new Date(c.cur_year,c.cur_month-1); + if(c.cur_date == dx.daysInMonth()){ + d = 1; + m = c.cur_month + 1; + }else{ + d = c.cur_date + 1; + m = c.cur_month; + } + + if(m == 13){ + m = 1; + y = c.cur_year + 1; + }else{ + y = c.cur_year; + } + + c.loadDayView(d,m,y); + break; } }) $("button#today_btn").click(function(){ - c.loadMonthView(); + switch (c.view){ + case "week": + c.loadWeekView(); + break; + case "month": + c.loadMonthView(); + break; + case "day": + c.loadDayView(); + break; + } }) } } @@ -156,7 +212,7 @@ var calendarAPI = function(){ if($('#calendar_month').length > 0){ var $c_table = $('#calendar_month'); var sum_h = 0; - var context_h = $('#main-sidebar').outerHeight(); + var context_h = $(window).height() - $('#orbit-bar').height(); $('#main-wrap > *').not('#orbit_calendar, .modal').each(function(){ sum_h += $(this).outerHeight(); }); @@ -215,6 +271,8 @@ var calendarAPI = function(){ var recordcurdate = true; if(allow){ + if(evnt.title=="Navratri") + console.log(pos); if(pos == 1){ var colspan = 0; if(evnt.total_days>7){ @@ -231,13 +289,13 @@ var calendarAPI = function(){ $eventrow.html('
'+evnt.title+'
'); }else{ if($eventrow.html()==""){ - $eventrow.append(''); + $eventrow.append(''); }else{ if((lastno+1)!=thisno){ var inposition = parseInt($eventrow.find("td.main_td:last").attr("pos")); var curcolspan = $eventrow.find("td.main_td:last").attr("colspan"); var colspan = pos - (inposition+parseInt(curcolspan)); - $eventrow.append(''); + $eventrow.append(''); } } var colspan = 0; @@ -297,16 +355,182 @@ var calendarAPI = function(){ } this.getEventsForWeek = function(week,year){ $.getJSON("cals/getWeekEvents",{"week":week,"year":year},function(events){ - + var height = 15; + var full_day_count = 0; + var rowcount = 7; + var tr = $(""); + var pre = true; + $.each(events,function(i,evnt){ + // console.log("rowcount: "+rowcount); + // console.log("start:"+evnt.start); + if(rowcount >= (7 - evnt.total_days)){ + if(tr.html()!=""){ + if(rowcount != 7){ + tr.append(""); + } + $("table.all_day_event_holder").append(tr); + } + tr = null; + tr = $(''); + pre = true; + } + + if(evnt.all_day){ + full_day_count++; + + var precountspan = 7 - evnt.total_days; + if(pre){ + height+=20; + $(".head_event_wrapper").height(height); + $(".head_event_wrapper table").eq(0).height(height); + tr.append(' '); + if(precountspan != 0){ + tr.append(''); + pre = false; + } + } + var colcount = evnt.total_days; + if(evnt.colcount != 0){ + colcount = evnt.colcount; + } + + rowcount = precountspan + colcount; + + tr.append('
'+evnt.title+'
'); + + // $(".week_day_header[date="+evnt.start_date+"]").append('
'+evnt.title+'
'); + }else{ + + var starttime,endtime,displaystarttime,displayendtime; + if(evnt.start_am_pm == "AM"){ + starttime = evnt.start_time; + if(starttime == 12) + starttime = 0; + if(starttime == 12.5) + starttime = 0.5; + }else + starttime = evnt.start_time + 12; + + if(evnt.end_am_pm == "AM"){ + endtime = evnt.end_time; + if(endtime == 12) + endtime = 0; + if(endtime == 12.5) + endtime = 0.5; + }else + endtime = evnt.end_time + 12; + + var temp = parseInt(evnt.start_time); + + if (evnt.start_time > temp) + displaystarttime = temp + ":30 " + evnt.start_am_pm; + else + displaystarttime = temp + ":00 " + evnt.start_am_pm; + + temp = parseInt(evnt.end_time); + + if (evnt.end_time > temp) + displayendtime = temp + ":30 " + evnt.end_am_pm; + else + displayendtime = temp + ":00 " + evnt.end_am_pm; + + var toppx = ((starttime * 2) * 20) + 1; + var h = endtime - starttime; + var halfhour = ""; + if(h == 0.5) + halfhour = "half"; + h = 17 + 20 + (((h-1) * 2) * 20) + 1; + var eventdom = $('
'+displaystarttime+' - '+displayendtime+'
'+evnt.title+'
'); + $(".week_day_body[date="+evnt.start_date+"] .inner").append(eventdom); + } + if(full_day_count == 0){ + tr.append(''); + $("table.all_day_event_holder").append(tr); + } + + }) + if(tr.html()!=""){ + if(rowcount != 7){ + tr.append(""); + } + $("table.all_day_event_holder").append(tr); + } }) } - this.loadDayView = function(){ - $('#view_holder').load("cals/day_view", function() { - $('.current_day_title').text('September 2, 2012'); + this.loadDayView = function(day,month,year){ + c.view = "day"; + if(!day){ + var dt = new Date(); + week = dt.getWeek(); + year = dt.getFullYear(); + day = dt.getDate(); + month = dt.getMonth()+1; + } + + c.cur_date = day; + c.cur_month = month; + c.cur_year = year; + + $('#view_holder').load("cals/day_view?date="+day+"&month="+month+"&year="+year, function() { + $('.current_day_title').text($("#day_header").text()); + c.getEventsForDay(day,month,year); + }) + } + this.getEventsForDay = function(day,month,year){ + $.getJSON("cals/getDayEvents",{"date":day,"month":month,"year":year},function(events){ + $.each(events,function(i,evnt){ + if(evnt.all_day){ + $(".all_day_event").append('
'+evnt.title+'
') + }else{ + var starttime,endtime,displaystarttime,displayendtime; + if(evnt.start_am_pm == "AM"){ + starttime = evnt.start_time; + if(starttime == 12) + starttime = 0; + if(starttime == 12.5) + starttime = 0.5; + }else + starttime = evnt.start_time + 12; + + if(evnt.end_am_pm == "AM"){ + endtime = evnt.end_time; + if(endtime == 12) + endtime = 0; + if(endtime == 12.5) + endtime = 0.5; + }else + endtime = evnt.end_time + 12; + + var temp = parseInt(evnt.start_time); + + if (evnt.start_time > temp) + displaystarttime = temp + ":30 " + evnt.start_am_pm; + else + displaystarttime = temp + ":00 " + evnt.start_am_pm; + + temp = parseInt(evnt.end_time); + + if (evnt.end_time > temp) + displayendtime = temp + ":30 " + evnt.end_am_pm; + else + displayendtime = temp + ":00 " + evnt.end_am_pm; + + var toppx = ((starttime * 2) * 20) + 1; + var h = endtime - starttime; + var halfhour = ""; + if(h == 0.5) + halfhour = "half"; + h = 17 + 20 + (((h-1) * 2) * 20) + 1; + var eventdom = $('
'+displaystarttime+' - '+displayendtime+'
'+evnt.title+'
'); + $(".event_holder").append(eventdom); + } + + }) + }) } this.loadAgendaView = function(){ - $('#view_holder').load("cals/week_view", function() { + $('#view_holder').load("cals/agenda_view", function() { $('.current_day_title').text('September 2, 2012'); }) } @@ -338,11 +562,27 @@ var calendarAPI = function(){ var domfor = $(this).attr("data-content"); $("tr[for="+domfor+"]").remove(); }) + $(".btn-edit-a").live("ajax:success",function(evt,form){ + $("#edit_area_" + $(this).attr("for")).html(form).slideDown(); + $("#edit_area_" + $(this).attr("for")).find(".color-picker").miniColors(); + }) + $(".bt-cancel").live("click",function(){ + $("#edit_area_" + $(this).attr("for")).html("").slideUp(); + }) } - this.displayEvent = function(dom){ + this.displayEvent = function(dom,pos){ var url = dom.attr("link"); c.event_quick_view_div.load(url,function(){ - c.event_quick_view_div.show() + var x = pos.x; + var y = pos.y; + var winheight = $(window).height() + if((x+c.event_quick_view_div.width()) > $(window).width()){ + x = x - c.event_quick_view_div.width(); + } + if((y+c.event_quick_view_div.height()) > winheight){ + y = y - c.event_quick_view_div.height(); + } + c.event_quick_view_div.css({"left":x+"px","top":y+"px"}).show() c.event_quick_view_div.find(".event-close-btn").click(function(){ c.event_quick_view_div.empty().hide(); }) diff --git a/vendor/built_in_modules/calendar/app/assets/stylesheets/calendar.css b/vendor/built_in_modules/calendar/app/assets/stylesheets/calendar.css index 85b0390f..874904a5 100644 --- a/vendor/built_in_modules/calendar/app/assets/stylesheets/calendar.css +++ b/vendor/built_in_modules/calendar/app/assets/stylesheets/calendar.css @@ -32,22 +32,26 @@ border-radius: 3px; cursor: pointer; padding: 1px 3px; + font-weight: bold; box-shadow: inset 0 0 1px black; -webkit-box-shadow: inset 0 0 1px black; -moz-box-shadow: inset 0 0 1px black; } +.event_list_wrapper { + position: relative; +} .event_list .cell { - height: 38px; + height: 39px; border: solid 1px #ddd; border-top: 0; } .event_list .divide { - height: 18px; + height: 19px; margin-bottom: 18px; border-bottom: solid 1px #eee; } .event_list .day_time { - height: 30px; + height: 31px; border-bottom: solid 1px #ddd; border-left: solid 1px #ddd; text-align: right; @@ -189,7 +193,7 @@ } #calendar_day .all_day_event { background: #eee; - border: solid 1px #ddd + border: solid 1px #ddd; } #calendar_day .event_list .table { border-top: solid 1px #ddd; @@ -223,14 +227,14 @@ } #calendar_week .header td { border: solid 1px #ddd; - background-color: #eee; + /*background-color: #eee;*/ } #calendar_week .week_day { padding: 0 2px; border: solid 1px #ddd; } #calendar_week .header .week_day { - padding: 1px 2px 10px 2px; + padding: 2px 4px 0px 2px; } #calendar_week .event_list .event { position: absolute; @@ -250,7 +254,18 @@ #calendar_week .event_holder .inner { margin: 0 8px 0 0; } - +#calendar_week .all_day_event_holder { + position: relative; + width: 100%; + table-layout: fixed; +} +#calendar_week .all_day_event_holder td { + border: 0; + background-color: transparent; +} +#calendar_week .all_day_event { + background: #eee; +} diff --git a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb index 2c171895..fdf712aa 100644 --- a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb +++ b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb @@ -11,6 +11,19 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController @calendars = Cal.all end + def edit + @calendar = Cal.find(params[:id]) + render :layout=>false + end + + def update + @calendar = Cal.find(params[:id]) + @calendar.update_attributes(params[:cal]) + respond_to do |h| + h.js + end + end + def create @calendar = Cal.new(params[:cal]) @calendar.save! @@ -26,14 +39,30 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController end def day_view - render :layout => false + date = params[:date].to_i + month = params[:month].to_i + year = params[:year].to_i + @cur_day = getDayName(date,month,year) + " " + month.to_s + "/" + date.to_s + " - " + year.to_s + @hours = getHours(12) + render :layout => false end def week_view - week = params[:week] - year = params[:year] + week = params[:week].to_i + year = params[:year].to_i @dates = week_dates(week,year) @range = week_range(week,year) + @d = getWeekDataSet(week,year) + t = Time.now + dt = Date.new(t.year,t.month,t.day) + today_cur_week = dt.strftime("%U").to_i + + if week == today_cur_week && t.year == year + @today = @d.index(t.day.to_s) + else + @today = 20 + end + @hours = getHours(12) render :layout => false end @@ -59,48 +88,172 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController end def get_month_events - month = params[:month] - year = params[:year] - month = month.to_i - year = year.to_i - events = Event.where(:start_month.lt => month).and(:start_year => year).and(:end_month.gte => month).asc(:start_date).desc(:total_days) + month = params[:month].to_i + year = params[:year].to_i + + # events = Event.where(:start_month.lt => month).and(:start_year => year).and(:end_month.gte => month).asc(:start_date).desc(:total_days) @events = Array.new no_of_days_in_month = getMonthDays(year) - events.each_with_index do |event,i| - no_of_days = event.total_days + # events.each_with_index do |event,i| + # no_of_days = event.total_days - if event.end_month > month - no_of_days = no_of_days_in_month[month] - elsif event.end_month == month - no_of_days = event.end_date - end + # if event.end_month > month + # no_of_days = no_of_days_in_month[month] + # elsif event.end_month == month + # no_of_days = event.end_date + # end - no_of_days = no_of_days.to_i + # no_of_days = no_of_days.to_i - color = Cal.find(event.cal_id).color - @events << {"id"=>event.id,"index"=>i,"start_date"=>"1", "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event)} - end - events = Event.where(:start_month => month).and(:start_year => year).asc(:start_date).desc(:total_days) + # color = Cal.find(event.cal_id).color + # @events << {"id"=>event.id,"index"=>i,"start_date"=>"1", "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event)} + # end + # events = Event.where(:start_month => month).and(:start_year => year).asc(:start_date).desc(:total_days) + # events.each_with_index do |event,i| + # # @temp = Array.new + # no_of_days = event.total_days + # if event.end_month > month + # no_of_days = no_of_days_in_month[month] - event.start_date + # end + # no_of_days = no_of_days.to_i + # no_of_days += 1 + + # color = Cal.find(event.cal_id).color + # @events << {"id"=>event.id,"index"=>i,"start_date"=>event.start_date, "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event)} + # end + events = Event.all.asc(:start_date).desc(:total_days) events.each_with_index do |event,i| # @temp = Array.new - no_of_days = event.total_days - if event.end_month > month - no_of_days = no_of_days_in_month[month] - event.start_date - end - no_of_days = no_of_days.to_i - no_of_days += 1 - color = Cal.find(event.cal_id).color - @events << {"id"=>event.id,"index"=>i,"start_date"=>event.start_date, "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event)} + startdt = Date.new(event.start_year,event.start_month) + enddt = Date.new(event.end_year,event.end_month) + range = startdt..enddt + + dt = Date.new(year,month) + if range === dt + no_of_days = event.total_days + start_date = event.start_date + + if event.start_year < year + no_of_days = no_of_days_in_month[month] - event.start_date + no_of_days += 1 + temp = month + 12 + if event.start_month < temp + start_date = 1 + end + end + if event.end_year > year + no_of_days = no_of_days_in_month[month] - event.start_date + no_of_days += 1 + temp = month + 12 + end + if event.end_month > month + no_of_days = no_of_days_in_month[month] - event.start_date + no_of_days += 1 + elsif event.end_month == month + no_of_days = event.end_date + end + + if event.start_month == month && event.end_month == month + no_of_days = event.total_days + no_of_days += 1 + end + + if event.start_month < month + start_date = 1 + end + + color = Cal.find(event.cal_id).color + @events << {"start_year"=>event.start_year, "id"=>event.id,"index"=>i,"start_date"=>start_date, "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event)} + end + end render :json => @events.to_json end def get_week_events - week = params[:week] - year = params[:year] - events = Event.where(:start_week => week).and(:start_year => year) - render :json => events.to_json + week = params[:week].to_i + year = params[:year].to_i + @d = getWeekDataSet(week,year) + events = Event.where(:start_week.lte => week).and(:start_year => year).and(:end_week.gte => week).and(:start_year => year).asc(:start_week).asc(:start_date) + @events = Array.new + events.each_with_index do |event,i| + # @temp = Array.new + days = event.total_days.to_i + 1 + colcount = 0 + startdt = event.start_date + + all_day = event.all_day + + if days > 1 + all_day = true + end + + if event.end_week > week && event.start_week < week + days = 7 + end + + if event.end_week == week + days = @d.index(event.end_date.to_s).to_i + end + + if event.start_week == week + days = 7 - @d.index(event.start_date.to_s).to_i + end + + + if event.start_week == week && event.end_week == week + x = @d.index(event.end_date.to_s).to_i + y = @d.index(event.start_date.to_s).to_i + colcount = x - y + colcount+=1 + + end + + if event.start_week < week + startdt = @d[0].to_i + event.all_day = true + if event.end_week == week + colcount = 7 - @d.index(event.end_date.to_s).to_i + days = 7; + startdt = event.start_date + end + end + + color = Cal.find(event.cal_id).color + @events << {"id"=>event.id,"index"=>i,"start_date"=>startdt,"end_date"=>event.end_date ,"all_day"=>all_day, "start_week" => event.start_week, "end_week" => event.end_week, "total_days" => days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event),"start_time"=>event.start_time,"end_time"=>event.end_time,"start_am_pm"=>event.start_am_pm,"end_am_pm"=>event.end_am_pm,"colcount"=>colcount} + end + render :json => @events.to_json + end + + def get_day_events + day = params[:date].to_i + month = params[:month].to_i + year = params[:year].to_i + dt = Date.new(year,month,day) + week = dt.strftime("%U") + events = Event.where(:start_month.lte => month).and(:start_year => year).and(:end_month.gte => month) + @events = Array.new + events.each_with_index do |event,i| + days = event.total_days.to_i + 1 + colcount = 0 + + all_day = event.all_day + + if days > 1 + all_day = true + end + startdt = Date.new(event.start_year,event.start_month,event.start_date) + enddt = Date.new(event.end_year,event.end_month,event.end_date) + + range = startdt..enddt + + if range === dt + color = Cal.find(event.cal_id).color + @events << {"id"=>event.id,"index"=>i,"start_date"=>event.start_date,"end_date"=>event.end_date ,"all_day"=>all_day, "start_week" => event.start_week, "end_week" => event.end_week, "total_days" => days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event),"start_time"=>event.start_time,"end_time"=>event.end_time,"start_am_pm"=>event.start_am_pm,"end_am_pm"=>event.end_am_pm} + end + end + render :json => @events.to_json end def week_number_test diff --git a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb index 519d84f4..41ffa151 100644 --- a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb +++ b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb @@ -42,6 +42,13 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController # if end_am_pm == "PM" # temp_end_time = $endtime + 12 # end + if params[:all_day] + all_day = true + $starttime = 0 + $endtime = 0 + else + all_day = false + end final_start_time = Date.new(start_year.to_i,start_month.to_i,start_date.to_i) final_end_time = Date.new(end_year.to_i,end_month.to_i,end_date.to_i) @@ -67,6 +74,7 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController @event.total_days = total_days @event.start_week = start_week @event.end_week = end_week + @event.all_day = all_day @event.save! respond_to do |h| @@ -81,6 +89,12 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController @end_day_name = getDayName(@event.end_date,@event.end_month,@event.end_year) render :layout=>false end + + def destroy + event = Event.find(params[:id]) + event.delete + render :json => {"success"=>"true"}.to_json + end end diff --git a/vendor/built_in_modules/calendar/app/helpers/panel/calendar/back_end/cals_helper.rb b/vendor/built_in_modules/calendar/app/helpers/panel/calendar/back_end/cals_helper.rb index 8b4d61d8..fc349ecd 100644 --- a/vendor/built_in_modules/calendar/app/helpers/panel/calendar/back_end/cals_helper.rb +++ b/vendor/built_in_modules/calendar/app/helpers/panel/calendar/back_end/cals_helper.rb @@ -131,6 +131,55 @@ module Panel::Calendar::BackEnd::CalsHelper end range end + + def getWeekDataSet(week_num,year) + year = year.to_i + week_num = week_num.to_i + dates = Array.new + + if week_num == 1 + weekstartday = monthStartDay(1,year) + d = 31 + x = 0 + for i in d - (weekstartday - 2)..d + dates << i.to_s + x = x + 1 + end + for i in 1..8 - weekstartday + dates << i.to_s + x = x + 1 + end + else + week_start = Date.commercial(year, week_num-1, 7) + month = week_start.strftime("%m") + month_days = getMonthDays(year) + date = week_start.strftime("%d") + x = date.to_i + for i in 0..6 + d = x + i + if d > month_days[month.to_i] + d = d - month_days[month.to_i] + end + dates << d.to_s + end + end + dates + end + + def getHours(format) + hours = Array.new + if format == 12 + hours << 12 + for i in 1..11 + hours << i + end + elsif format == 24 + for i in 0..23 + hours << i + end + end + hours + end end diff --git a/vendor/built_in_modules/calendar/app/models/event.rb b/vendor/built_in_modules/calendar/app/models/event.rb index cff01fcc..5c53b1c1 100644 --- a/vendor/built_in_modules/calendar/app/models/event.rb +++ b/vendor/built_in_modules/calendar/app/models/event.rb @@ -19,6 +19,7 @@ class Event field :final_start_time, type: Date field :final_end_time, type: Date field :total_days, type: Integer + field :all_day, type: Boolean belongs_to :cal diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/_calendar.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/_calendar.html.erb index 9accb75a..c03b0d18 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/_calendar.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/_calendar.html.erb @@ -1,10 +1,12 @@ +
+
diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/agenda_view.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/agenda_view.html.erb index b7726e4c..57bb1bf9 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/agenda_view.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/agenda_view.html.erb @@ -45,4 +45,223 @@ -
\ No newline at end of file +
+ \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/day_view.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/day_view.html.erb index cdbc1c47..709437c7 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/day_view.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/day_view.html.erb @@ -3,14 +3,14 @@ -

Sunday 9/2

+ -
event1
-
event2
+ @@ -18,136 +18,56 @@ - diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/edit.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/edit.html.erb new file mode 100644 index 00000000..9cf6b355 --- /dev/null +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/edit.html.erb @@ -0,0 +1,26 @@ +<%= form_for @calendar, :url => panel_calendar_back_end_cal_path(@calendar), :remote => true do |f| %> +

Edit

+
+
+ <%= label_tag("color", t("calendar.color")) %> + <%= f.text_field :color, :class => "color-picker miniColors", :size => "5", :maxlength => "5", :autocomplete=>"off",:value=>@calendar.color %> +
+
+ +
+ <%= f.fields_for :name_translations do |name| %> + <% @site_valid_locales.each_with_index do |locale, i| %> +
+ <%= label_tag(locale, t("calendar.name")+"-"+I18nVariable.from_locale(locale)) %> +
+ <%= name.text_field locale, :class => "input-xxlarge", :size=>"30", :value=>@calendar.name_translations[locale] %> +
+
+ <% end %> + <% end %> +
+
+ <%= f.submit t("calendar.save"), :class=>"btn btn-primary" %> + +
+<% end %> \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb index 96701aaf..791cfe19 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb @@ -64,7 +64,7 @@ - +
-
12am
-
1am
-
2am
-
3am
-
4am
-
5am
-
6am
-
7am
-
8am
-
9am
-
10am
-
11am
-
12am
-
1pm
-
2pm
-
3pm
-
4pm
-
5pm
-
6pm
-
7pm
-
8pm
-
9pm
-
10pm
-
11pm
+ <% @hours.each do |hour| %> +
<%= hour %>am
+ <% end %> + <% @hours.each do |hour| %> +
<%= hour %>pm
+ <% end %>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
10:30am - 11:00am
-
template
-
+
+
+ <% @hours.each do |hour| %> +
+
-
-
-
10:30am - 11:00am
-
template
-
-
-
-
-
10:30am - template
-
-
-
-
-
-
10:30am - 11:00am
-
template
-
-
-
-
-
10:30am - 11:00am
-
template
-
+
+
+ <% end %> +
+