Welcome Guest, Not a member yet? Register   Sign In
Javascript - array of objects, exchage values
#3

[eluser]SPeed_FANat1c[/eluser]
you mean by setting all fields to 0 and only assigning 1 to which had moved down?

What if admin moves the link down several times (e.g. from place 0 to place 2) Ok, we could increase that value by one on each move down.

Then admin wants to move down another link, then suddenly he decides to move up the link he moved donn earlier. This gets so confusing. And by sending that data to server, we will have to have a php function which figures out what link is in what place by those numbers. And then save to database.

What I want is to have some array with current places after all movements up and down so I could send it to a controller which simply saves it to database.

The table look like this:
Code:
<tbody><tr>
<th>Pavadinimas</th><th>Nuoroda</th><th>Apibūdinimas</th><th>Redagavimas</th><th>Trynimas</th><th>Kilnojimas</th></tr>
<tr>
<td>test</td><td>www.google.lt</td><td>paieska</td><td><a href="http://localhost/darzelis/admin_/nuorodos/redaguoti/1"><img src="http://localhost/darzelis/images/admin/application_form_edit.png"></a></td><td><a class="trinti" id="trinti_1" href="http://localhost/darzelis/admin_/nuorodos/trinti/1"><img src="http://localhost/darzelis/images/admin/delete.png"></a></td><td><a class="down" id="down_1" href="#"><img src="http://localhost/darzelis/images/admin/arrow_down.png"></a></td></tr>
<tr>
<td>asd</td><td>http://asd.lt</td><td>apib</td><td><a href="http://localhost/darzelis/admin_/nuorodos/redaguoti/2"><img src="http://localhost/darzelis/images/admin/application_form_edit.png"></a></td><td><a class="trinti" id="trinti_2" href="http://localhost/darzelis/admin_/nuorodos/trinti/2"><img src="http://localhost/darzelis/images/admin/delete.png"></a></td><td><a class="up" id="up_2" href="#"><img src="http://localhost/darzelis/images/admin/arrow_up.png"></a><a class="down" id="down_2" href="#"><img src="http://localhost/darzelis/images/admin/arrow_down.png"></a></td></tr>
<tr>
<td>asd</td><td>http://asd.lt</td><td>apib</td><td><a href="http://localhost/darzelis/admin_/nuorodos/redaguoti/3"><img src="http://localhost/darzelis/images/admin/application_form_edit.png"></a></td><td><a class="trinti" id="trinti_3" href="http://localhost/darzelis/admin_/nuorodos/trinti/3"><img src="http://localhost/darzelis/images/admin/delete.png"></a></td><td><a class="up" id="up_3" href="#"><img src="http://localhost/darzelis/images/admin/arrow_up.png"></a></td></tr>
</tbody>


I am trying now do this:

Code:
$('a.down').live('click',function(){
         id = this.id.replace('down_', "");
         place = -1;
         //find a place of link
        
         $.each(places, function(i, field){
            if(field.name == 'link_'+id)
            {
                place = field.value;
                console.log('vieta ' + place);
            }
         });
                  
         //find an id of the lower link
         lower_link_id = -1;
         $.each(places, function(i, field){
            console.log('tikrinam ' + field.value + (place+1));
            place_of_lower_link = place + 1;
            
            if(field.value == place_of_lower_link)
            {    
                lower_link_id = (field.name).replace('link_',"");
                
            }
         });
        
         console.log(lower_link_id);
        
        
         return false;
     });

It is not finished. But this code is also so confusing. How the hell can be so much code to change only two values? Big Grin In codeigniter php + mysql with page refresh on each click there would be few lines Smile


Edit: I am thinking now that there is no need to only update database when all movements are finished. I'll update database on each move up or down. It uses more server resourses but still that is so small usage that nobody ever notice Smile so there is no need to do it too perfect. Will do it tomorow, today I am sick of this javascript - so much time wasted and no result.
Thanks for the replay btw Smile


Messages In This Thread
Javascript - array of objects, exchage values - by El Forum - 12-14-2010, 09:49 AM
Javascript - array of objects, exchage values - by El Forum - 12-14-2010, 10:42 AM
Javascript - array of objects, exchage values - by El Forum - 12-14-2010, 11:30 AM
Javascript - array of objects, exchage values - by El Forum - 12-15-2010, 06:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB