add js resource for concurrency api, check method for resource checkin & checkout
authorRob Moen <rmoen@users.mediawiki.org>
Wed, 11 Jan 2012 00:17:17 +0000 (00:17 +0000)
committerRob Moen <rmoen@users.mediawiki.org>
Wed, 11 Jan 2012 00:17:17 +0000 (00:17 +0000)
resources/Resources.php
resources/jquery/jquery.concurrency.js [new file with mode: 0644]

index 667d5ca..2f73f24 100644 (file)
@@ -112,6 +112,9 @@ return array(
        'jquery.colorUtil' => array(
                'scripts' => 'resources/jquery/jquery.colorUtil.js',
        ),
+       'jquery.concurrency' => array(
+               'scripts' => 'resources/jquery/jquery.concurrency.js',
+       ),
        'jquery.cookie' => array(
                'scripts' => 'resources/jquery/jquery.cookie.js',
        ),
diff --git a/resources/jquery/jquery.concurrency.js b/resources/jquery/jquery.concurrency.js
new file mode 100644 (file)
index 0000000..fec95e5
--- /dev/null
@@ -0,0 +1,42 @@
+/**
+ * Base jQuery plugin for Concurrency 
+ *
+ * @author Rob Moen
+ */
+
+(function ( $ ) {
+       $.concurrency = {
+               /* 
+                * Checkin our checkout an object via API
+                * @param ccaction: checkout, checkin
+                * @param resourcetype: extension specific type (string)
+                * @param record: resource id (int) 
+                * @param callback: function to handle response 
+                */
+               check: function( params, callback ) {
+                       params = $.extend({
+                               action: 'concurrency',
+                               token: mw.user.tokens.get( 'editToken' ),
+                               format: 'json'
+                       }, params);
+                               
+                       return $.ajax( {
+                               type: 'POST',
+                               url: mw.util.wikiScript( 'api' ),
+                               data: params,
+                               success: function( data ){
+                                       if ( typeof callback == 'function' ){
+                                               callback(data); 
+                                       }
+                               },
+                               error: function( data ){
+                                       if ( typeof callback == 'function' ){
+                                               callback(data); 
+                                       }
+                               },
+                               dataType: 'json'
+                       } );
+               }
+       };      
+
+})( jQuery );
\ No newline at end of file