← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10038: Sharing: moved javascript out of vm macro into external file. Enabled i18n of form.

 

------------------------------------------------------------
revno: 10038
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-03-07 12:39:25 +0100
message:
  Sharing: moved javascript out of vm macro into external file. Enabled i18n of form.
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.sharing.js
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties


--
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
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.sharing.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.sharing.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.sharing.js	2013-03-07 11:39:25 +0000
@@ -0,0 +1,184 @@
+
+function loadSharingSettings( type, uid ) {
+    return $.ajax( {
+        url: '../api/sharing',
+        data: {
+            type: type,
+            id: uid
+        },
+        dataType: 'json'
+    } );
+}
+
+function saveSharingSettings( type, uid, data ) {
+    return $.ajax( {
+        url: '../api/sharing?type=' + type + '&id=' + uid,
+        type: 'POST',
+        dataType: 'json',
+        contentType: 'application/json; charset=UTF-8',
+        data: JSON.stringify( data )
+    } );
+}
+
+var sharingSelectedItem;
+
+function renderUserGroupAccessTemplate(item) {
+    var tmpl = jQuery('#user-group-access-template').html();
+    var tmpl_html = _.template(tmpl, item);
+
+    return tmpl_html;
+}
+
+function addUserGroupAccessSelectedItem(e) {
+    var tmpl_html = renderUserGroupAccessTemplate({
+        label: sharingSelectedItem.label,
+        id: sharingSelectedItem.id,
+        access: "r-------"
+    });
+
+    $(tmpl_html).insertAfter( $('#sharingAccessTable tbody tr').not('[id]') );
+
+    $('#sharingFindUserGroup').val('')
+    sharingSelectedItem = undefined;
+
+    $( '#addUserGroupAccess' ).attr( 'disabled', true );
+}
+
+function removeUserGroupAccess(e) {
+    $( this ).parent().parent().remove();
+    e.preventDefault();
+}
+
+function clearUserGroupAccesses() {
+    $('#sharingAccessTable tbody tr[id]' ).remove();
+}
+
+function setUserGroupAccesses(userGroupAccesses) {
+    clearUserGroupAccesses();
+
+    if(userGroupAccesses) {
+        $.each(userGroupAccesses, function(idx, item) {
+            var tmpl_html = renderUserGroupAccessTemplate({
+                label: item.name,
+                id: item.id,
+                access: item.access
+            });
+
+            $(tmpl_html).insertAfter( $('#sharingAccessTable tbody tr').not('[id]') );
+        });
+    }
+}
+
+function setPublicAccess(access) {
+    $( '#sharingPublicAccess option' ).removeAttr( 'selected' ).each( function ( idx, item ) {
+        if ( $( item ).val() == access ) {
+            $( item ).attr( 'selected', true );
+        }
+    } );
+}
+
+function getPublicAccess() {
+    return $( '#sharingPublicAccess' ).val();
+}
+
+function getUserGroupAccesses() {
+    var v = [];
+
+    $( '#sharingAccessTable tbody tr[id]' ).each( function ( idx, item ) {
+        var jqItem = $(item);
+
+        var groupName = $( item ).find('.sharingGroupName').text();
+        var groupAccess = $( item ).find('.sharingGroupAccess').val();
+
+        v.push({
+            id: jqItem.attr('id'),
+            name: groupName,
+            access: groupAccess
+        });
+    } );
+
+    return v;
+}
+
+function showSharingDialog( type, uid ) {
+    loadSharingSettings( type, uid ).done( function ( data ) {
+        setPublicAccess( data.object.publicAccess );
+        setUserGroupAccesses( data.object.userGroupAccesses );
+
+        $( '#sharingName' ).text( data.object.name );
+
+        if ( !data.meta.allowPublicAccess ) {
+            $( '#sharingPublicAccess' ).attr( 'disabled', true );
+        }
+
+        $( '.removeUserGroupAccess' ).unbind( 'click' )
+        $( document ).on( 'click', '.removeUserGroupAccess', removeUserGroupAccess );
+        $( '#addUserGroupAccess' ).unbind( 'click' ).bind( 'click', addUserGroupAccessSelectedItem );
+
+        $( '#sharingFindUserGroup' ).autocomplete( {
+            source: function ( request, response ) {
+                $.ajax({
+                    url: '../api/sharing/search',
+                    dataType: 'json',
+                    data: {
+                        key: request.term
+                    }
+                } ).success(function(data) {
+                    var v = [];
+                    var u = getUserGroupAccesses();
+
+                    if(data.userGroups) {
+                        $.each(data.userGroups, function(idx, item) {
+                            var d = {};
+
+                            d.label = item.name;
+                            d.value = item.name;
+                            d.id = item.id;
+
+                            var found = false;
+
+                            $.each(u, function(idx, item) {
+                                if(item.id == d.id) {
+                                    found = true;
+                                }
+                            });
+
+                            if(!found) {
+                                v.push(d);
+                            }
+                        });
+                    }
+
+                    response(v);
+                });
+            },
+            minLength: 2,
+            select: function( event, ui ) {
+                sharingSelectedItem = ui.item;
+                $( '#addUserGroupAccess' ).removeAttr( 'disabled' );
+            }
+        });
+
+        $( '#sharingSettings' ).dialog( {
+            modal: true,
+            resizable: false,
+            width: 485,
+            height: 480,
+            buttons: {
+                'Cancel': function () {
+                    $( this ).dialog( 'close' );
+                },
+                'Save': function () {
+                    var me = $( this );
+
+                    data.object.publicAccess = getPublicAccess();
+                    data.object.userGroupAccesses = getUserGroupAccesses();
+
+                    saveSharingSettings( type, uid, data ).done( function () {
+                        me.dialog( 'close' );
+                    } );
+                }
+            }
+        } );
+    } );
+}

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm	2013-02-19 12:04:37 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm	2013-03-07 11:39:25 +0000
@@ -314,197 +314,11 @@
 
 #macro( sharingDialog )
 
-<script>
-function loadSharingSettings( type, uid ) {
-    return $.ajax( {
-        url: '../api/sharing',
-        data: {
-            type: type,
-            id: uid
-        },
-        dataType: 'json'
-    } );
-}
-
-function saveSharingSettings( type, uid, data ) {
-    return $.ajax( {
-        url: '../api/sharing?type=' + type + '&id=' + uid,
-        type: 'POST',
-        dataType: 'json',
-        contentType: 'application/json; charset=UTF-8',
-        data: JSON.stringify( data )
-    } );
-}
-
-var sharingSelectedItem;
-
-function renderUserGroupAccessTemplate(item) {
-    var tmpl = jQuery('#user-group-access-template').html();
-    var tmpl_html = _.template(tmpl, item);
-
-    return tmpl_html;
-}
-
-function addUserGroupAccessSelectedItem(e) {
-    var tmpl_html = renderUserGroupAccessTemplate({
-        label: sharingSelectedItem.label,
-        id: sharingSelectedItem.id,
-        access: "r-------"
-    });
-
-    $(tmpl_html).insertAfter( $('#sharingAccessTable tbody tr').not('[id]') );
-
-    $('#sharingFindUserGroup').val('')
-    sharingSelectedItem = undefined;
-
-    $( '#addUserGroupAccess' ).attr( 'disabled', true );
-}
-
-function removeUserGroupAccess(e) {
-    $( this ).parent().parent().remove();
-    e.preventDefault();
-}
-
-function clearUserGroupAccesses() {
-    $('#sharingAccessTable tbody tr[id]' ).remove();
-}
-
-function setUserGroupAccesses(userGroupAccesses) {
-    clearUserGroupAccesses();
-
-    if(userGroupAccesses) {
-        $.each(userGroupAccesses, function(idx, item) {
-            var tmpl_html = renderUserGroupAccessTemplate({
-                label: item.name,
-                id: item.id,
-                access: item.access
-            });
-
-            $(tmpl_html).insertAfter( $('#sharingAccessTable tbody tr').not('[id]') );
-        });
-    }
-}
-
-function setPublicAccess(access) {
-    $( '#sharingPublicAccess option' ).removeAttr( 'selected' ).each( function ( idx, item ) {
-        if ( $( item ).val() == access ) {
-            $( item ).attr( 'selected', true );
-        }
-    } );
-}
-
-function getPublicAccess() {
-    return $( '#sharingPublicAccess' ).val();
-}
-
-function getUserGroupAccesses() {
-    var v = [];
-
-    $( '#sharingAccessTable tbody tr[id]' ).each( function ( idx, item ) {
-        var jqItem = $(item);
-
-        var groupName = $( item ).find('.sharingGroupName').text();
-        var groupAccess = $( item ).find('.sharingGroupAccess').val();
-
-        v.push({
-            id: jqItem.attr('id'),
-            name: groupName,
-            access: groupAccess
-        });
-    } );
-
-    return v;
-}
-
-function showSharingDialog( type, uid ) {
-    loadSharingSettings( type, uid ).done( function ( data ) {
-        setPublicAccess( data.object.publicAccess );
-        setUserGroupAccesses( data.object.userGroupAccesses );
-
-        $( '#sharingName' ).text( data.object.name );
-
-        if ( !data.meta.allowPublicAccess ) {
-            $( '#sharingPublicAccess' ).attr( 'disabled', true );
-        }
-
-        $( '.removeUserGroupAccess' ).unbind( 'click' )
-        $( document ).on( 'click', '.removeUserGroupAccess', removeUserGroupAccess );
-        $( '#addUserGroupAccess' ).unbind( 'click' ).bind( 'click', addUserGroupAccessSelectedItem );
-
-        $( '#sharingFindUserGroup' ).autocomplete( {
-            source: function ( request, response ) {
-                $.ajax({
-                    url: '../api/sharing/search',
-                    dataType: 'json',
-                    data: {
-                        key: request.term
-                    }
-                } ).success(function(data) {
-                    var v = [];
-                    var u = getUserGroupAccesses();
-
-                    if(data.userGroups) {
-                        $.each(data.userGroups, function(idx, item) {
-                            var d = {};
-
-                            d.label = item.name;
-                            d.value = item.name;
-                            d.id = item.id;
-
-                            var found = false;
-
-                            $.each(u, function(idx, item) {
-                                if(item.id == d.id) {
-                                    found = true;
-                                }
-                            });
-
-                            if(!found) {
-                                v.push(d);
-                            }
-                        });
-                    }
-
-                    response(v);
-                });
-            },
-            minLength: 2,
-            select: function( event, ui ) {
-                sharingSelectedItem = ui.item;
-                $( '#addUserGroupAccess' ).removeAttr( 'disabled' );
-            }
-        });
-
-        $( '#sharingSettings' ).dialog( {
-            modal: true,
-            resizable: false,
-            width: 485,
-            height: 480,
-            buttons: {
-                'Cancel': function () {
-                    $( this ).dialog( 'close' );
-                },
-                'Save': function () {
-                    var me = $( this );
-
-                    data.object.publicAccess = getPublicAccess();
-                    data.object.userGroupAccesses = getUserGroupAccesses();
-
-                    saveSharingSettings( type, uid, data ).done( function () {
-                        me.dialog( 'close' );
-                    } );
-                }
-            }
-        } );
-    } );
-}
-</script>
-
-<div id="sharingSettings" title='$i18n.getString( "sharing_settings" )' style="display: none;">
+<div id="sharingSettings" title='$i18n.getString( "sharing_settings" )' style="display: none;" class="page">
     <table style="width: 100%;">
         <tbody>
             <tr>
-                <td colspan="2"><h3 style="border-bottom: 1px solid black;" id="sharingName"></h3></td>
+                <td colspan="2"><h5 style="border-bottom: 1px solid #606060;" id="sharingName"></h5></td>
             </tr>
 
             <tr>
@@ -517,12 +331,12 @@
     <table id="sharingAccessTable" style="width: 100%;">
         <tbody>
             <tr>
-                <td style="width: 300px;">Public Access</td>
+                <td style="width: 300px;">$i18n.getString( "public_access" )</td>
                 <td>
                     <select id="sharingPublicAccess" style="width: 150px;">
-                        <option selected="selected" value="--------">None</option>
-                        <option value="r-------">Read Only</option>
-                        <option value="rw------">Read and Write</option>
+                        <option selected="selected" value="--------">$i18n.getString( "none" )</option>
+                        <option value="r-------">$i18n.getString( "read_only" )</option>
+                        <option value="rw------">$i18n.getString( "read_write" )</option>
                     </select>
                 </td>
                 <td style="width: 25px; text-align: center;"></td>
@@ -536,8 +350,8 @@
     <td class="sharingGroupName" style="width: 300px;"><%= label %></td>
     <td>
         <select class="sharingGroupAccess" style="width: 150px;">
-            <option value="r-------" <% if(access == 'r-------') { %>selected<% } %>>Read Only</option>
-            <option value="rw------" <% if(access == 'rw------') { %>selected<% } %>>Read and Write</option>
+            <option value="r-------" <% if(access == 'r-------') { %>selected<% } %>>$i18n.getString( "read_only" )</option>
+            <option value="rw------" <% if(access == 'rw------') { %>selected<% } %>>$i18n.getString( "read_write" )</option>
         </select>
     </td>
     <td style="width: 25px; text-align: center;"><a href="" class="removeUserGroupAccess">X</a></td>

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2013-02-22 03:59:31 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2013-03-07 11:39:25 +0000
@@ -46,6 +46,7 @@
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.comparator.js"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.availability.js"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.trigger.js"></script>
+    <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.sharing.js"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.js"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js"></script>

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2013-02-26 02:41:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2013-03-07 11:39:25 +0000
@@ -617,6 +617,8 @@
 no_access=None
 read_access=Read
 read_write_access=Read / Write
+read_only=Read only
+read_write=Read and write
 
 #-- Countries / flags ---------------------------------------------------------#