← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8331: mobile: new-message works now, can add ou, user, usergroup. still needs plenty of polish.

 

------------------------------------------------------------
revno: 8331
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-10-02 03:06:55 +0700
message:
  mobile: new-message works now, can add ou, user, usergroup. still needs plenty of polish.
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/messages.vm
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java	2012-10-01 16:49:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java	2012-10-01 20:06:55 +0000
@@ -173,15 +173,11 @@
 
         String metaData = MessageService.META_USER_AGENT + request.getHeader( ContextUtils.HEADER_USER_AGENT );
 
-        System.err.println( message );
-
-        /*
         int id = messageService.sendMessage( message.getSubject(), message.getText(), metaData, message.getUsers() );
         MessageConversation m = messageService.getMessageConversation( id );
 
         response.setStatus( HttpServletResponse.SC_CREATED );
         response.setHeader( "Location", MessageConversationController.RESOURCE_PATH + "/" + m.getUid() );
-        */
     }
 
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/messages.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/messages.vm	2012-10-01 04:01:22 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/messages.vm	2012-10-01 20:06:55 +0000
@@ -5,8 +5,6 @@
             url: '../api/currentUser/inbox.json',
             async: false
         }).success(function(data) {
-            console.log(data);
-
             jQuery.each(data.messageConversations, function(i, item) {
                 jQuery('#messageList').append('<li><a href="messages/' + item.id + '">' + item.name + '</a></li>');
             });

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm	2012-10-01 16:36:21 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm	2012-10-01 20:06:55 +0000
@@ -136,18 +136,56 @@
         displaySelected();
     }
 
+    function sendMessage() {
+        var subject = jQuery('#new-message-subject').val();
+        var text = jQuery('#new-message-text').val();
+
+        var message = {};
+        message.subject = subject;
+        message.text = text;
+        message.organisationUnits = [];
+        message.users = [];
+        message.userGroups = [];
+
+        $.mobile.showPageLoadingMsg();
+
+        _(_(selected).keys()).each(function(key) {
+            if( key.indexOf('ou:') != -1 )
+            {
+                message.organisationUnits.push( { "id": key.substring(3) } );
+            }
+            else if( key.indexOf('u:') != -1 )
+            {
+                message.users.push( { "id": key.substring(2) } );
+            }
+            else if( key.indexOf('ug:') != -1 )
+            {
+                message.userGroups.push( { "id": key.substring(3) } );
+            }
+        });
+
+        $.ajax({
+           url: "$baseUrl/../api/messageConversations",
+           type: 'POST',
+           contentType: 'application/json',
+           data: JSON.stringify(message),
+           async: false
+        }).success(function() {
+            $.mobile.hidePageLoadingMsg();
+            window.location.href = '../messages';
+        }).error(function() {
+            $.mobile.showPageLoadingMsg( $.mobile.pageLoadErrorMessageTheme, "Unable to send message, please try again later", true );
+            setTimeout( $.mobile.hidePageLoadingMsg, 1500 );
+            console.log("failed to send message");
+        });
+
+        return false;
+    }
+
     function newMessagePage()
     {
-        $('#new-message-form input:submit').bind('click', function () {
-            var subject = jQuery('#new-message-subject').val();
-            var text = jQuery('#new-message-text').val();
-
-            console.log(subject);
-            console.log(text);
-
-            return false;
-        });
-
+        $('#new-message-form input:submit').unbind('click');
+        $('#new-message-form input:submit').bind('click', sendMessage );
         updateRecipientCounter();
     }
 
@@ -170,7 +208,7 @@
 
 	<header data-role="header" data-theme="b">
 		<div align="center"><img src="$baseUrl/../dhis-web-commons/css/light_blue/logo_banner.png" /></div>
-        <a href="messages" data-icon="delete" class="ui-btn-right">Discard</a>
+        <a href="../messages" data-icon="delete" class="ui-btn-right">Discard</a>
     </header>
 
 	<section data-role='content'>
@@ -185,7 +223,7 @@
                 </form>
 
             </li>
-            <li data-icon="gear"><a href="#manage-recipients-page" data-icon="plus">Manage recipients</a> <span id="message-recipient-counter" class='ui-li-count'>0</span></li>
+            <li data-icon="gear"><a href="#manage-recipients-page">Manage recipients</a> <span id="message-recipient-counter" class='ui-li-count'>0</span></li>
         </ul>
 
 	</section>