From a668603cf49d635cccee0567f864205c5778d7d6 Mon Sep 17 00:00:00 2001
From: diosmosis <benaka@piwik.pro>
Date: Tue, 7 Oct 2014 13:36:04 -0700
Subject: [PATCH] Add isSubmitting property to piwik-ajax-form directive and
 make sure child elements can access scope.

---
 .../angularjs/ajax-form/ajax-form.controller.js        | 10 ++++++++++
 .../angularjs/ajax-form/ajax-form.directive.js         | 10 ++++++++--
 tests/PHPUnit/UI                                       |  2 +-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/plugins/CoreHome/angularjs/ajax-form/ajax-form.controller.js b/plugins/CoreHome/angularjs/ajax-form/ajax-form.controller.js
index 13d88f3991..13f6f6e58f 100644
--- a/plugins/CoreHome/angularjs/ajax-form/ajax-form.controller.js
+++ b/plugins/CoreHome/angularjs/ajax-form/ajax-form.controller.js
@@ -28,6 +28,13 @@
          */
         vm.errorPostResponse = null;
 
+        /**
+         * true if currently submitting a POST request, false if otherwise.
+         *
+         * @type {bool}
+         */
+        vm.isSubmitting = false;
+
         vm.submitForm = submitForm;
 
         /**
@@ -45,6 +52,7 @@
                 postParams = vm.data;
             }
 
+            vm.isSubmitting = true;
             piwikApi.post(
                 { // GET params
                     module: 'API',
@@ -69,6 +77,8 @@
                 }
             }).catch(function (errorMessage) {
                 vm.errorPostResponse = errorMessage;
+            })['finally'](function () {
+                //vm.isSubmitting = false;
             });
         }
     }
diff --git a/plugins/CoreHome/angularjs/ajax-form/ajax-form.directive.js b/plugins/CoreHome/angularjs/ajax-form/ajax-form.directive.js
index 4f2242135f..064cc1d7ac 100644
--- a/plugins/CoreHome/angularjs/ajax-form/ajax-form.directive.js
+++ b/plugins/CoreHome/angularjs/ajax-form/ajax-form.directive.js
@@ -46,7 +46,7 @@
  *          <h2>My Form</h2>
  *          <input name="myOption" value="myDefaultValue" type="text" />
  *          <input name="myOtherOption" type="checkbox" checked="checked" />
- *          <input type="submit" value="Submit" />
+ *          <input type="submit" value="Submit" ng-disabled="ajaxForm.isSubmitting" />
  *
  *          <div piwik-notification context='error' ng-show="errorPostResponse">ERROR!</div>
  *     </div>
@@ -68,6 +68,7 @@
             require: '?ngModel',
             controller: 'AjaxFormController',
             controllerAs: 'ajaxForm',
+            transclude: true,
             compile: function (element, attrs) {
                 if (!attrs.submitApiMethod) {
                     throw new Error("submitApiMethod is required");
@@ -75,7 +76,7 @@
 
                 attrs.noErrorNotification = !! attrs.noErrorNotification;
 
-                return function (scope, element, attrs, ngModel) {
+                return function (scope, element, attrs, ngModel, transclude) {
                     scope.ajaxForm.submitApiMethod = scope.submitApiMethod;
                     scope.ajaxForm.sendJsonPayload = scope.sendJsonPayload;
                     scope.ajaxForm.noErrorNotification = scope.noErrorNotification;
@@ -100,6 +101,11 @@
                         scope.ajaxForm.submitForm();
                     });
 
+                    // make sure child elements can access this directive's scope
+                    transclude(scope, function(clone, scope) {
+                        element.append(clone);
+                    });
+
                     function setFormValueFromInput(inputElement) {
                         var $ = angular.element,
                             name = $(inputElement).attr('name'),
diff --git a/tests/PHPUnit/UI b/tests/PHPUnit/UI
index 235d158cb9..d98325f48a 160000
--- a/tests/PHPUnit/UI
+++ b/tests/PHPUnit/UI
@@ -1 +1 @@
-Subproject commit 235d158cb98415144ef5bf6312703c83ff1c9b08
+Subproject commit d98325f48a495a6d5d71cb1ffed231f6834f30bb
-- 
GitLab