javascript - jQuery Ajax call not working 100% in Rails app -


ajax call, triggers twice if 1 card moved onto stack. there many stacks. if cards changed around on same stack, call triggered once.

ajax call sends array of ids each record/card repositioned. method in controller repositions them based on sequence.

somehow process seems work 3/4 calls.

   $( ".row" ).sortable({      connectwith: ".row",      handle: ".portlet-header",      cancel: ".portlet-toggle",      placeholder: "portlet-placeholder ui-corner-all",      update: function (event, ui) {        var data = {           'positions' : $(this).sortable('toarray', {attribute: "data-item"}),              'dates' : $(this).sortable('toarray', {attribute: "data-date"}),            'newdate' : $(this).closest('.row').attr("data-row-date")         }            // return ids in order           $.ajax({             type: "patch",             async: true,             url: "/ticket_board/reposition_cards.json",             data: json.stringify(data),             datatype: 'json',             contenttype: 'application/json'          });        }      }); 

sample params (drag-n-drop cards order jquery sortable).

started patch "/ticket_board/reposition_cards.json" ::1 @ 2015-05-14 08:25:38 -0500 processing ticketboardcontroller#reposition_cards json   parameters: {"positions"=>["5", "8", "13", "1"], "dates"=>["2015-04-20", "2015-04-20", "2015-04-21", "2015-04-18"], "newdate"=>"2015-04-20", "ticket_board"=>{"positions"=>["5", "8", "13", "1"], "dates"=>["2015-04-20", "2015-04-20", "2015-04-21", "2015-04-18"], "newdate"=>"2015-04-20"}} 

the controller method, ajax call seems work 75% of time. critical client. need help.

  def reposition_cards      dates = params[:ticket_board][:dates]     positions = params[:ticket_board][:positions]      if dates or positions        # move job on same stack       if dates.size > 1 , dates.uniq.size == 1         positions.each_with_index |ticket_id, index|           ticket.find(ticket_id).update(calendar_order: index)         end        # move job empty stack       elsif dates.size == 1           positions.each_with_index |ticket_id, index|             ticket.find(ticket_id).               update(calendar_order: index, calendar_date: params[:newdate])           end         # useless case        elsif dates.size == 0          nil         # add job existing stack        elsif dates.size > 1 , dates.uniq.size == 2          positions.each_with_index |ticket_id, index|            ticket.find(ticket_id).              update(calendar_order: index,               calendar_date: params[:newdate])          end        end      end      respond_to |format|        format.json { render json: @tickets, status: :ok }      end    end 

from comment above.

sometimes seem find answer after posting question. if closely @ params, you'll see 3 unique dates, , controller recognizes 2. i've changed line dates.uniq.size == 2 dates.uniq.size > 1


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -