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 78089ac7..076e44b3 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 @@ -82,12 +82,12 @@ var calendarAPI = function(){ month = dt.getMonth()+1; year = dt.getFullYear(); } - // month = 2; + // month = 10; // year = 2008; c.cur_month = month; c.cur_year = year; $('#view_holder').load("cals/month_view?month="+month+"&year="+year, function() { - getEvents(month,year); + c.getEvents(month,year); $('.current_day_title').text(c.monthlist[c.cur_month]+" "+c.cur_year); if($('#calendar_month').length > 0){ var $c_table = $('#calendar_month'); @@ -111,71 +111,109 @@ var calendarAPI = function(){ }); } }) - var getEvents = function(month,year){ - $.getJSON("cals/getEvents",{"type":"monthview","month":month,"year":year},function(events){ - var $eventrow = $(""); - var nos = new Array(); - var currow = 0; - var lastno = 0; - nos.push(0); - $.each(events,function(i,evnt){ + + } + + this.getEvents = function(month,year){ + $.getJSON("cals/getEvents",{"type":"monthview","month":month,"year":year},function(events){ + makerow(events); + }) + var doneEventArray = new Array(); + var makerow = function(events){ + var $eventrow =null; + var currow = 0; + var curdate = 0; + var allow = false; + var curparent = null; + var lastno = 0; + var indexcount = events.length; + $.each(events,function(i,evnt){ + indexcount++; + if($.inArray(evnt.index,doneEventArray) == -1){ + var daydom = $("#calendar_month td[date="+evnt.start_date+"]"); - var curparent = daydom.parent().parent().parent(); - var thisrow = curparent.attr("row"); - var pos = daydom.attr("position"); + var thisparent = daydom.parent().parent().parent(); + var thisrow = thisparent.attr("row"); + var pos = parseInt(daydom.attr("position")); var thisno = daydom.attr("no"); + if(thisrow != currow){ + if(curparent){ + curparent.append($eventrow); + } + $eventrow = null; + $eventrow = $(""); + allow = true; + }else if(evnt.start_date > curdate){ + allow = true; + + } + var recordcurdate = true; - var index = "new"; - var smallcount = 0; - - for(x in nos){ - if(thisno > nos[x]){ - smallcount++; - } - if(smallcount > 0){ - index = x; - break; - } - } - if(index == "new"){ - nos=[] - $eventrow = null; - $eventrow = $(""); - } - - if(thisrow!=currow){ - $eventrow = null; - $eventrow = $(""); - - } - - if(index!="new"){ - nos[index] = (parseInt(thisno) + parseInt(evnt.total_days)) - 1; - }else{ - nos.push((parseInt(thisno) + parseInt(evnt.total_days)) - 1); - } - if(pos == 1){ - $eventrow.html('
'+evnt.title+'
'); - }else{ - if($eventrow.html()==""){ - $eventrow.append(''); - }else{ - if((lastno+1)!=thisno){ - var inposition = $eventrow.find("td.main_td").attr("pos"); - var colspan = parseInt(pos) - parseInt(inposition); - colspan--; - $eventrow.append(''); + if(allow){ + if(pos == 1){ + var colspan = 0; + if(evnt.total_days>7){ + colspan = 7; + var totaldays = parseInt(evnt.total_days) - colspan; + var stardate = parseInt(evnt.start_date) + colspan; + var index = i + 1; + var tempArray = {"index":indexcount,"id":evnt.id,"start_date":stardate,"total_days":totaldays,"title":evnt.title,"color":evnt.color,"show_link":evnt.show_link}; + events.splice(index,0,tempArray); + //recordcurdate = false; + }else{ + colspan = evnt.total_days; } + $eventrow.html('
'+evnt.title+'
'); + }else{ + if($eventrow.html()==""){ + $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(''); + } + } + var colspan = 0; + if((pos + parseInt(evnt.total_days))-1 > 7){ + colspan = 7-(pos-1); + var totaldays = parseInt(evnt.total_days) - colspan; + var stardate = parseInt(evnt.start_date) + colspan; + + var index = i + 1; + var tempArray = {"index":indexcount,"id":evnt.id,"start_date":stardate,"total_days":totaldays,"title":evnt.title,"color":evnt.color,"show_link":evnt.show_link}; + events.splice(index,0,tempArray); + // recordcurdate = false; + + }else{ + colspan = evnt.total_days; + } + // if(evnt.title == "Again") + // console.log(colspan); + $eventrow.append('
'+evnt.title+'
'); } - $eventrow.append('
'+evnt.title+'
'); + lastno = (parseInt(thisno) + parseInt(evnt.total_days)) - 1; + currow = thisrow; + curdate =(evnt.start_date + evnt.total_days) - 1; + allow = false; + curparent = thisparent; + if(recordcurdate) + doneEventArray.push(evnt.index); + } - lastno = (parseInt(thisno) + parseInt(evnt.total_days)) - 1; - currow = thisrow; - curparent.append($eventrow); - }) + } + }) + if(curparent){ + curparent.append($eventrow); + } + if(events.length != doneEventArray.length){ + makerow(events); + } } } + this.loadWeekView = function(){ $('#view_holder').load("cals/week_view", function() { $('.current_day_title').text('September 2 - 8, 2012'); 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 6330e95b..38e3c18f 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 @@ -58,17 +58,19 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController def get_events month = params[:month] year = params[:year] - events = Event.where(:start_month => month).and(:start_year => year).asc(:start_date) + month = month.to_i + year = year.to_i + events = Event.where(:start_month => month).and(:start_year => year).asc(:start_date).desc(:total_days) @events = Array.new - events.each do |event| + events.each_with_index do |event,i| # @temp = Array.new - no_of_days = Date.new(event.end_year,event.end_month,event.end_date) - Date.new(event.start_year,event.start_month,event.start_date) + no_of_days = event.total_days no_of_days = no_of_days.to_i no_of_days += 1 color = Cal.find(event.cal_id).color - @events << {"start_date"=>event.start_date, "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event)} + @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 = @events.sort{|k,v| v[:total_days] <=> k[:total_days]} + render :json => @events.to_json end 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 ea319cdb..a23a6c4c 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 @@ -23,8 +23,9 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController temp = $start.split("/") start_date = temp[0] start_month = temp[1] - star_year = temp[2] - + start_year = temp[2] + @m = start_month + @y = start_year temp = $end.split("/") end_date = temp[0] end_month = temp[1] @@ -35,10 +36,20 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController cal_id = params[:event][:cal_id] + # if start_am_pm == "PM" + # temp_start_time = $starttime + 12 + # end + # if end_am_pm == "PM" + # temp_end_time = $endtime + 12 + # 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) + total_days = final_end_time - final_start_time @event = Event.new @event.title = title @event.note = note - @event.start_year = star_year + @event.start_year = start_year @event.end_year = end_year @event.start_month = start_month @event.end_month = end_month @@ -49,6 +60,9 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController @event.end_time = $endtime @event.end_am_pm = end_am_pm @event.cal_id = cal_id + @event.final_start_time = final_start_time + @event.final_end_time = final_end_time + @event.total_days = total_days @event.save! respond_to do |h| diff --git a/vendor/built_in_modules/calendar/app/models/event.rb b/vendor/built_in_modules/calendar/app/models/event.rb index 55f37e52..5d0bc3f3 100644 --- a/vendor/built_in_modules/calendar/app/models/event.rb +++ b/vendor/built_in_modules/calendar/app/models/event.rb @@ -14,6 +14,9 @@ class Event field :start_am_pm field :end_time, type: Float field :end_am_pm + field :final_start_time, type: Date + field :final_end_time, type: Date + field :total_days, type: Integer belongs_to :cal diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/create.js.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/create.js.erb index 42efb25c..eee4491b 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/create.js.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/create.js.erb @@ -1,2 +1,4 @@ $("#event_create").empty().hide(); -$("#create_event_btn").removeClass("active"); \ No newline at end of file +$("#create_event_btn").removeClass("active"); +$("#calendar_month tr.event_row").remove(); +calendar.getEvents(<%= @m %>,<%= @y %>); \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/config/locales/zh_tw.yml b/vendor/built_in_modules/calendar/config/locales/zh_tw.yml index d0bb3120..0e3ec155 100644 --- a/vendor/built_in_modules/calendar/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/calendar/config/locales/zh_tw.yml @@ -1,3 +1,4 @@ zh_tw: calendar: - calendars: Calendars \ No newline at end of file + calendars: Calendars + create: Create \ No newline at end of file diff --git a/vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb b/vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb index c20d44f2..c09b1379 100644 --- a/vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb +++ b/vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb @@ -7,7 +7,20 @@ class Panel::Gprs::BackEnd::LocationsController < OrbitBackendController def create debugger @newlocation = Location.new(params[:location]) - render :json => {"success"=>"true"}.to_json + @newlocation.save! + render :action => "index" + end + + def get_locations + locations = Location.all + @data = Array.new + + locations.each do |location| + picurl = "http://"+request.host + location.file.url + thumburl = "http://"+request.host + location.file.thumb.url + @data << {"name"=>location.name,"pic_url"=>picurl,"thumb_url"=>thumburl,"description"=>location.description} + end + render :json => @data.to_json end end diff --git a/vendor/built_in_modules/gprs/config/routes.rb b/vendor/built_in_modules/gprs/config/routes.rb index 501bc5d3..050b2cbd 100644 --- a/vendor/built_in_modules/gprs/config/routes.rb +++ b/vendor/built_in_modules/gprs/config/routes.rb @@ -3,7 +3,9 @@ Rails.application.routes.draw do namespace :gprs do namespace :back_end do - resources :locations + match "locations/get_locations" => "locations#get_locations" + + resources :locations end end