1: <?php
  2: 
  3: /**
  4:  * Picon Framework
  5:  * http://code.google.com/p/picon-framework/
  6:  *
  7:  * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
  8: 
  9:  * Picon Framework is free software: you can redistribute it and/or modify
 10:  * it under the terms of the GNU General Public License as published by
 11:  * the Free Software Foundation, either version 3 of the License, or
 12:  * (at your option) any later version.
 13: 
 14:  * Picon Framework is distributed in the hope that it will be useful,
 15:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17:  *  General Public License for more details.
 18: 
 19:  * You should have received a copy of the GNU General Public License
 20:  * along with Picon Framework.  If not, see <http://www.gnu.org/licenses/>.
 21:  * */
 22: 
 23: namespace picon;
 24: 
 25: /**
 26:  * A form button, when submited the callback methods will be invoked based on the 
 27:  * valid state of the form
 28:  * 
 29:  * @todo This currently needs to be a child of a Form - it should provide the option
 30:  * of manually specifying the form to submit so the button may be placed elsewhere
 31:  * @author Martin Cassidy
 32:  * @package web/markup/html/form
 33:  */
 34: class Button extends FormComponent implements FormSubmitListener, FormSubmitter
 35: {
 36:     private $onSubmit;
 37:     private $onError;
 38:     
 39:     /**
 40:      *
 41:      * @param string $id
 42:      * @param callback $onSubmit Called when the form is valid
 43:      * @param callback $onError Called when the form is not valid
 44:      */
 45:     public function __construct($id, $onSubmit = null, $onError = null)
 46:     {
 47:         parent::__construct($id);
 48:         
 49:         if($onSubmit!=null)
 50:         {
 51:             Args::callBack($onSubmit, 'onSubmit');
 52:         }
 53:         if($onError!=null)
 54:         {
 55:             Args::callBack($onError, 'onError');
 56:         }
 57:         
 58:         $this->onSubmit = $onSubmit;
 59:         $this->onError = $onError;
 60:     }
 61:     
 62:     public function isStateless()
 63:     {
 64:         return false;
 65:     }
 66:     
 67:     public function onSubmit()
 68:     {
 69:         $callable = $this->onSubmit;
 70:         if($callable!=null)
 71:         {
 72:             $callable();
 73:         }
 74:     }
 75:     
 76:     public function onError()
 77:     {
 78:         $callable = $this->onError;
 79:         if($callable!=null)
 80:         {
 81:             $callable();
 82:         }
 83:     }
 84:     
 85:     public function onEvent()
 86:     {
 87:         $form = $this->getForm();
 88:         $form->process($this);
 89:     }
 90:     
 91:     protected function convertInput()
 92:     {
 93:         //Do nothing
 94:     }
 95:     
 96:     public function updateModel()
 97:     {
 98:         //Do nothing
 99:     }
100:     
101:     protected function validateModel()
102:     {
103:         //Do nothing
104:     }
105: }
106: 
107: ?>
108: