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; c = this;
this.event_create_div = $("#event_create"); this.event_create_div = $("#event_create");
this.event_quick_view_div = $("#event_quick_view"); 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(){ this.initialize = function(){
$(window).load(function(){ $(window).load(function(){
c.loadMonthView(); c.loadMonthView();
@ -24,7 +28,7 @@ var calendarAPI = function(){
var target = $(this).text(); var target = $(this).text();
switch(target){ switch(target){
case 'month': case 'month':
c.loadMonthView(); c.loadMonthView(c.cur_month,c.cur_year);
break; break;
case 'week': case 'week':
c.loadWeekView(); c.loadWeekView();
@ -36,12 +40,46 @@ var calendarAPI = function(){
c.loadAgendaView(); c.loadAgendaView();
break; 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(){ this.loadMonthView = function(month,year){
$('#view_holder').load("cals/month_view", function() { if(!month){
$('.current_day_title').text('September 2012'); 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){ if($('#calendar_month').length > 0){
var $c_table = $('#calendar_month'); var $c_table = $('#calendar_month');
var sum_h = 0; var sum_h = 0;
@ -106,6 +144,10 @@ var calendarAPI = function(){
if($('.color-picker').length > 0){ if($('.color-picker').length > 0){
$('.color-picker').miniColors(); // just in category view $('.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(){ this.displayEvent = function(){

View File

@ -1,5 +1,6 @@
class Panel::Calendar::BackEnd::CalsController < OrbitBackendController class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
include AdminHelper include AdminHelper
include Panel::Calendar::BackEnd::CalsHelper
def index def index
@ -8,13 +9,20 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
def new def new
@calendar = Cal.new @calendar = Cal.new
@calendars = Cal.all @calendars = Cal.all
debugger
end end
def create def create
debugger @calendar = Cal.new(params[:cal])
calendar = Cal.new(params[:cal]) @calendar.save!
render :json => calendar.to_json respond_to do |h|
h.js
end
end
def destroy
calendar = Cal.find(params[:id])
calendar.delete
render :json => {"success"=>"true"}.to_json
end end
def day_view def day_view
@ -26,6 +34,20 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
end end
def month_view 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 render :layout => false
end end

View File

@ -1,6 +1,7 @@
class Panel::Calendar::BackEnd::EventsController < OrbitBackendController class Panel::Calendar::BackEnd::EventsController < OrbitBackendController
def new def new
@calendars = Cal.all
render :layout => false render :layout => false
end end
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="span3">
<div class="btn-toolbar" style="margin:0;"> <div class="btn-toolbar" style="margin:0;">
<div class="btn-group"> <div class="btn-group">
<button class="btn">Today</button> <button class="btn" id="today_btn">Today</button>
</div> </div>
<div class="btn-group"> <div class="btn-group">
<button class="btn"><span class="icon-chevron-left"></span></button> <button class="btn" id="prev_month_btn"><span class="icon-chevron-left"></span></button>
<button class="btn"><span class="icon-chevron-right"></span></button> <button class="btn" id="next_month_btn"><span class="icon-chevron-right"></span></button>
</div> </div>
</div> </div>
</div> </div>
<div class="span5"> <div class="span5">
<h4 class="current_day_title">Semptember 2012</h4> <h4 class="current_day_title"></h4>
</div> </div>
<div class="span4"> <div class="span4">
<div class="btn-group calendar_mode" data-toggle="buttons-radio"> <div class="btn-group calendar_mode" data-toggle="buttons-radio">

View File

@ -12,55 +12,50 @@
</tr> </tr>
</table> </table>
</div> </div>
<div class="month_row">
<table class="table month_table"> <% i = 0 %>
<tr> <% day_count_for_title = 0 %>
<td class="disable"></td> <% day_count_for_space = 0 %>
<td class="disable"></td> <% while i < 6 %>
<td class="disable"></td> <div class="month_row">
<td class="disable"></td> <table class="table month_table">
<td class="disable"></td> <tr>
<td class="disable"></td> <% x = 0 %>
<td></td> <% while x < 7 %>
</tr> <% if day_count_for_space < @pre_disabled_days %>
</table> <td class="disable"></td>
<table class="table month_date"> <% elsif day_count_for_space >= @post_disabled_days %>
<tr> <td class="disable"></td>
<td class="day_title disable">Aug 26</td> <% elsif day_count_for_space == @today-1 %>
<td class="day_title disable">27</td> <td class="today"></td>
<td class="day_title disable">28</td> <% else %>
<td class="day_title disable">29</td> <td></td>
<td class="day_title disable">30</td> <% end %>
<td class="day_title disable">31</td> <% day_count_for_space += 1 %>
<td>Sep 1</td> <% x += 1 %>
</tr> <% end %>
</table> </tr>
</div> </table>
<div class="month_row"> <table class="table month_date">
<table class="table month_table"> <tr>
<tr> <% x = 0 %>
<td></td> <% while x < 7 %>
<td></td> <% if day_count_for_title < @pre_disabled_days %>
<td></td> <td class="day_title disable"><%= @dateset[day_count_for_title] %></td>
<td></td> <% elsif day_count_for_title >= @post_disabled_days %>
<td></td> <td class="day_title disable"><%= @dateset[day_count_for_title] %></td>
<td></td> <% else %>
<td></td> <td class="day_title"><%= @dateset[day_count_for_title] %></td>
</tr> <% end %>
</table> <% day_count_for_title += 1 %>
<table class="table month_date"> <% x += 1 %>
<tr> <% end %>
<td class="day_title">2</td> </tr>
<td class="day_title">3</td> </table>
<td class="day_title">4</td> </div>
<td class="day_title">5</td> <% i += 1 %>
<td class="day_title">6</td> <% end %>
<td class="day_title">7</td> <!-- <div class="month_row">
<td class="day_title">8</td>
</tr>
</table>
</div>
<div class="month_row">
<table class="table month_table"> <table class="table month_table">
<tr> <tr>
<td></td> <td></td>
@ -92,76 +87,5 @@
</tr> </tr>
</table> </table>
</div> </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> </div>

View File

@ -12,47 +12,25 @@
<table class="table main-list"> <table class="table main-list">
<thead> <thead>
<tr> <tr>
<th class="span2"><span class="" title="">Key</span></th> <th class="span2"><span class="" title="">Color</span></th>
<th class="span2">Color</th>
<th class="span2">English</th> <th class="span2">English</th>
<th class="span2">Chiness</th> <th class="span2">Chinese</th>
</tr> </tr>
</thead> </thead>
</table> </table>
</div> </div>
</div> </div>
</div> </div>
<table id="calendars" class="table main-list">
<table id="callendars" class="table main-list">
<thead> <thead>
<tr> <tr>
<th class="span2"></th> <th class="span2"></th>
<th class="span2"></th> <th class="span2"></th>
<th class="span2"></th> <th class="span2"></th>
<th class="span2"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="calendar_list">
<% @calendars.each do |calendar| %> <%= render :partial => "calendar", :collection => @calendars %>
<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> </tbody>
</table> </table>
@ -63,7 +41,7 @@
<div class="row-fluid"> <div class="row-fluid">
<div class="span2"> <div class="span2">
<%= label_tag("color", t("calendar.color")) %> <%= 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>
</div> </div>

View File

@ -95,11 +95,12 @@
<div class="row-fluid"> <div class="row-fluid">
<label for="" class="control-label span3">Calendars</label> <label for="" class="control-label span3">Calendars</label>
<div class="row-fluid span9"> <div class="row-fluid span9">
<select name="" id="" class="span12"> <!-- <select name="" id="" class="span12">
<option value="">calendar 1</option> <option value="">calendar 1</option>
<option value="">calendar 2</option> <option value="">calendar 2</option>
<option value="">calendar 3</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> </div>
<div class="row-fluid"> <div class="row-fluid">

View File

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