[gnome-documents/sharing] sharing: code cleanup



commit cc7687e02dce3046af5c28db1e9fefb3d1bb0012
Author: Meg Ford <megford gnome org>
Date:   Tue Jan 8 22:57:02 2013 -0600

    sharing: code cleanup

 src/sharing.js |  213 +++++++++++++++++++++++++++-----------------------------
 1 files changed, 104 insertions(+), 109 deletions(-)
---
diff --git a/src/sharing.js b/src/sharing.js
index c790955..2b3fcd3 100644
--- a/src/sharing.js
+++ b/src/sharing.js
@@ -138,8 +138,7 @@ const SharingDialog = new Lang.Class({
                                                         ypad: 4 });
         this._viewCol.pack_start(this._rendererText, true);
         this._viewCol.add_attribute(this._rendererText,
-                                    'text', SharingDialogColumns.NAME);
-       
+                                    'text', SharingDialogColumns.NAME);       
         
         // Role column
         this._rendererDetail = new Gd.StyledTextRenderer({ xpad: 16 });
@@ -259,8 +258,6 @@ const SharingDialog = new Lang.Class({
         this._close.hide();
     },
 
-
-
     _permissionPopUp: function() { 
         this.dw.hide();
         this.button1.show();
@@ -315,7 +312,7 @@ const SharingDialog = new Lang.Class({
             }));
     },
 
-     // Get each entry (person) from the feed, and get the scope for each person, and then store the emails and values in an array
+    // Get each entry (person) from the feed, and get the scope for each person, and then store the emails and values in an array
     _getScopeRulesEntry: function(feed) {
         let entries = this.feed.get_entries();
         let testValues = [];
@@ -342,7 +339,7 @@ const SharingDialog = new Lang.Class({
                 }
              }));
 
-         // Set values in the treemodel
+        // Set values in the treemodel
         values.forEach(Lang.bind (this,
             function(value) {
                  let iter = this.model.append();
@@ -417,87 +414,86 @@ const SharingDialog = new Lang.Class({
     },
 
     _sendNewDocumentRule: function() {
- 	        
-            let source = Application.sourceManager.getItemById(this.resourceUrn);
-
-            let authorizer = new GData.GoaAuthorizer({ goa_object: source.object });
-            let service = new GData.DocumentsService({ authorizer: authorizer });
-
-            let docAccessRule = this._getDocumentPermission();
-            let newDocRole = this._getDocumentRole();
-            let entries = this.feed.get_entries();
-            let values = [];
-            let count = 0;
-            let arrIndex = 0;
-            let flag = "";
-
-                entries.forEach(Lang.bind(this,
-                    function(individualEntry) {
-                        let [type, value] = individualEntry.get_scope();
-                        let role = individualEntry.get_role();
-
-                        if (type == "default") {
-                            arrIndex = count;
-                            if (docAccessRule == GData.ACCESS_SCOPE_USER)
-                                flag = "deletePub";
-                            else if (newDocRole != role && role != 'none')
-                                 flag = "changePub";
-                            else if (role == 'none')
-                                 flag = "deleteLinkToPub";
-                            else 
-                                flag = "doNotSend";                           
-                        }
-                        count++;  
-                    }));
-
-            if (flag == "" && docAccessRule == GData.ACCESS_SCOPE_DEFAULT)
-                flag = "addPub";
+        let source = Application.sourceManager.getItemById(this.resourceUrn);
+
+        let authorizer = new GData.GoaAuthorizer({ goa_object: source.object });
+        let service = new GData.DocumentsService({ authorizer: authorizer });
+
+        let docAccessRule = this._getDocumentPermission();
+        let newDocRole = this._getDocumentRole();
+        let entries = this.feed.get_entries();
+        let values = [];
+        let count = 0;
+        let arrIndex = 0;
+        let flag = "";
+
+        entries.forEach(Lang.bind(this,
+            function(individualEntry) {
+                let [type, value] = individualEntry.get_scope();
+                let role = individualEntry.get_role();
+
+                if (type == "default") {
+                    arrIndex = count;
+                    if (docAccessRule == GData.ACCESS_SCOPE_USER)
+                        flag = "deletePub";
+                    else if (newDocRole != role && role != 'none')
+                        flag = "changePub";
+                    else if (role == 'none')
+                        flag = "deleteLinkToPub";
+                    else 
+                        flag = "doNotSend";                           
+                 }
+                 count++;  
+            }));
+
+        if (flag == "" && docAccessRule == GData.ACCESS_SCOPE_DEFAULT)
+            flag = "addPub";
  
-            if (flag != '') {
+        if (flag != '') {
       
-                if (flag == "addPub") { 
-                // If we are making the doc public, send a new permission
-                    let accessRule = new GData.AccessRule();
-                    let aclLink = this.entry.look_up_link(GData.LINK_ACCESS_CONTROL_LIST);
-
-                    accessRule.set_scope(docAccessRule, null);
-                    accessRule.set_role(newDocRole);
-                    service.insert_entry_async(service.get_primary_authorization_domain(),
-                        aclLink.get_uri(), accessRule, null, Lang.bind(this,
-                            function(service, res) {
-                                try {
-                                    let insertedAccessRule = service.insert_entry_finish(res);
-                                } catch(e) {
-                                    log("Error inserting new ACL scope for document " + e.message);
-                                    this.errorStr = "The document was not updated";
-                                    this._showErrorDialog(this.errorStr);
-		                }
-                            }));
-                }
+            if (flag == "addPub") { 
+            // If we are making the doc public, send a new permission
+                let accessRule = new GData.AccessRule();
+                let aclLink = this.entry.look_up_link(GData.LINK_ACCESS_CONTROL_LIST);
+
+                accessRule.set_scope(docAccessRule, null);
+                accessRule.set_role(newDocRole);
+                service.insert_entry_async(service.get_primary_authorization_domain(),
+                    aclLink.get_uri(), accessRule, null, Lang.bind(this,
+                        function(service, res) {
+                            try {
+                                let insertedAccessRule = service.insert_entry_finish(res);
+                            } catch(e) {
+                                log("Error inserting new ACL scope for document " + e.message);
+                                this.errorStr = "The document was not updated";
+                                this._showErrorDialog(this.errorStr);
+		            }
+                        }));
+            }
              
-                if (flag == "changePub") { 
-                // If we are changing the role, update the entry              
-                    let accessRule = entries[arrIndex];
-
-                        accessRule.set_role(newDocRole);
-                        service.update_entry_async(service.get_primary_authorization_domain(), 
-                            accessRule, null, Lang.bind(this,
-                                function(service, res) {
-                                    try {
-                                        let updatedAccessRule = service.update_entry_finish(res);
-                                    } catch(e) {
-                                        log("Error updating ACL scope for document " + e.message);
-                                        this.errorStr = "The document was not updated";
-                                        this._showErrorDialog(this.errorStr);
-		                    }
-                            }));
-                }
+            if (flag == "changePub") { 
+            // If we are changing the role, update the entry              
+                let accessRule = entries[arrIndex];
+
+                accessRule.set_role(newDocRole);
+                service.update_entry_async(service.get_primary_authorization_domain(), 
+                    accessRule, null, Lang.bind(this,
+                        function(service, res) {
+                            try {
+                                let updatedAccessRule = service.update_entry_finish(res);
+                            } catch(e) {
+                                log("Error updating ACL scope for document " + e.message);
+                                this.errorStr = "The document was not updated";
+                                this._showErrorDialog(this.errorStr);
+		            }
+                        }));
+            }
                       
-                if (flag == "deletePub") { 
-                // If we are changing the permission to private, delete the public entry.
-                    let accessRule = entries[arrIndex];
+            if (flag == "deletePub") { 
+            // If we are changing the permission to private, delete the public entry.
+                let accessRule = entries[arrIndex];
 
-                    service.delete_entry_async(service.get_primary_authorization_domain(), 
+                service.delete_entry_async(service.get_primary_authorization_domain(), 
                     accessRule, null, Lang.bind(this,
                         function(service, res) {
                             try {
@@ -506,15 +502,15 @@ const SharingDialog = new Lang.Class({
                                 log("Error deleting ACL scope for document  " + e.message);
                                 this.errorStr = "The document was not updated";
                                 this._showErrorDialog(this.errorStr);
-		         			}
+		            }
                         }));
-                }
+            }
                  
-                if (flag == "deleteLinkToPub") {
-                // Workaround if the doc is shared with link: step 1 delete shared with link permission.
-                   let accessRule = entries[arrIndex];
+            if (flag == "deleteLinkToPub") {
+            // Workaround if the doc is shared with link: step 1 delete shared with link permission.
+                let accessRule = entries[arrIndex];
 
-                    service.delete_entry_async(service.get_primary_authorization_domain(), 
+                service.delete_entry_async(service.get_primary_authorization_domain(), 
                     accessRule, null, Lang.bind(this,
                         function(service, res) {
                             try {
@@ -525,31 +521,30 @@ const SharingDialog = new Lang.Class({
                                 this._showErrorDialog(this.errorStr);
 		            }
                         }));
-                 }
+            }
 
-                 if (flag == "deleteLinkToPub") {
-                 // Workaround if the doc is shared with link: step 2 add the new public permisssion.
-                    let newAccessRule = new GData.AccessRule();
-                    let aclLink = this.entry.look_up_link(GData.LINK_ACCESS_CONTROL_LIST);
-
-                    newAccessRule.set_scope(docAccessRule, null);
-                    newAccessRule.set_role(newDocRole);
-                    service.insert_entry_async(service.get_primary_authorization_domain(),
-                        aclLink.get_uri(), newAccessRule, null, Lang.bind(this,
-                            function(service, res) {
-                                try {
-                                    let insertedAccessRule = service.insert_entry_finish(res);
-                                } catch(e) {
-                                    log("Error inserting new ACL scope for document " + e.message);
-                                    this.errorStr = "The document was not updated";
-                                    this._showErrorDialog(this.errorStr);
-		         			    }
-                            }));
-                }
+            if (flag == "deleteLinkToPub") {
+            // Workaround if the doc is shared with link: step 2 add the new public permisssion.
+                let newAccessRule = new GData.AccessRule();
+                let aclLink = this.entry.look_up_link(GData.LINK_ACCESS_CONTROL_LIST);
+
+                newAccessRule.set_scope(docAccessRule, null);
+                newAccessRule.set_role(newDocRole);
+                service.insert_entry_async(service.get_primary_authorization_domain(),
+                    aclLink.get_uri(), newAccessRule, null, Lang.bind(this,
+                        function(service, res) {
+                            try {
+                                let insertedAccessRule = service.insert_entry_finish(res);
+                            } catch(e) {
+                                log("Error inserting new ACL scope for document " + e.message);
+                                this.errorStr = "The document was not updated";
+                                this._showErrorDialog(this.errorStr);
+		            }
+                        }));
+            }
         }    
     },
 
-
     // Get the role for the new contact from the combobox
     _getNewContact: function() {
         let activeItem = this._comboBoxText.get_active();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]