Amigos, estoy trabajando con Hoteles que se le asignan categorias. Necesito eliminar un hotel pero no se puede pues tiene categorias asignadas. Lo que quiero lograr hacer es lo siguiente:
Al poner eliminar le mando el siguiente script :
Código Javascript
:
Ver original<script>
$(function(){
$('.option_delete').on('click', function (e) {
modal.confirm('<?=h(__('Do you really want to delete this Hotel?'));?>', function () {
window.location.href = '<?php echo $this->Html->url(array('controller' => 'hotels',
'action' => 'delete',
$hotels['Hotel']['id']));?>';
});
});
});
</script>
Aqui se le deberia decir que no se puede eliminar porque tiene asignado X cantidad de categorias y preguntarle si quiere asignar esas categorias a otro Hotel, si el pone que si, mostrarle una especie de lista de los Hoteles que hay disponibles, el seleccionarlo y seguir el procedimiento.
Codigo de eliminar:
Código PHP:
Ver originalpublic function admin_delete($id = null) {
$this->Hotel->id = $id;
if (!$this->Hotel->exists())
throw new NotFoundException(__('Invalid Hotel'));
$resultSelected= $this->Hotel->Category->find('count', array('conditions'=>array('Category.hotel_id' => $id))); if ($resultSelected > 0)
//throw new RuntimeException(__('There are categories bind to this Hotel, unbind and try again.'));
if (!$this->Hotel->delete())
throw new RuntimeException(__('The role couldn\'t be deleted. Try again'));
$this->Session->setSuccess(__('Hotel successfully deleted'));
$this->redirect(array('action' => 'index')); }
Alguna idea de como hacerlo??? Slds.