jQuery sortable: how to update database?

2014-02-01 Thread Sam Clauw
Hi there!

I've made a sortable table in my custom CMS system. You can drag and drop 
tr's so they have another position. 

This is the javascript in my sort.ctp file:

script
$(function() {
$('.sortable tbody').sortable({
axis: 'y',
scroll: true,
opacity: 0.5,
revert: 100,
cursor: 's-resize',
items: 'tr.grab',

// volledige breedte van tr behouden

helper: function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
},
stop: function (event, ui) {
var data = $(this).sortable('serialize');

// POST naar server ($.post of $.ajax)

$.ajax({
data: data,
type: 'POST',
url: '?php echo APP . 'CoasterCms' . DS . 'Lib' . DS . 
'sort.php'; ?'
});
}
}).disableSelection();
});
/script

Then, I've made a sort.php file and I've put it in the lib folder of my 
plugin (CoasterCms/Lib/sort.php). Here's the place where the magic should 
happen...
But it doesn't happen at all. The file currently looks like this:

?php

$db = $this-getDataSource();

$db-updateAll(
array( // fields
'Attraction.show' = 'N'
),
array( // conditions
'Attraction.id' = 3
)
);

?

Unfortunately, it does nothing. The baddest thing is that I can't test it 
on errors because I cannot reach the lib file by an url. Is there anybody 
who can guide me on the right way? How can I connect to my database and do 
some update actions on a specific model?

Thanks for helping me ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-01 Thread Salines
You do it in the wrong way. 

In your controller create method and then put the code that will save your 
changes.

use chrome developer tools or firefox firebug to see which values ​​are 
sent via ajax query

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-01 Thread Sam Clauw
Ow yes, you've got me on the right way! I've changed my .ctp file now:

script
$(function() {
$('.sortable tbody').sortable({
axis: 'y',
scroll: true,
opacity: 0.5,
revert: 100,
cursor: 's-resize',
items: 'tr.grab',

// volledige breedte van tr behouden

helper: function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
},
stop: function (event, ui) {
var data = $(this).sortable('serialize');

// POST naar server ($.post of $.ajax)

$.ajax({
data: data,
type: 'POST',
url: '*?php echo $this-here; ?*'
});
}
}).disableSelection();
});
/script

Then, I'll check on a submitted POST in my sort action and will handle the 
update.

One additional thing: where in Chrome developer tools can you see those 
ajax values? Elements, Network, Sources, ...? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.