@@ -35,13 +35,22 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
35
35
} ;
36
36
37
37
/**
38
- * Record that the user is a contact.
38
+ * Check the state of the element, if the current user has sent a contact request or not .
39
39
*
40
- * @method setContact
40
+ * @method isRequested
41
+ * @param {object } element jQuery object for the button
42
+ * @return {bool }
43
+ */
44
+ let isRequested = ( element ) => element . attr ( 'data-is-requested' ) == '1' ;
45
+
46
+ /**
47
+ * Record that the user has sent a contact request.
48
+ *
49
+ * @method setContactRequested
41
50
* @param {object } element jQuery object for the button
42
51
*/
43
- var setContact = function ( element ) {
44
- element . attr ( 'data-is-contact ' , '1' ) ;
52
+ var setContactRequested = function ( element ) {
53
+ element . attr ( 'data-is-requested ' , '1' ) ;
45
54
} ;
46
55
47
56
/**
@@ -144,11 +153,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
144
153
}
145
154
} ;
146
155
sendRequest ( element , request ) . done ( function ( ) {
147
- setContact ( element ) ;
156
+ setContactRequested ( element ) ;
157
+ element . addClass ( 'disabled' ) ;
148
158
const templateContext = {
149
159
'displaytextlabel' : displayTextLabel ( element )
150
160
} ;
151
- Templates . render ( 'message/remove_contact_button ' , templateContext ) . done ( function ( html , js ) {
161
+ Templates . render ( 'message/contact_request_sent ' , templateContext ) . done ( function ( html , js ) {
152
162
Templates . replaceNodeContents ( element , html , js ) ;
153
163
} ) ;
154
164
} ) ;
@@ -196,7 +206,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
196
206
var enhance = function ( element ) {
197
207
element = $ ( element ) ;
198
208
199
- if ( ! element . children ( '.loading-icon' ) . length ) {
209
+ if ( ! element . children ( '.loading-icon' ) . length && ! isRequested ( element ) ) {
200
210
// Add the loading gif if it isn't already there.
201
211
Templates . render ( 'core/loading' , { } ) . done ( function ( html , js ) {
202
212
element . append ( html , js ) ;
@@ -208,7 +218,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
208
218
element . on ( CustomEvents . events . activate , function ( e , data ) {
209
219
if ( isContact ( element ) ) {
210
220
removeContact ( element ) ;
211
- } else {
221
+ } else if ( ! isRequested ( element ) ) {
212
222
addContact ( element ) ;
213
223
}
214
224
e . preventDefault ( ) ;
0 commit comments