This repository has been archived by the owner on Sep 4, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '4.2' of github.com:atk4/atk4-addons into 4.2
- Loading branch information
Showing
10 changed files
with
164 additions
and
60 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace filestore; | ||
class Field_Image extends \Field { | ||
function init(){ | ||
parent::init(); | ||
$this->setModel('filestore/Image'); | ||
$this->display(array('form'=>'upload')); | ||
} | ||
function ref($load=true){ | ||
if(!$this->model){ | ||
$this->model=preg_replace('|^(.*/)?(.*)$|','\1Model_\2',$this->getModel()); | ||
$this->model=$this->add($this->model); | ||
} | ||
if(!$load)return $this->model; | ||
if(!$this->get())throw $this->exception('Reference field has no value') | ||
->addMoreInfo('model',$this->owner) | ||
->addMoreInfo('field',$this->short_name) | ||
->addMoreInfo('id',$this->owner->id) | ||
; | ||
return $this->model->load($this->get()); | ||
} | ||
} |
This file contains 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
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
namespace formandsave; | ||
class FormAndSave extends \Form { | ||
function init(){ | ||
parent::init(); | ||
$this->addSubmit('Save'); | ||
|
||
$this->onSubmit(function($f){ | ||
$f->update(); | ||
$f->js()->univ()->successMessage('Saved')->execute(); | ||
}); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
namespace gridorder; | ||
class Controller_GridOrder extends \AbstractController { | ||
public $model; | ||
|
||
function init(){ | ||
parent::init(); | ||
|
||
$l=$this->api->locate('addons','gridorder','location'); | ||
$this->api->pathfinder->addLocation($this->api->locate('addons','gridorder'),array( | ||
'template'=>'templates' | ||
))->setParent($l); | ||
|
||
$this->owner->addButton('Re-order records') | ||
->js('click')->univ()->frameURL('Re-order records', | ||
$this->api->getDestinationURL(null, | ||
array($this->name=>'activate')),array('width'=>'500px')); | ||
|
||
$this->owner->dq->order('ord'); | ||
|
||
if($_GET[$this->name]=='activate'){ | ||
$this->api->stickyGET($this->name); | ||
$this->initFrame(); | ||
} | ||
} | ||
function initFrame(){ | ||
$v=$this->owner->owner->add('View',null,$this->owner->spot); | ||
$_GET['cut_object']=$v->name; | ||
|
||
$lister=$v->add('CompleteLister',null,null,array('view/gridorder')); | ||
$this->model=$m=$this->owner->getModel(); | ||
|
||
if(!$m->hasElement('ord')){ | ||
$m->addField('ord')->system(true); | ||
} | ||
|
||
$lister->setModel($m); | ||
$lister->dq->order('ord'); | ||
|
||
$lister->js(true)->sortable(); | ||
|
||
$v->add('Button')->set('Save')->js('click')->univ()->ajaxec( | ||
array($this->api->getDestinationURL(), | ||
$this->name.'_order'=>$v->js(null,"\$('#{$lister->name}').children().map(function(){ return $(this).attr('data-id'); }).get().join(',')") | ||
) | ||
); | ||
if(isset($_GET[$this->name.'_order'])){ | ||
$this->processReorder($_GET[$this->name.'_order']); | ||
$v->js(null,$this->owner->js()->reload(array($this->name=>false)))->univ()->closeDialog()->successMessage('New order saved')->execute(); | ||
} | ||
} | ||
function processReorder($id_order){ | ||
// add missing "ord" fields | ||
$q=$this->model->dsql(); | ||
$q->set('ord',$q->expr('id')); | ||
$q->where($q->expr('ord is null')); | ||
$q->do_update(); | ||
|
||
$q=$this->model->dsql()->field('id')->field('ord'); | ||
$seq=$q->do_getAllHash(); | ||
|
||
// extract ORDs | ||
$ord=array(); | ||
foreach($seq as $key=>$val){ | ||
$ord[]=$val['ord']; | ||
} | ||
|
||
sort($ord); | ||
|
||
foreach(explode(',',$id_order) as $id){ | ||
$q=$this->model->dsql(); | ||
$q->set('ord',array_shift($ord)); | ||
$q->where('id',$id); | ||
$q->do_update(); | ||
} | ||
} | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
This addon allows you to sort records. | ||
|
||
1. Create field "ord" in your database table | ||
2. $grid->add('gridorder/Controller_GridOrder'); | ||
|
||
if you need sorting in grud, then | ||
|
||
if($crud->grid)$crud->grid->add('gridorder/Controller_GridOrder'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div id="<?$_name?>"> | ||
<?rows?><?row?> | ||
<div data-id="<?$id?>"> <i style="float: left" class="ui-icon ui-icon-arrow-2-n-s"></i> <?$name?></div> | ||
<?/?><?/?> | ||
<div class="hr"></div> | ||
</div> |