[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/webroot/rsrc/js/core/ -> behavior-workflow.js (source)

   1  /**
   2   * @provides javelin-behavior-workflow
   3   * @requires javelin-behavior
   4   *           javelin-stratcom
   5   *           javelin-workflow
   6   *           javelin-dom
   7   *           javelin-router
   8   */
   9  
  10  JX.behavior('workflow', function() {
  11  
  12    // Queue a workflow at elevated priority. The user just clicked or submitted
  13    // something, so service this before loading background content.
  14    var queue = function(workflow) {
  15      var routable = workflow.getRoutable()
  16        .setPriority(2000)
  17        .setType('workflow');
  18  
  19      JX.Router.getInstance().queue(routable);
  20    };
  21  
  22    // If a user clicks an alternate submit button, make sure it gets marshalled
  23    // into the workflow.
  24    JX.Stratcom.listen(
  25      'click',
  26      ['workflow', 'tag:form', 'alternate-submit-button'],
  27      function(e) {
  28        e.prevent();
  29  
  30        var target = e.getNode('alternate-submit-button');
  31        var form = e.getNode('tag:form');
  32        var button = {};
  33        button[target.name] = target.value || true;
  34  
  35        JX.DOM.invoke(form, 'didSyntheticSubmit', {extra: button});
  36      });
  37  
  38    // Listen for both real and synthetic submit events.
  39    JX.Stratcom.listen(
  40      ['submit', 'didSyntheticSubmit'],
  41      ['workflow', 'tag:form'],
  42      function(e) {
  43        if (JX.Stratcom.pass()) {
  44          return;
  45        }
  46  
  47        var data = e.getData();
  48        var extra = (data && data.extra) || {};
  49  
  50        // NOTE: We activate workflow if any parent node has the "workflow" sigil,
  51        // not just the <form /> itself.
  52  
  53        e.prevent();
  54  
  55        queue(JX.Workflow.newFromForm(e.getNode('tag:form'), extra));
  56      });
  57  
  58    JX.Stratcom.listen(
  59      'click',
  60      ['workflow', 'tag:a'],
  61      function(e) {
  62        if (!e.isNormalClick()) {
  63          return;
  64        }
  65  
  66        // NOTE: As above, we want to activate workflow if a parent node has
  67        // the sigil, not just the <a /> that the user clicked. However, there
  68        // is an exception in this case: if the <a /> does not have workflow and
  69        // is inside a <form /> which does, we don't workflow it (this covers
  70        // things like "help" links in captions). Test if the node with the
  71        // workflow sigil is a form.
  72  
  73        var workflow_node = e.getNode('workflow');
  74        if (JX.DOM.isType(workflow_node, 'form')) {
  75          // This covers the case of an <a /> without workflow inside a <form />
  76          // with workflow.
  77          return;
  78        }
  79  
  80        if (JX.Stratcom.pass()) {
  81          return;
  82        }
  83  
  84        e.prevent();
  85        queue(JX.Workflow.newFromLink(e.getNode('tag:a')));
  86      });
  87  
  88  });


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1