calendar month view update

This commit is contained in:
Harry Bomrah 2012-09-16 05:59:20 +08:00
parent b09b1cf2f5
commit 9491945fd4
11 changed files with 217 additions and 165 deletions

View File

@ -4,6 +4,10 @@ var calendarAPI = function(){
c = this;
this.event_create_div = $("#event_create");
this.event_quick_view_div = $("#event_quick_view");
this.cur_month = null;
this.cur_year = null;
this.today = new Date();
this.monthlist = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
this.initialize = function(){
$(window).load(function(){
c.loadMonthView();
@ -24,7 +28,7 @@ var calendarAPI = function(){
var target = $(this).text();
switch(target){
case 'month':
c.loadMonthView();
c.loadMonthView(c.cur_month,c.cur_year);
break;
case 'week':
c.loadWeekView();
@ -36,12 +40,46 @@ var calendarAPI = function(){
c.loadAgendaView();
break;
}
});
})
$("button#prev_month_btn").click(function(){
var m,y;
if(c.cur_month == 1){
m = 12;
y = c.cur_year-1;
}else{
m = c.cur_month-1;
y = c.cur_year;
}
c.loadMonthView(m,y);
})
$("button#next_month_btn").click(function(){
var m,y;
if(c.cur_month == 12){
m = 1;
y = c.cur_year+1;
}else{
m = c.cur_month+1;
y = c.cur_year;
}
c.loadMonthView(m,y);
})
$("button#today_btn").click(function(){
c.loadMonthView();
})
}
}
this.loadMonthView = function(){
$('#view_holder').load("cals/month_view", function() {
$('.current_day_title').text('September 2012');
this.loadMonthView = function(month,year){
if(!month){
var dt = new Date();
month = dt.getMonth()+1;
year = dt.getFullYear();
}
// month = 2;
// year = 2008;
c.cur_month = month;
c.cur_year = year;
$('#view_holder').load("cals/month_view?month="+month+"&year="+year, function() {
$('.current_day_title').text(c.monthlist[c.cur_month]+" "+c.cur_year);
if($('#calendar_month').length > 0){
var $c_table = $('#calendar_month');
var sum_h = 0;
@ -106,6 +144,10 @@ var calendarAPI = function(){
if($('.color-picker').length > 0){
$('.color-picker').miniColors(); // just in category view
}
$(".btn-del-a").live("ajax:success",function(){
var domfor = $(this).attr("data-content");
$("tr[for="+domfor+"]").remove();
})
}
this.displayEvent = function(){

View File

@ -1,5 +1,6 @@
class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
include AdminHelper
include Panel::Calendar::BackEnd::CalsHelper
def index
@ -8,13 +9,20 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
def new
@calendar = Cal.new
@calendars = Cal.all
debugger
end
def create
debugger
calendar = Cal.new(params[:cal])
render :json => calendar.to_json
@calendar = Cal.new(params[:cal])
@calendar.save!
respond_to do |h|
h.js
end
end
def destroy
calendar = Cal.find(params[:id])
calendar.delete
render :json => {"success"=>"true"}.to_json
end
def day_view
@ -26,6 +34,20 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
end
def month_view
month = params[:month].to_i
year = params[:year].to_i
t = Time.now
startday = monthStartDay(month,year)
@pre_disabled_days = startday - 1
if t.month == month && t.year == year
@today = @pre_disabled_days + t.day
else
@today = 50
end
cur_month_days = getMonthDays(year)
@post_disabled_days = @pre_disabled_days + cur_month_days[month]
@dateset = getDateSet(month,year)
render :layout => false
end

View File

@ -1,6 +1,7 @@
class Panel::Calendar::BackEnd::EventsController < OrbitBackendController
def new
@calendars = Cal.all
render :layout => false
end
end

View File

@ -0,0 +1,65 @@
module Panel::Calendar::BackEnd::CalsHelper
def monthStartDay(month,year)
dt = Date.new(year,month,1)
startday = dt.wday + 1
return startday
end
def getDateSet(month,year)
dateset = Array.new
startday = monthStartDay(month,year)
monthsdays = getMonthDays(year)
cur_month_days = monthsdays[month]
next_month_days = monthsdays[month+1]
prev_month_days = monthsdays[month-1]
prev_month_days_to_add = startday - 1
i = prev_month_days_to_add
while i > 0 do
i -= 1
dateset << prev_month_days - i
end
i = 0
while i < cur_month_days do
dateset << i + 1
i += 1
end
next_month_days_to_add = 42 - (prev_month_days_to_add + cur_month_days)
i = 0
while i < next_month_days_to_add do
dateset << i + 1
i += 1
end
return dateset
end
def getMonthDays(year)
monthsdays = Array.new
monthsdays << 0
monthsdays << 31
if Date.new(year).leap?
monthsdays << 29
else
monthsdays << 28
end
monthsdays << 31
monthsdays << 30
monthsdays << 31
monthsdays << 30
monthsdays << 31
monthsdays << 31
monthsdays << 30
monthsdays << 31
monthsdays << 30
monthsdays << 31
return monthsdays
end
end

View File

@ -0,0 +1,16 @@
<tr class="with_action" for="<%= calendar.id.to_s %>">
<td>
<span class="calendars_color_tag" style="background-color: <%= calendar.color %>"></span>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><a href="">Edit</a></li>
<li><%= link_to t("calendar.delete"), panel_calendar_back_end_cal_path(calendar), :method => "delete",:remote => true, :confirm => t("gallery.sure?"),:class=>"btn-del-a", "data-content"=>calendar.id.to_s %></li>
</ul>
</div>
</td>
<% @site_valid_locales.each do |locale| %>
<td>
<%= calendar.name_translations[locale] %>
</td>
<% end %>
</tr>

View File

@ -0,0 +1 @@
$("#calendar_list").prepend("<%= j render :partial=>'calendar', :object=>@calendar %>");

View File

@ -31,16 +31,16 @@
<div class="span3">
<div class="btn-toolbar" style="margin:0;">
<div class="btn-group">
<button class="btn">Today</button>
<button class="btn" id="today_btn">Today</button>
</div>
<div class="btn-group">
<button class="btn"><span class="icon-chevron-left"></span></button>
<button class="btn"><span class="icon-chevron-right"></span></button>
<button class="btn" id="prev_month_btn"><span class="icon-chevron-left"></span></button>
<button class="btn" id="next_month_btn"><span class="icon-chevron-right"></span></button>
</div>
</div>
</div>
<div class="span5">
<h4 class="current_day_title">Semptember 2012</h4>
<h4 class="current_day_title"></h4>
</div>
<div class="span4">
<div class="btn-group calendar_mode" data-toggle="buttons-radio">

View File

@ -12,55 +12,50 @@
</tr>
</table>
</div>
<div class="month_row">
<table class="table month_table">
<tr>
<td class="disable"></td>
<td class="disable"></td>
<td class="disable"></td>
<td class="disable"></td>
<td class="disable"></td>
<td class="disable"></td>
<td></td>
</tr>
</table>
<table class="table month_date">
<tr>
<td class="day_title disable">Aug 26</td>
<td class="day_title disable">27</td>
<td class="day_title disable">28</td>
<td class="day_title disable">29</td>
<td class="day_title disable">30</td>
<td class="day_title disable">31</td>
<td>Sep 1</td>
</tr>
</table>
</div>
<div class="month_row">
<table class="table month_table">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table class="table month_date">
<tr>
<td class="day_title">2</td>
<td class="day_title">3</td>
<td class="day_title">4</td>
<td class="day_title">5</td>
<td class="day_title">6</td>
<td class="day_title">7</td>
<td class="day_title">8</td>
</tr>
</table>
</div>
<div class="month_row">
<% i = 0 %>
<% day_count_for_title = 0 %>
<% day_count_for_space = 0 %>
<% while i < 6 %>
<div class="month_row">
<table class="table month_table">
<tr>
<% x = 0 %>
<% while x < 7 %>
<% if day_count_for_space < @pre_disabled_days %>
<td class="disable"></td>
<% elsif day_count_for_space >= @post_disabled_days %>
<td class="disable"></td>
<% elsif day_count_for_space == @today-1 %>
<td class="today"></td>
<% else %>
<td></td>
<% end %>
<% day_count_for_space += 1 %>
<% x += 1 %>
<% end %>
</tr>
</table>
<table class="table month_date">
<tr>
<% x = 0 %>
<% while x < 7 %>
<% if day_count_for_title < @pre_disabled_days %>
<td class="day_title disable"><%= @dateset[day_count_for_title] %></td>
<% elsif day_count_for_title >= @post_disabled_days %>
<td class="day_title disable"><%= @dateset[day_count_for_title] %></td>
<% else %>
<td class="day_title"><%= @dateset[day_count_for_title] %></td>
<% end %>
<% day_count_for_title += 1 %>
<% x += 1 %>
<% end %>
</tr>
</table>
</div>
<% i += 1 %>
<% end %>
<!-- <div class="month_row">
<table class="table month_table">
<tr>
<td></td>
@ -92,76 +87,5 @@
</tr>
</table>
</div>
<div class="month_row">
<table class="table month_table">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table class="table month_date">
<tr>
<td class="day_title">16</td>
<td class="day_title">17</td>
<td class="day_title">18</td>
<td class="day_title">19</td>
<td class="day_title">20</td>
<td class="day_title">21</td>
<td class="day_title">22</td>
</tr>
</table>
</div>
<div class="month_row">
<table class="table month_table">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table class="table month_date">
<tr>
<td class="day_title">23</td>
<td class="day_title">24</td>
<td class="day_title">25</td>
<td class="day_title">26</td>
<td class="day_title">27</td>
<td class="day_title">28</td>
<td class="day_title">29</td>
</tr>
</table>
</div>
<div class="month_row">
<table class="table month_table">
<tr>
<td></td>
<td class="disable"></td>
<td class="disable"></td>
<td class="disable"></td>
<td class="disable"></td>
<td class="disable"></td>
<td class="disable"></td>
</tr>
</table>
<table class="table month_date">
<tr>
<td>30</td>
<td class="day_title disable">Nov 1</td>
<td class="day_title disable">2</td>
<td class="day_title disable">3</td>
<td class="day_title disable">4</td>
<td class="day_title disable">5</td>
<td class="day_title disable">6</td>
</tr>
</table>
</div>
-->
</div>

View File

@ -12,47 +12,25 @@
<table class="table main-list">
<thead>
<tr>
<th class="span2"><span class="" title="">Key</span></th>
<th class="span2">Color</th>
<th class="span2"><span class="" title="">Color</span></th>
<th class="span2">English</th>
<th class="span2">Chiness</th>
<th class="span2">Chinese</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<table id="callendars" class="table main-list">
<table id="calendars" class="table main-list">
<thead>
<tr>
<th class="span2"></th>
<th class="span2"></th>
<th class="span2"></th>
<th class="span2"></th>
</tr>
</thead>
<tbody>
<% @calendars.each do |calendar| %>
<tr id="" class="with_action">
<td>
<span class="calendars_color_tag" style="background-color: <%= calendar.color %>"></span>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><a href="">Category Authorization</a></li>
<li><a href="">Edit</a></li>
<li><a href="">Delete</a></li>
</ul>
</div>
</td>
<% @site_valid_locales.each do |locale| %>
<td>
<% calendar.name_translations[locale] %>
</td>
<% end %>
</tr>
<% end %>
<tbody id="calendar_list">
<%= render :partial => "calendar", :collection => @calendars %>
</tbody>
</table>
@ -63,7 +41,7 @@
<div class="row-fluid">
<div class="span2">
<%= label_tag("color", t("calendar.color")) %>
<%= f.text_field :color, :class => "color-picker miniColors span5", :size => "7", :maxlength => "7", :autocomplete=>"off",:value=>"FFCC00" %>
<%= f.text_field :color, :class => "color-picker miniColors span5", :size => "7", :maxlength => "7", :autocomplete=>"off",:value=>"9100FF" %>
</div>
</div>

View File

@ -95,11 +95,12 @@
<div class="row-fluid">
<label for="" class="control-label span3">Calendars</label>
<div class="row-fluid span9">
<select name="" id="" class="span12">
<!-- <select name="" id="" class="span12">
<option value="">calendar 1</option>
<option value="">calendar 2</option>
<option value="">calendar 3</option>
</select>
</select> -->
<%= select("Calendar", Cal.all.collect {|p| [ p.name, p.id ] },{:prompt => t("calendar.select_calendar")},:class => "validate") %>
</div>
</div>
<div class="row-fluid">

View File

@ -3,4 +3,6 @@ en:
calendars: Calendars
color: Color
name: Name
save: Save
save: Save
delete: Delete
select_calendar: "Select Calendar"