コード例 #1
0
ファイル: WFSubmit.php プロジェクト: apinstein/phocoa
 /**
  * Constructor.
  */
 function __construct($id, $page)
 {
     if (strtolower($id) === 'submit') {
         throw new WFException("WFSubmit cannot have an ID of submit. It causes problems with javascript.");
     }
     parent::__construct($id, $page);
     $this->submitEvent = new WFClickEvent(WFAction::ServerAction());
     $this->setListener($this->submitEvent);
     $this->setAction($id);
     $this->label = "Submit";
     $this->imagePath = NULL;
     $this->duplicateSubmitMessage = NULL;
     $this->postSubmitLabel = NULL;
 }
コード例 #2
0
ファイル: WFRPC.php プロジェクト: ardell/phocoa
 /**
  * Create a new AjaxAction to reponsd to an event.
  * 
  * Call an action on the server, done via XHR.
  *
  * @return object WFAction
  */
 public static function AjaxAction()
 {
     $a = new WFAction();
     $a->addRPC(true);
     return $a;
 }
コード例 #3
0
ファイル: WFHTML5_Uploader.php プロジェクト: apinstein/phocoa
 function submitAction()
 {
     return WFAction::serverAction()->setTarget("#page#{$this->id}")->setAction('_handleSyncMultipleUploads');
 }
コード例 #4
0
ファイル: WFView.php プロジェクト: apinstein/phocoa
 /**
  * All WFView objects support our powerful onEvent syntax. This makes it very easy to attach javascript operations to any DOM events of your choosing.
  *
  * You can specify these programmatically or in the YAML file, like:
  *
  * onEvent: <eventName> do <processingOption>:<processingInfo>
  *
  * You can choose from three processing options, "j" (execute javascript code), "s" (execute a server action via a form submit), or "a" (execute a server action via ajax).
  *
  * For "j" events, it looks like:
  *
  * onEvent: click do j:alert("Somthing was clicked")
  *
  * Your code is actually processed inside of an object function callback; "this" will be the WFAction, and it has a parameter "event". By default, the event is NOT stopped
  * when using "j" events, so if you don't want the default behavior to occur, be sure to use this.stopEvent(event) in your j:javascript.
  *
  * NOTE: the 's' and 'a' processing options also accept a '!' modifier which turns on runsIfInvalid mode. This is useful in many cases where you need to
  * run server-side processing of form data before you even expect the form to be valid (for instance chained WFSelect widgets).
  */
 public function setOnEvent($str)
 {
     // clean up script & gracefully handle empty scripts
     $str = trim($str);
     if (empty($str)) {
         return;
     }
     $this->originalOnEvent = $str;
     $matches = array();
     // statement syntax: <event> do <j|s|a>:[action]
     // repeat by adding "onEvent:" and another statement
     $pieces = preg_split('/\\W\\bonEvent\\b:\\W*/', $str);
     foreach ($pieces as $statement) {
         if (preg_match('/^\\W*([A-z]*)\\W*do\\W*([jsa])(!)?:?((#(page|module)#[^:]*):)?(.*)$/', $statement, $matches)) {
             list(, $eventName, $actionType, $runsIfInvalid, , $target, , $actionArgument) = $matches;
             if (empty($runsIfInvalid)) {
                 $runsIfInvalid = false;
             } else {
                 $runsIfInvalid = true;
             }
             if (empty($actionArgument)) {
                 $actionArgument = NULL;
             }
             // normalize to null
             if (empty($target)) {
                 $target = NULL;
             }
             // normalize to null
             if ($actionType === 'j') {
                 $action = WFAction::JSAction();
                 if ($actionArgument !== NULL) {
                     $action->setJsEventHandler("function(event) { " . $actionArgument . " }.bind(action)");
                 }
             } else {
                 if ($actionType === 's') {
                     $action = WFAction::ServerAction();
                     if ($actionArgument !== NULL) {
                         if ($target !== NULL) {
                             $action->setTarget($target);
                         }
                         $action->setAction($actionArgument);
                     }
                     if ($runsIfInvalid) {
                         $action->rpc()->setRunsIfInvalid(true);
                     }
                 } else {
                     if ($actionType === 'a') {
                         $action = WFAction::AjaxAction();
                         if ($actionArgument !== NULL) {
                             if ($target !== NULL) {
                                 $action->setTarget($target);
                             }
                             $action->setAction($actionArgument);
                         }
                         if ($runsIfInvalid) {
                             $action->rpc()->setRunsIfInvalid(true);
                         }
                     }
                 }
             }
             $this->setListener(WFEvent::factory($eventName, $action));
         } else {
             throw new WFException("Couldn't parse onEvent statement: " . $statement);
         }
     }
 }