]> source.dussan.org Git - nextcloud-server.git/commitdiff
Remove dependency from arbitrary data object structure for easier usage
authorJoas Schilling <nickvergessen@gmx.de>
Fri, 13 Feb 2015 15:10:13 +0000 (16:10 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Fri, 20 Feb 2015 09:43:39 +0000 (10:43 +0100)
core/js/js.js

index 7ff010eca0a285dbc696ef7d690c985daebcab09..7789dc77365c95069be2383f8fc600b223b5bcf7 100644 (file)
@@ -605,60 +605,95 @@ OC.addStyle.loaded=[];
 OC.addScript.loaded=[];
 
 /**
- * @todo Write documentation
+ * A little class to manage a status field for a "saving" process.
+ * It can be used to display a starting message (e.g. "Saving...") and then
+ * replace it with a green success message or a red error message.
+ *
+ * @namespace OC.msg
  */
-OC.msg={
+OC.msg = {
        /**
-        * @param selector
-        * @todo Write documentation
+        * Displayes a "Saving..." message in the given message placeholder
+        *
+        * @param {Object} selector     Placeholder to display the message in
         */
-       startSaving:function(selector){
-               OC.msg.startAction(selector, t('core', 'Saving...'));
+       startSaving: function(selector) {
+               this.startAction(selector, t('core', 'Saving...'));
        },
 
        /**
-        * @param selector
-        * @param data
-        * @todo Write documentation
+        * Displayes a custom message in the given message placeholder
+        *
+        * @param {Object} selector     Placeholder to display the message in
+        * @param {string} message      Plain text message to display (no HTML allowed)
         */
-       finishedSaving:function(selector, data){
-               OC.msg.finishedAction(selector, data);
+       startAction: function(selector, message) {
+               $(selector).text(message)
+                       .removeClass('success')
+                       .removeClass('error')
+                       .stop(true, true)
+                       .show();
        },
 
        /**
-        * @param selector
-        * @param {string} message Message to display
-        * @todo WRite documentation
+        * Displayes an success/error message in the given selector
+        *
+        * @param {Object} selector     Placeholder to display the message in
+        * @param {Object} response     Response of the server
+        * @param {Object} response.data        Data of the servers response
+        * @param {string} response.data.message        Plain text message to display (no HTML allowed)
+        * @param {string} response.status      is being used to decide whether the message
+        * is displayed as an error/success
         */
-       startAction:function(selector, message){
-               $(selector)
-                       .html( message )
-                       .removeClass('success')
+       finishedSaving: function(selector, response) {
+               this.finishedAction(selector, response);
+       },
+
+       /**
+        * Displayes an success/error message in the given selector
+        *
+        * @param {Object} selector     Placeholder to display the message in
+        * @param {Object} response     Response of the server
+        * @param {Object} response.data Data of the servers response
+        * @param {string} response.data.message Plain text message to display (no HTML allowed)
+        * @param {string} response.status is being used to decide whether the message
+        * is displayed as an error/success
+        */
+       finishedAction: function(selector, response) {
+               if (response.status === "success") {
+                       this.finishedSuccess(selector, response.data.message);
+               } else {
+                       this.finishedError(selector, response.data.message);
+               }
+       },
+
+       /**
+        * Displayes an success message in the given selector
+        *
+        * @param {Object} selector Placeholder to display the message in
+        * @param {string} message Plain text success message to display (no HTML allowed)
+        */
+       finishedSuccess: function(selector, message) {
+               $(selector).text(message)
+                       .addClass('success')
                        .removeClass('error')
                        .stop(true, true)
+                       .delay(3000)
+                       .fadeOut(900)
                        .show();
        },
 
        /**
-        * @param selector
-        * @param data
-        * @todo Write documentation
+        * Displayes an error message in the given selector
+        *
+        * @param {Object} selector Placeholder to display the message in
+        * @param {string} message Plain text error message to display (no HTML allowed)
         */
-       finishedAction:function(selector, data){
-               if( data.status === "success" ){
-                       $(selector).html( data.data.message )
-                                       .addClass('success')
-                                       .removeClass('error')
-                                       .stop(true, true)
-                                       .delay(3000)
-                                       .fadeOut(900)
-                                       .show();
-               }else{
-                       $(selector).html( data.data.message )
-                                       .addClass('error')
-                                       .removeClass('success')
-                                       .show();
-               }
+       finishedError: function(selector, message) {
+               $(selector).text(message)
+                       .addClass('error')
+                       .removeClass('success')
+                       .show();
        }
 };