This commit is contained in:
Mark van Driel 2017-02-12 20:55:02 +01:00
commit ec6fa53be4

View file

@ -24,22 +24,22 @@ function PostList(element,template) {
var li = $(this).parent('li'); var li = $(this).parent('li');
var id = li.find('span.id').text(); var id = li.find('span.id').text();
var content = li.find('span.content').text(); var content = li.find('span.content').text();
content = prompt('Value',content); content = prompt('Value', content);
if (content!==null) { if (content!==null) {
$.ajax({url:url+'/'+id, type: 'PUT', data: {content:content}, success:self.update}); $.ajax({url: url + '/' + id, type: 'PUT', data: {content: content}, success: self.update});
} }
}; };
self.delete = function() { self.delete = function() {
var li = $(this).parent('li'); var li = $(this).parent('li');
var id = li.find('span.id').text(); var id = li.find('span.id').text();
if (confirm("Deleting #"+id+". Continue?")) { if (confirm("Deleting #" + id + ". Continue?")) {
$.ajax({url:url+'/'+id, type: 'DELETE', success:self.update}); $.ajax({url: url + '/' + id, type: 'DELETE', success: self.update});
} }
}; };
self.submit = function(e) { self.submit = function(e) {
e.preventDefault(); e.preventDefault();
var content = $(this).find('input[name="content"]').val(); var content = $(this).find('input[name="content"]').val();
$.post(url, {user_id:1,category_id:1,content:content}, self.update); $.post(url, {user_id: 1, category_id: 1, content: content}, self.update);
}; };
self.render = function(data) { self.render = function(data) {
data = php_crud_api_transform(data); data = php_crud_api_transform(data);
@ -58,17 +58,20 @@ function PostList(element,template) {
$.get(url, self.render); $.get(url, self.render);
}; };
self.post = function() { self.post = function() {
$.post(url, {user_id:1,category_id:1,content:"from zepto"}, self.update); $.post(url, {user_id: 1, category_id: 1, content: "from zepto"}, self.update);
}; };
element.on('submit','form',self.submit); element.on('submit', 'form', self.submit);
element.on('click','a.edit',self.edit) element.on('click', 'a.edit', self.edit);
element.on('click','a.delete',self.delete) element.on('click', 'a.delete', self.delete);
self.post(); self.post();
}; };
$(function(){ new PostList($('#PostListDiv'),$('#PostListTemplate')); }); $(function(){
new PostList($('#PostListDiv'), $('#PostListTemplate'));
});
</script> </script>
</head> </head>
<body> <body>
<div id="PostListDiv">Loading...</div> <div id="PostListDiv">Loading...</div>
</body> </body>
</html> </html>