arshadulla / jquery-week-calendar

Automatically exported from code.google.com/p/jquery-week-calendar
0 stars 0 forks source link

if i added two consecutive events without refresh they are added at the same time slot #135

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
if i added an event and then refresh the page and add another it works fine but 
if i added an event and then added another one without refreshing the page 
first it's saved in the same time slot .

my guess that some variables keep their value until page is refreshed but i 
couldn't know which variable is the error.

i am using $.ajax calls to send and get and modify data from database

and this is the code:

javascript side :

'eventNew':function(calEvent, $event) { 
    calendar_new_entry(calEvent,$event); 
    }
    });
    });

    function calendar_new_entry(calEvent,$event)
    {
                var ds=calEvent.start;
                var df=calEvent.end;

                var body = $('#calendar_new_entry_form_body').val(''); 
                var title = $('#calendar_new_entry_form_title').val('') ;

            $("#calendar_new_entry_form").dialog({ 

            autoOpen: false, 
            height: 440, 
            width: 550, 
            modal: true,
            close: function()   // onClose
                {
                    $('#calendar_wrapper').weekCalendar('removeUnsavedEvents');
                },
            buttons: 
            {
                'Save': function() 
                {

                    var body = $('#calendar_new_entry_form_body').val(); 
                    var title = $('#calendar_new_entry_form_title').val() ;

                    var data = {body: body,title:title,start:ds.getTime()/1000,end:df.getTime()/1000};

                    $.ajax({
                                        type:       'POST',
                                        url:        baseUrl+'calendar/add',
                                        data:       data,
                                        dataType:   'json',
                                        success:    function(json)
                                        {
                                            if (json.status == "success")   // the user was added to the database
                                            {
                                                alert('done');

                                                $("#calendar_wrapper").weekCalendar("refresh");
                                            }
                                        }
                                                                              });

                    $(this).dialog('close');
}

and this is the php side :

function add()
        {
            $start = date('c',(int)($this->input->post('start')+3600));
            $end = date('c',(int)($this->input->post('end')+3600));
            $title = $this->input->post('title');
            $body = $this->input->post('body');

            $data = array(
                       'start' => $start,
                       'end' => $end,
                       'title' => $title,
                       'body' => $body

                    );

                    if($this->events->add($data))
                    {

                        $return = array(

                        'status'    =>      'success',
                        'message'   =>      'Event has been saved'

                    );
                    // print out a JSON encoded success message
                    echo json_encode($return);

                }
                else
                {

                    $return = array(

                        'status'    =>      'failed',
                        'message'   =>      'Failed to save this event'

                    );

                    // print out a JSON encoded error message
                    echo json_encode($return);

                }

        }

I also forgot to mention that i am using codeigniter so the previous code is 
the controller and this code is for the model :

function add($data)
        {
            $this->db->insert('events', $data);
            return $this->db->insert_id();
        }

thanks in advance for help

Original issue reported on code.google.com by jokira...@gmail.com on 1 Sep 2012 at 5:25

GoogleCodeExporter commented 8 years ago
Thanks i solved the problem by making these variables var ds=calEvent.start; 
var df=calEvent.end; global and defining them when a new event is created i was 
too stupid that i didn't trace these variables and find that they stay the same 
each time

Original comment by jokira...@gmail.com on 1 Sep 2012 at 5:45