Created
March 12, 2014 07:14
-
-
Save amine2233/a27fccba3a4eec72b0a7 to your computer and use it in GitHub Desktop.
CakePhp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function autocomplete() { | |
$this->request->params['named']['filter'] = $this->request->data[$this->modelClass]['filter']; | |
if (!empty($this->request->params['named']['filter']) || $this->request->params['named']['filter'] !== '') { | |
$this->Prg->commonProcess(); | |
$this->Paginator->settings = array( | |
'conditions' => $this->Location->parseCriteria($this->Prg->parsedParams()), | |
); | |
$this->set('locations', $this->Paginator->paginate()); | |
} | |
$this->render('autocomplete', 'ajax'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
<div class="col-lg-offset-3 col-lg-6"> | |
<?php | |
echo $this->Form->create('Location', array( | |
'url' => array('controller' => 'locations', 'action' => 'find'), | |
'inputDefaults' => array( | |
'div' => false, | |
) | |
) | |
); | |
?> | |
<div class="input-group"> | |
<?php | |
echo $this->Form->input('filter', array('label' => '', 'type' => 'text', 'class' => "form-control", | |
'placeholder' => 'Recherche', 'id' => 'InputRecherche'), array('escape' => false)); | |
?> | |
<span class="input-group-btn"> | |
<?php | |
echo $this->Form->button('<span class="glyphicon glyphicon-search"/>', array( | |
'class' => 'btn btn-default', | |
)); | |
?> | |
</span> | |
</div> | |
<?php echo $this->Form->end(); ?> | |
<?php | |
$update = "#Recherche"; | |
$before = $this->Js->get("#loading")->effect('fadeIn', array('buffer' => false)); | |
$complete = $this->Js->get('#loading')->effect('fadeOut', array('buffer' => false)); | |
$data = $this->Js->get('#InputRecherche')->serializeForm(array('isForm' => true, 'inline' => true)); | |
echo $this->Js->get("#InputRecherche")->event('keyup', $this->Js->request( | |
array('controller' => 'locations', 'action' => 'autocomplete'), array( | |
'async' => true, | |
'dataExpression' => true, | |
'method' => 'post', | |
'data' => $data, | |
'update' => $update, | |
'before' => $before, | |
'complete' => $complete, | |
) | |
)); | |
?> | |
</div> | |
</div> | |
<div id="loading" class="center-block"><?php $this->Html->image('load.gif'); ?></div> | |
<div id="Recherche"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* rating method | |
* | |
* @param string $id | |
* @return void | |
* | |
*/ | |
public function rating($id) { | |
$this->Location->id = $id; | |
if (!$this->Location->exists()) { | |
throw new NotFoundException(__('Invalid location')); | |
} | |
if ($this->request->is(array('post', 'put', 'ajax'))) { | |
$this->Location->save(array('rate' => $this->request['data']['value'])); | |
} | |
if ($this->request->is('ajax')) { | |
$this->render('ajax'); | |
} else { | |
return $this->redirect($this->referer()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = "{field: 'rate', value: $('#RatingLocation').val()}"; | |
$this->Js->get("#RatingLocation")->event( | |
'change', $this->Js->request( | |
array('action' => 'rating', $location['Location']['id']), array( | |
'update' => '#View', | |
'data' => $data, | |
'async' => true, | |
'dataExpression' => true, | |
'method' => 'POST' | |
) | |
) | |
); | |
?> | |
<?php | |
echo $this->Form->input('rate', array( | |
'type' => "number", | |
'id' => "some_id", | |
'data-max' => "5", | |
'data-min' => "1", | |
'id' => 'RatingLocation', | |
'class' => "rating", | |
'value' => $location['Location']['rate'] | |
)); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function available($id = null) { | |
$this->Location->id = $id; | |
if (!$this->Location->exists()) { | |
throw new NotFoundException(__('Invalid location')); | |
} | |
if ($this->request->is(array('post', 'put', 'ajax'))) { | |
$this->Location->Data = $this->Location->findById($id); | |
if ($this->Location->Data['Location']['available'] == false) { | |
$available = true; | |
} else { | |
$available = false; | |
} | |
if ($this->Location->save(array('available' => $available))) { | |
$this->Session->setFlash(__('The location has been available.'), 'flash', array( | |
'alert' => 'success')); | |
} | |
} else { | |
$this->Session->setFlash(__('The location could not be available. Please, try again.'), 'flash', array( | |
'alert' => 'danger')); | |
} | |
if ($this->request->is('ajax')) { | |
if ($available) { | |
$response = 'Available'; | |
$class = 'success'; | |
} else { | |
$response = 'Not Available'; | |
$class = 'danger'; | |
} | |
$this->set(compact('id', 'class', 'response')); | |
$this->render('available', 'ajax'); | |
} else { | |
return $this->redirect($this->referer()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ($location['Location']['available'] == true): ?> | |
<?php | |
echo $this->Js->link('<div id="available' . $location['Location']['id'] . '" ><span class="label label-success">Available</span></div>', array( | |
'action' => 'available', | |
$location['Location']['id'], | |
$location['Location']['available']), array( | |
'escape' => false, | |
'update' => "#available" . $location['Location']['id'], | |
'before' => $this->Js->get("#loading")->effect('fadeIn', array('buffer' => false)), | |
'complete' => $this->Js->get('#loading')->effect('fadeOut', array('buffer' => false)), | |
)); | |
?> | |
<?php else: ?> | |
<?php | |
echo $this->Js->link('<span id="available' . $location['Location']['id'] . '" class="label label-danger">Not Available</span>', array( | |
'action' => 'available', | |
$location['Location']['id'], | |
$location['Location']['available']), array( | |
'escape' => false, | |
'update' => "#available" . $location['Location']['id'], | |
'before' => $this->Js->get("#loading")->effect('fadeIn', array('buffer' => false)), | |
'complete' => $this->Js->get('#loading')->effect('fadeOut', array('buffer' => false)), | |
)); | |
?> | |
<?php endif; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo $this->Js->link('<i class="glyphicon glyphicon-plus"></i>', array( | |
'action' => 'contacted', | |
$location['Location']['id'], | |
'up'), array( | |
'escape' => false, | |
'update' => "#ContactedValue" . $location['Location']['id'], | |
'before' => $this->Js->get("#loading")->effect('fadeIn'), | |
'complete' => $this->Js->get('#loading')->effect('fadeOut'), | |
)); | |
?> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="pagination pagination-large"> | |
<ul class="pagination"> | |
<?php | |
//echo $this->Paginator->first('First', array('escape' => false, 'tag' => 'li'), null, array('escape' => false, 'tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a')); | |
echo $this->Paginator->prev( | |
'«', | |
array('escape' => false, 'tag' => 'li'), | |
null, | |
array( | |
'escape' => false, | |
'tag' => 'li', | |
'class' => 'disabled', | |
'disabledTag' => 'a')); | |
echo $this->Paginator->numbers( | |
array( | |
'separator' => '', | |
'currentTag' => 'a', | |
'currentClass' => 'active', | |
'tag' => 'li', | |
'first' => 1)); | |
echo $this->Paginator->next( | |
'»', | |
array( | |
'escape' => false, | |
'tag' => 'li', | |
'currentClass' => 'disabled'), | |
null, | |
array( | |
'escape' => false, | |
'tag' => 'li', | |
'class' => 'disabled', | |
'disabledTag' => 'a')); | |
//echo $this->Paginator->last('Last',array('escape' => false, 'tag' => 'li', 'currentClass' => 'disabled'), null, array('escape' => false, 'tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a')); | |
?> | |
</ul> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="pagination pagination-large"> | |
<ul class="pagination"> | |
<?php | |
$this->Paginator->options(array( | |
'update' => '#View', | |
'evalScript' => true, | |
'before' => $this->Js->get("#loading")->effect('fadeIn', array('buffer' => false)), | |
'complete' => $this->Js->get('#loading')->effect('fadeOut', array('buffer' => false)), | |
)); | |
//echo $this->Paginator->first('First', array('escape' => false, 'tag' => 'li'), null, array('escape' => false, 'tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a')); | |
echo $this->Paginator->prev( | |
'«', | |
array('escape' => false, 'tag' => 'li'), | |
null, | |
array( | |
'escape' => false, | |
'tag' => 'li', | |
'class' => 'disabled', | |
'disabledTag' => 'a')); | |
echo $this->Paginator->numbers( | |
array( | |
'separator' => '', | |
'currentTag' => 'a', | |
'currentClass' => 'active', | |
'tag' => 'li', | |
'first' => 1)); | |
echo $this->Paginator->next( | |
'»', | |
array( | |
'escape' => false, | |
'tag' => 'li', | |
'currentClass' => 'disabled'), | |
null, | |
array( | |
'escape' => false, | |
'tag' => 'li', | |
'class' => 'disabled', | |
'disabledTag' => 'a')); | |
//echo $this->Paginator->last('Last',array('escape' => false, 'tag' => 'li', 'currentClass' => 'disabled'), null, array('escape' => false, 'tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a')); | |
?> | |
</ul> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = "{field: 'rate', value: $('#RatingLocation').val()}"; | |
$this->Js->get("#RatingLocation")->event( | |
'change', $this->Js->request( | |
array('action' => 'rating', $location['Location']['id']), array( | |
'update' => '#View', | |
'data' => $data, | |
'async' => true, | |
'dataExpression' => true, | |
'method' => 'POST' | |
) | |
) | |
); | |
?> | |
<?php | |
echo $this->Form->input('rate', array( | |
'type' => "number", | |
'id' => "some_id", | |
'data-max' => "5", | |
'data-min' => "1", | |
'id' => 'RatingLocation', | |
'class' => "rating", | |
'value' => $location['Location']['rate'] | |
)); | |
?> | |
<?php echo $this->Html->script('bootstrap-rating-input', array('inline' => false)); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function validate_message() { | |
if ($this->request->is('ajax')) { | |
$location = $this->Location->create(); | |
$location['Location'][$this->request['data']['field']] = $this->request['data']['value']; | |
$this->Location->set($location); | |
$error = $this->validateErrors($this->Location); | |
if ($this->Location->validates($location)) { | |
$this->autoRender = FALSE; | |
$this->autoLayout = ''; | |
} else { | |
$errors = $this->validateErrors($this->Location); | |
foreach ($errors[$this->request['data']['field']] as $key => $value) { | |
$error = $value; | |
} | |
$this->set(compact('error')); | |
$this->render('validate_message', 'ajax'); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php echo $this->Form->input('name', array('id' => 'Name')); ?> | |
<?php | |
$update = "#error"; | |
$before = $this->Js->get("#loading")->effect('fadeIn', array('buffer' => false)); | |
$complete = $this->Js->get('#loading')->effect('fadeOut', array('buffer' => false)); | |
$data = "{field: 'name', value: $('#Name').val()}"; | |
echo $this->Js->get("#Name")->event('blur', $this->Js->request( | |
array('controller' => 'locations', 'action' => 'validate_message'), array( | |
'async' => true, | |
'dataExpression' => true, | |
'method' => 'post', | |
'data' => $data, | |
'update' => $update, | |
'before' => $before, | |
'complete' => $complete, | |
) | |
) | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment