From eaa87b3dd8b0a17acbdf6c24d72a6edb4cb5bcfe Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 4 Nov 2013 14:44:20 +0800 Subject: [PATCH] new categories for calendar with colors inside.. plus changed the working of calendar. it has now categories like all other modules --- app/assets/javascripts/admin/categories.js | 1 + app/assets/stylesheets/jquery.miniColors.css | 6 ++ .../back_end/event_categories_controller.rb | 74 +++-------------- .../back_end/events_controller.rb | 15 ++-- .../calendar_new/app/models/event.rb | 17 ++-- .../event_categories/_category.html.erb | 21 +++++ .../back_end/event_categories/_form.html.erb | 12 +++ .../back_end/event_categories/index.html.erb | 79 ++++++++++++++----- .../back_end/event_categories/list.html.erb | 13 +++ .../back_end/events/_form.html.erb | 2 +- .../calendar_new/config/routes.rb | 2 + vendor/built_in_modules/calendar_new/init.rb | 12 +-- 12 files changed, 142 insertions(+), 112 deletions(-) create mode 100644 vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/_category.html.erb create mode 100644 vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/_form.html.erb create mode 100644 vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/list.html.erb diff --git a/app/assets/javascripts/admin/categories.js b/app/assets/javascripts/admin/categories.js index 54250153..7b8b7f60 100644 --- a/app/assets/javascripts/admin/categories.js +++ b/app/assets/javascripts/admin/categories.js @@ -12,6 +12,7 @@ $(function() { } else { setForm(item.data('form')); + if( $( ".color-picker" ).length ) $(".color-picker").miniColors("value",item.data("form").color); pageslide.find('form').attr('action', '/admin/module_apps/' + item.data('module') + '/categories/' + item.data('id')); pageslide.find('form').attr('method', 'put'); } diff --git a/app/assets/stylesheets/jquery.miniColors.css b/app/assets/stylesheets/jquery.miniColors.css index 831da6f8..7cce8442 100755 --- a/app/assets/stylesheets/jquery.miniColors.css +++ b/app/assets/stylesheets/jquery.miniColors.css @@ -56,4 +56,10 @@ width: 26px; height: 3px; background: url(miniColors/line.gif) center no-repeat; +} + +.miniColors-trigger.btn { + background-image: none; + height: 16px; + width: 0px; } \ No newline at end of file diff --git a/vendor/built_in_modules/calendar_new/app/controllers/panel/calendar_new/back_end/event_categories_controller.rb b/vendor/built_in_modules/calendar_new/app/controllers/panel/calendar_new/back_end/event_categories_controller.rb index 97d4636b..d7da4816 100644 --- a/vendor/built_in_modules/calendar_new/app/controllers/panel/calendar_new/back_end/event_categories_controller.rb +++ b/vendor/built_in_modules/calendar_new/app/controllers/panel/calendar_new/back_end/event_categories_controller.rb @@ -4,78 +4,22 @@ class Panel::CalendarNew::BackEnd::EventCategoriesController < OrbitBackendContr # GET /events # GET /events.json def index - @event_categories = EventCategory.all + @module_app_id = @module_app.id rescue nil + @categories = get_categories_for_index + @categories = @categories.page(params[:page]).per(10) respond_to do |format| format.html # index.html.erb - format.json { render json: @event_categories } + format.json { render json: @categories } end end - # GET /events/1 - # GET /events/1.json - def show - @event_category = EventCategory.find(params[:id]) + def list + @module_app_id = @module_app.id rescue nil - respond_to do |format| - format.html # show.html.erb - format.json { render json: @event_category } - end - end - - # GET /events/new - # GET /events/new.json - def new - @event_category = EventCategory.new - respond_to do |format| - format.html # new.html.erb - format.json { render json: @event_category } - end - end - - # GET /events/1/edit - def edit - @event_category = EventCategory.find(params[:id]) - end - - def create - @event_category = EventCategory.new(params[:event_category]) - - respond_to do |format| - if @event_category.save - format.html { redirect_to panel_calendar_new_back_end_event_categories_path, notice: 'Category was successfully created.' } - format.json { render json: @event_category, status: :created, location: @event_category } - else - format.html { render action: "new" } - format.json { render json: @event_category.errors, status: :unprocessable_entity } - end - end - end - - def update - @event_category = EventCategory.find(params[:id]) - - respond_to do |format| - if @event_category.update_attributes(params[:event_category]) - format.html { redirect_to panel_calendar_new_back_end_event_categories_path, notice: 'Category was successfully updated.' } - format.json { head :no_content } - #format.js - else - format.html { render action: "edit" } - format.json { render json: @event_category.errors, status: :unprocessable_entity } - #format.js - end - end - end - - def destroy - @event_category = EventCategory.find(params[:id]) - @event_category.destroy - - respond_to do |format| - format.html { redirect_to panel_calendar_new_back_end_event_categories_path } - format.json { head :no_content } - end + @categories = get_categories_for_index + @categories = @categories.page(params[:page]).per(10) + render :layout => false end end \ No newline at end of file diff --git a/vendor/built_in_modules/calendar_new/app/controllers/panel/calendar_new/back_end/events_controller.rb b/vendor/built_in_modules/calendar_new/app/controllers/panel/calendar_new/back_end/events_controller.rb index abb0441c..1cb702b2 100644 --- a/vendor/built_in_modules/calendar_new/app/controllers/panel/calendar_new/back_end/events_controller.rb +++ b/vendor/built_in_modules/calendar_new/app/controllers/panel/calendar_new/back_end/events_controller.rb @@ -40,6 +40,7 @@ class Panel::CalendarNew::BackEnd::EventsController < OrbitBackendController # GET /events/new.json def new @event = Event.new + @categories = get_categories_for_index @end_d_t = "" @start_d_t = "" @all_day = false; @@ -61,15 +62,13 @@ class Panel::CalendarNew::BackEnd::EventsController < OrbitBackendController @start_d_t = params[:startDate] end render :layout => false - #respond_to do |format| - # format.html # new.html.erb - # format.json { render json: @event } - #end + end # GET /events/1/edit def edit @event = Event.find(params[:id]) + @categories = get_categories_for_index @end_d_t = @event.end.strftime("%Y/%m/%d %H:%M").to_s @start_d_t = @event.start.strftime("%Y/%m/%d %H:%M").to_s @all_day = @event.all_day @@ -80,12 +79,8 @@ class Panel::CalendarNew::BackEnd::EventsController < OrbitBackendController # POST /events # POST /events.json def create - @event = Event.new(params[:event]) - # if params[:event][:period] == "Does not repeat" - - #else - # @event_recurring = EventRecurring.new(params[:event]) - #end + @event = Event.new(params[:event]) + if @event.present? && @event.save render json: @event.to_json else diff --git a/vendor/built_in_modules/calendar_new/app/models/event.rb b/vendor/built_in_modules/calendar_new/app/models/event.rb index eb8c4e80..2fefe7b4 100644 --- a/vendor/built_in_modules/calendar_new/app/models/event.rb +++ b/vendor/built_in_modules/calendar_new/app/models/event.rb @@ -4,6 +4,7 @@ require 'date' class Event include Mongoid::Document include Mongoid::Timestamps + include OrbitCategory::Categorizable include Mongoid::MultiParameterAttributes field :title @@ -12,13 +13,11 @@ class Event field :end, type: DateTime field :all_day, type: Boolean field :recurring, type: Boolean - field :event_category_id field :frequency field :period attr_accessor :agenda_start, :agenda_end, :get_agenda_events - belongs_to :event_category validates_presence_of :title, :message => "Please fill the title of the Event" @@ -42,8 +41,8 @@ class Event :end => self.end.rfc822, :allDay => self.all_day, :recurring => self.recurring, - :calendar => self.event_category_id, - :color => EventCategory.find(self.event_category_id).color, + :calendar => self.category_id, + :color => Category.find(self.category_id).custom_value, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(self.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(self.id) } @@ -64,13 +63,13 @@ class Event @i = TimeDifference.between(re.start,end_date).in_days.to_i (1..@i).each do |i| @start_date = re.start + i - @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @start_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.event_category_id.to_s, :color => EventCategory.find(re.event_category_id).color, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} + @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @start_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.category_id.to_s, :color => Category.find(re.category_id).custom_value, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} end elsif re.start < start_date @i = TimeDifference.between(start_date,end_date).in_days.to_i (0..@i-1).each do |i| @start_date = start_date.to_date + i - @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @start_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.event_category_id.to_s, :color => EventCategory.find(re.event_category_id).color, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} + @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @start_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.category_id.to_s, :color => Category.find(re.category_id).custom_value, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} end end when "Weekly" @@ -81,7 +80,7 @@ class Event @start_date += (7*re.frequency.to_i) @end_date += (7*re.frequency.to_i) - @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @end_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.event_category_id.to_s, :color => EventCategory.find(re.event_category_id).color, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} + @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @end_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.category_id.to_s, :color => Category.find(re.category_id).custom_value, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} end when "Monthly" if !(start_date..end_date).cover?(re.start) @@ -91,7 +90,7 @@ class Event @start_date = sd sd = sd >> @i*re.frequency.to_i ed = ed >> @i*re.frequency.to_i - @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>sd, :end => ed, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.event_category_id.to_s, :color => EventCategory.find(re.event_category_id).color, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} + @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>sd, :end => ed, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.category_id.to_s, :color => Category.find(re.category_id).custom_value, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} end when "Yearly" if !(start_date..end_date).cover?(re.start) @@ -101,7 +100,7 @@ class Event @start_date = sd sd = sd >> 12 * @i*re.frequency.to_i ed = ed >> 12 * @i*re.frequency.to_i - @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>sd, :end => ed, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.event_category_id.to_s, :color => EventCategory.find(re.event_category_id).color, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} + @recurring << {:id => re.id, :title=>re.title, :note=>re.note, :start=>sd, :end => ed, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.category_id.to_s, :color => Category.find(re.category_id).custom_value, :edit_url => Rails.application.routes.url_helpers.edit_panel_calendar_new_back_end_event_path(re.id), :delete_url => Rails.application.routes.url_helpers.panel_calendar_new_back_end_event_path(re.id)} end end end diff --git a/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/_category.html.erb b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/_category.html.erb new file mode 100644 index 00000000..096260c6 --- /dev/null +++ b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/_category.html.erb @@ -0,0 +1,21 @@ + + <% @site_valid_locales.each_with_index do |locale, i| %> + + <%= category.title_translations[locale] %> + <% if i == 0 %> +
+ +
+ <% end %> + + <% end %> + <%= category.custom_value %> + \ No newline at end of file diff --git a/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/_form.html.erb b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/_form.html.erb new file mode 100644 index 00000000..e89f6050 --- /dev/null +++ b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/_form.html.erb @@ -0,0 +1,12 @@ +<%= flash_messages %> +<%= f.error_messages %> +<%= label_tag("color", t("calendar.color")) %> +
+ <%= f.text_field :custom_value, id: "color", :class => "color-picker miniColors input-small", :size => "7", :maxlength => "7", :autocomplete=>"off",:value=>"9100FF" %> +
+<%= f.fields_for :title_translations do |f| %> + <% @site_valid_locales.each do |locale| %> + <%= label_tag "name-#{locale}", "#{t(:name)} (#{I18nVariable.from_locale(locale)})" %> + <%= f.text_field locale, :class => 'input-large', :value => (@category.title_translations[locale] rescue ''), placeholder: t(:name), id: locale %> + <% end %> +<% end %> diff --git a/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/index.html.erb b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/index.html.erb index 350c0553..8a7842b8 100644 --- a/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/index.html.erb +++ b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/index.html.erb @@ -1,28 +1,65 @@ - +<%= stylesheet_link_tag "jquery.miniColors" %> + +<%= javascript_include_tag "jquery.miniColors.min" %> + +<%= javascript_include_tag "admin/categories" %> + +
+
- - - - <%if is_manager? %> - - + + <% @site_valid_locales.each_with_index do |locale, i| %> + <% end %> + - - <% @event_categories.each do |event_category| %> - - - - - <%if is_manager? %> - - - <%end%> - - <% end %> + + <%= render partial: 'category', collection: @categories %>
<%= t('event_category.name') %><%= t('event_category.color') %><%= t('event_category.edit') %><%= t('event_category.delete') %>
<%= t(:_locale, :locale => locale) %><%= t('event_category.color') %>
<%= event_category.name %><%= event_category.color%><%= link_to 'Edit', edit_panel_calendar_new_back_end_event_category_path(event_category) %><%= link_to 'Destroy', panel_calendar_new_back_end_event_category_path(event_category), method: :delete , :confirm => t(:sure?) %>
-<%= link_to "Add", new_panel_calendar_new_back_end_event_category_path, :class => "btn btn-primary pull-right", :id=>"create_event_btn", :ref=>"add-btn" %> -

\ No newline at end of file +
+
+ <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), '#', class: "btn btn-primary open-slide", data: {title: t(:add_category), id: 'new', module: @module_app_id.to_s } %> +
+ +
+ +
+
+ + + + +
+
+
+
+ <%= form_for :category, url: nil, html:{:id=>"color"}, remote: true do |f| %> +
+ <%= render :partial => "form", :locals => { :f => f } %> +
+ <%= t(:cancel) %> + <%= f.submit t(:submit), class: 'btn btn-primary btn-small' %> +
+
+ <% end %> +
+
+
+
+ \ No newline at end of file diff --git a/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/list.html.erb b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/list.html.erb new file mode 100644 index 00000000..a7ba79f4 --- /dev/null +++ b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/event_categories/list.html.erb @@ -0,0 +1,13 @@ + + + + <% @site_valid_locales.each_with_index do |locale, i| %> + + <% end %> + + + + + <%= render partial: 'category', collection: @categories %> + +
<%= t(:_locale, :locale => locale) %><%= t('event_category.color') %>
\ No newline at end of file diff --git a/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/events/_form.html.erb b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/events/_form.html.erb index dce7e876..2403c17c 100644 --- a/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/events/_form.html.erb +++ b/vendor/built_in_modules/calendar_new/app/views/panel/calendar_new/back_end/events/_form.html.erb @@ -52,7 +52,7 @@
<%= f.label "Calendar", :class=>"control-label span3" %> - <%= f.collection_select :event_category_id, EventCategory.all, :id, :name%> + <%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %>
diff --git a/vendor/built_in_modules/calendar_new/config/routes.rb b/vendor/built_in_modules/calendar_new/config/routes.rb index 3cc9d726..fd411537 100644 --- a/vendor/built_in_modules/calendar_new/config/routes.rb +++ b/vendor/built_in_modules/calendar_new/config/routes.rb @@ -2,8 +2,10 @@ Rails.application.routes.draw do namespace :panel do namespace :calendar_new do namespace :back_end do + match 'event_categories/list' => "event_categories#list" resources :event_categories match 'events/agenda' => 'events#agenda', :as => :agenda + resources :events end namespace :front_end do diff --git a/vendor/built_in_modules/calendar_new/init.rb b/vendor/built_in_modules/calendar_new/init.rb index c1aee0c8..c738ef51 100644 --- a/vendor/built_in_modules/calendar_new/init.rb +++ b/vendor/built_in_modules/calendar_new/init.rb @@ -28,18 +28,18 @@ module CalendarNew head_link_path "panel_calendar_new_back_end_events_path" - context_link 'calendar.categories', - :link_path=>"admin_module_app_categories_path(get_module_app)" , - :priority=>2, - :active_for_category => 'CalendarNew', - :available_for => [:manager] + # context_link 'calendar.categories', + # :link_path=>"admin_module_app_categories_path(get_module_app)" , + # :priority=>2, + # :active_for_category => 'CalendarNew', + # :available_for => [:manager] context_link 'tags', :link_path=>"admin_module_tags_path(module_app_id: get_module_app)" , :priority=>4, :active_for_tag => 'CalendarNew', :available_for => [:manager] - context_link 'calendar.color', + context_link 'calendar.categories', :link_path=>"panel_calendar_new_back_end_event_categories_path" , :priority=>3, :active_for_tag => 'CalendarNew',