PageRenderTime 103ms CodeModel.GetById 61ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/atk4-addons/mvc/SelectGrid.php

https://github.com/mahimarathore/mahi
PHP | 72 lines | 58 code | 2 blank | 12 comment | 2 complexity | 5e20504146634cc3c2b08cf5bd863afb MD5 | raw file
 1<?php
 2/**
 3 * SelectGrid
 4 * AJAX based class
 5 * Created on 09.10.2006 by *Camper* (camper@adevel.com)
 6 */
 7class SelectGrid extends Grid{
 8	protected $selected=array();
 9
10	function init(){
11		parent::init();
12		//restoring selected
13		//$this->addHook('post-submit', array($this, 'getSelected'), 1);
14		$this->getSelected();
15		if($_GET['save_selected']){
16			$r=explode(',',$_GET['selected']);
17			$sel=array();
18			foreach($r as $i=>$v){
19				list($id,$selected)=explode(':',$v);
20				$sel[$id]=$selected;
21			}
22			$this->processSelection($sel);
23		}
24	}
25	function getSelected($id=null){
26		if(!$this->selected)$this->selected = $this->recall('selected', array());
27		return (is_null($id)?$this->selected:$this->selected[$id]);
28	}
29	/**
30	 * changes selected status of the row
31	 */
32	function select($id){
33		$this->selected[$id]=($this->selected[$id]=='Y'?'N':'Y');
34		$this->memorize('selected', $this->selected);
35	}
36	function setSelected($selected){
37		$this->selected=array_merge($this->selected,$selected);
38		$this->memorize('selected', $this->selected);
39	}
40	function format_checkbox($field){
41		$this->current_row[$field] = '<input type="checkbox" id="cb_'.
42			$this->current_row['id'].'" name="cb_'.$this->current_row['id'].
43			'" value="'.$this->current_row['id'].'"'.
44			($this->selected[$this->current_row['id']]=='Y'?" checked ":" ").'" onclick="'.
45			$this->onClick($field).'" />';
46		$this->setTDParam($field,'width','10');
47		$this->setTDParam($field,'align','center');
48	}
49	function onClick($field){
50//    	return $this->add('Ajax')->loadRegionURL('cb_'.$this->current_row['id'],
51		
52		//return "alert('".$this->api->url(null,array('cb'=>$this->current_row['id']))."')";
53		return str_replace('"',"'",$this->ajax()->executeUrl(
54				$this->api->url(null,array('cb'=>$this->current_row['id']))
55			)->getString());
56	}
57	function format_assigned($field){
58		$this->current_row[$field] = ($this->assignmentExists($this->current_row['id']))?"Yes":"No";
59		if($this->current_row[$field] == 'Yes')$this->current_row[$field] = "<b>".$this->current_row[$field]."</b>";
60	}
61	function assignmentExists($id){
62		return false;
63	}
64	/**
65	 * Override this method to perform any updates to DB, etc
66	 *
67	 * @param $selected array of IDs selected
68	 */
69	function processSelection($selected){
70		$this->memorize('selected',$selected);
71	}
72}