Permalink
Browse files

finishing delete-ads

  • Loading branch information...
1 parent b5b2bb7 commit 79a99560382e69646c294e16cbfb60ee3981303e futura-creative committed Feb 19, 2013
View
@@ -7,4 +7,5 @@ app/[Cc]onfig/database.php
!empty
!/app/Config/core.php
!/app/tmp/cache/
-!/app/tmp/log/
+!/app/tmp/log/
+!/app/tmp/logs/
@@ -17,14 +17,15 @@ class AdsController extends AppController {
'Session',
'Paginator'
);
+
public $paginate = array(
'limit' => 10,
'order' => 'Ad.id DESC'
);
public function beforeFilter() {
parent::beforeFilter();
- $this->Auth->allow(array('index','add','refresh','search'));
+ $this->Auth->allow(array('index','refresh','search'));
}
public function index(){
@@ -58,7 +59,7 @@ public function add(){
if($this->Ad->validates()){
if($this->Ad->save()){
if($image!=null)move_uploaded_file($image['tmp_name'],$filePath);
- $this->set('ads',$this->request->data['Ad']);
+ $this->set('ads',$this->Ad->findById($this->Ad->id));
$this->set('user',$this->Auth->user());
$this->render('add');
}
@@ -111,6 +112,22 @@ public function search(){
$this->redirect(array("controller"=>'ads',"action"=>"index"));
}
}
+
+ public function delete(){
+ if($this->request->is("Ajax")){
+ $id = $this->request->data['id'];
+ $this->autoRender = False;
+ $this->autoLayout = False;
+ if($this->Ad->delete($id)){
+ $message = array("status"=>1);
+ echo json_encode($message);
+ }
+ else{
+ $message = array("status"=>0);
+ echo json_encode($message);
+ }
+ }
+ }
}
?>
View
@@ -1,12 +1,17 @@
<div class="Ads-box box-shadow">
<div class="Ads-image">
- <?= $this->Html->image('../files/'.$ads['image'],array('class'=>'Ads-image')) ?>
+ <?= $this->Html->image('../files/'.$ads['Ad']['image'],array('class'=>'Ads-image')) ?>
</div>
<div class="Ads-content">
- <h2><?= $ads['ads_title'] ?></h2>
- <p><?= $ads['ads_body'] ?></p>
+ <h2><?= $ads['Ad']['ads_title'] ?></h2>
+ <p><?= $ads['Ad']['ads_body'] ?></p>
</div>
<div class="Ads-contact">
- <strong>C : <?= $user['first_name']." ".$user['last_name'] ?> <br/> +62<?= $user['handphone'] ?> </strong>
+ <strong>C : <?= $ads['User']['first_name']." ".$ads['User']['last_name'] ?> <br/> +62<?= $ads['User']['handphone'] ?> </strong>
</div>
+ <?php if($loggedInUser['id'] == $ads['User']['id']): ?>
+ <div>
+ <?= $this->Html->link('delete',array("controller"=>"ads","action"=>"delete"),array('class'=>'delete-link','aid'=>hash("sha256",rand(1000000,1000000000000000000000000000000000)),'ad'=>$ads['Ad']['id'])); ?>
+ </div>
+ <?php endif; ?>
</div>
View
@@ -49,6 +49,13 @@
<div class="Ads-contact">
<strong>C : <?= $ad['User']['first_name']." ".$ad['User']['last_name'] ?> <br/> +62<?= $ad['User']['handphone'] ?> </strong>
</div>
+ <?php if($loggedInUser['id'] == $ad['User']['id']): ?>
+ <div class="menu-ads">
+ <?= $this->Html->link('hapus',array("controller"=>"ads","action"=>"delete"),array('class'=>'delete-link','aid'=>hash("sha256",rand(1000000,1000000000000000000000000000000000)),'ad'=>$ad['Ad']['id'])); ?>
+ |
+ <?= $this->Html->link('edit',array("controller"=>"ads","action"=>"edit"),array('class'=>'edit-link','aid'=>hash("sha256",rand(1000000,1000000000000000000000000000000000)),'ad'=>$ad['Ad']['id'])); ?>
+ </div>
+ <?php endif; ?>
</div>
<?php endforeach; ?>
</div>
@@ -57,7 +64,10 @@
</div>
<?= $this->Html->script('jquery.ads-add'); ?>
<?= $this->Html->script('jquery.refresh'); ?>
+<?= $this->Html->script('jquery.edit.delete'); ?>
<script>
+
+
$('#content-inside').masonry({
itemSelector: '.Ads-box'
});
@@ -73,7 +83,25 @@
},
function( newElements ) {
$elem = $(newElements);
+ $elem.find('.delete-link').click(function(e){
+ e.preventDefault();
+ if(window.confirm("Apakah anda yakin ingin menghapus iklan ini?")){
+ $(this).parent().parent().addClass('delete-mark');
+ $.post($(this).attr("href"),{id:$(this).attr("ad")},handleDelete,"JSON");
+ }
+ });
+
+ function handleDelete(response){
+ if(response.status == 1){
+ $(".delete-mark").fadeOut("fast").remove();
+ $('#content-inside').masonry('reload');
+ }
+ else{
+ alert("Penghapusan Iklan gagal. Silahkan refresh halaman ini");
+ }
+ }
$("#content-inside").masonry('appended',$elem,true);
+
}
);
</script>
View
@@ -11,5 +11,10 @@
<div class="Ads-contact">
<strong>C : <?= $ad['User']['first_name']." ".$ad['User']['last_name'] ?> <br/> +62<?= $ad['User']['handphone'] ?> </strong>
</div>
+ <?php if($loggedInUser['id'] == $ad['User']['id']): ?>
+ <div>
+ <?= $this->Html->link('delete',array("controller"=>"ads","action"=>"delete"),array('class'=>'delete-link','aid'=>hash("sha256",rand(1000000,1000000000000000000000000000000000)),'ad'=>$ad['Ad']['id'])); ?>
+ </div>
+ <?php endif; ?>
</div>
<?php endforeach; ?>
View
@@ -12,6 +12,11 @@
<div class="Ads-contact">
<strong>C : <?= $ad['User']['first_name']." ".$ad['User']['last_name'] ?> <br/> +62<?= $ad['User']['handphone'] ?> </strong>
</div>
+ <?php if($loggedInUser['id'] == $ad['User']['id']): ?>
+ <div>
+ <?= $this->Html->link('delete',array("controller"=>"ads","action"=>"delete"),array('class'=>'delete-link','aid'=>hash("sha256",rand(1000000,1000000000000000000000000000000000)),'ad'=>$ad['Ad']['id'])); ?>
+ </div>
+ <?php endif; ?>
</div>
<?php endforeach; ?>
</div>
@@ -21,6 +26,7 @@
<div id="page-nav" style="position:relative; display:none">
<?php echo $this->paginator->numbers(); ?>
</div>
+<?= $this->Html->script('jquery.edit.delete'); ?>
<script>
$('#content-inside').masonry({
itemSelector: '.Ads-box'
@@ -37,8 +43,27 @@
},
function( newElements ) {
$elem = $(newElements);
+ $elem.find('.delete-link').click(function(e){
+ e.preventDefault();
+ if(window.confirm("Apakah anda yakin ingin menghapus iklan ini?")){
+ $(this).parent().parent().addClass('delete-mark');
+ $.post($(this).attr("href"),{id:$(this).attr("ad")},handleDelete,"JSON");
+ }
+ });
+
+ function handleDelete(response){
+ if(response.status == 1){
+ $(".delete-mark").fadeOut("fast").remove();
+ $('#content-inside').masonry('reload');
+ }
+ else{
+ alert("Penghapusan Iklan gagal. Silahkan refresh halaman ini");
+ }
+ }
$("#content-inside").masonry('appended',$elem,true);
+
}
+
);
</script>
<style>
@@ -58,7 +58,7 @@ $cakeDescription = __d('cake_dev', 'CakePHP: the rapid development php framework
</div>
<a id="arrow" class='arrow' href='javascript:void(0)'></a>
<ul id="menu" class='menu'>
- <li>Setting Profil</li>
+ <li><?= $this->Html->link("Edit Profil",array("controller"=>"users","action"=>"edit")); ?></li>
<li><?= $this->Html->link('Logout',array('controller'=>'users','action'=>'logout')); ?></li>
</ul>
</div>
@@ -1,2 +1,2 @@
-1361189628
+1361254200
a:10:{s:2:"id";a:5:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:10;s:3:"key";s:7:"primary";}s:9:"ads_title";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:40;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:8:"ads_body";a:6:{s:4:"type";s:4:"text";s:4:"null";b:0;s:7:"default";N;s:6:"length";N;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:11:"category_id";a:4:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:4;}s:7:"user_id";a:4:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:10;}s:7:"city_id";a:4:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:4;}s:8:"state_id";a:4:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:4;}s:10:"issue_date";a:4:{s:4:"type";s:4:"date";s:4:"null";b:0;s:7:"default";N;s:6:"length";N;}s:10:"issue_time";a:4:{s:4:"type";s:4:"time";s:4:"null";b:0;s:7:"default";N;s:6:"length";N;}s:5:"image";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:100;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}}
@@ -1,2 +1,2 @@
-1361189628
+1361254200
a:2:{s:2:"id";a:5:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:4;s:3:"key";s:7:"primary";}s:5:"cname";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:40;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}}
@@ -1,2 +1,2 @@
-1361189628
+1361254200
a:3:{s:2:"id";a:5:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:4;s:3:"key";s:7:"primary";}s:5:"cname";a:6:{s:4:"type";s:6:"string";s:4:"null";b:1;s:7:"default";N;s:6:"length";i:100;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:5:"state";a:4:{s:4:"type";s:7:"integer";s:4:"null";b:1;s:7:"default";N;s:6:"length";i:3;}}
@@ -1,2 +1,2 @@
-1361189628
+1361254200
a:5:{i:0;s:3:"ads";i:1;s:10:"categories";i:2;s:6:"cities";i:3;s:6:"states";i:4;s:5:"users";}
@@ -1,2 +1,2 @@
-1361189628
+1361254200
a:2:{s:2:"id";a:5:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:3;s:3:"key";s:7:"primary";}s:5:"sname";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:30;s:7:"collate";s:15:"utf8_general_ci";s:7:"charset";s:4:"utf8";}}
@@ -1,2 +1,2 @@
-1361189628
+1361254200
a:14:{s:2:"id";a:5:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:10;s:3:"key";s:7:"primary";}s:10:"first_name";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:30;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:9:"last_name";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:30;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:8:"username";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:40;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:8:"password";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:40;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:13:"jenis_kelamin";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:1;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:9:"tgl_lahir";a:4:{s:4:"type";s:4:"date";s:4:"null";b:0;s:7:"default";N;s:6:"length";N;}s:6:"alamat";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:50;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:5:"state";a:4:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:4;}s:4:"city";a:4:{s:4:"type";s:7:"integer";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:4;}s:9:"handphone";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";N;s:6:"length";i:12;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:17:"security_question";a:6:{s:4:"type";s:4:"text";s:4:"null";b:0;s:7:"default";N;s:6:"length";N;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:15:"security_answer";a:6:{s:4:"type";s:4:"text";s:4:"null";b:0;s:7:"default";N;s:6:"length";N;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}s:6:"status";a:6:{s:4:"type";s:6:"string";s:4:"null";b:0;s:7:"default";s:1:"1";s:6:"length";i:1;s:7:"collate";s:17:"latin1_swedish_ci";s:7:"charset";s:6:"latin1";}}
@@ -1,2 +1,2 @@
-1361189628
+1361254200
a:1:{s:11:"LC_MESSAGES";a:0:{}}
View
@@ -1,2 +1,2 @@
-1361189628
+1361254200
a:1:{s:11:"LC_MESSAGES";a:0:{}}
@@ -1,2 +1,2 @@
-1361189628
+1361254124
a:1:{s:11:"LC_MESSAGES";a:0:{}}
Oops, something went wrong.

0 comments on commit 79a9956

Please sign in to comment.