[gnome-documents/sharing] sharing: improve the radiobutton and checkbox behavior, display a message when the user can't edit p



commit 2f3260767941054838aa90aa09419f1536d21297
Author: Meg Ford <megford gnome org>
Date:   Fri Jan 11 01:04:52 2013 -0600

    sharing: improve the radiobutton and checkbox behavior, display a message when the user can't edit permissions

 src/sharing.js |  186 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 126 insertions(+), 60 deletions(-)
---
diff --git a/src/sharing.js b/src/sharing.js
index 2b3fcd3..cfd26de 100644
--- a/src/sharing.js
+++ b/src/sharing.js
@@ -75,8 +75,11 @@ const SharingDialog = new Lang.Class({
         let errorStr ="";
         let feed = null;      
         let newPub = false;
+        let noPermissionText = "";
         this.pubEdit = false;
         let rows = 0;
+        let isVisible = true;
+        this.changeEdit = false;
 
         this._createGDataEntry();
         let toplevel = Application.application.get_windows()[0];
@@ -85,13 +88,12 @@ const SharingDialog = new Lang.Class({
                                        transient_for: toplevel,
                                        modal: true,
                                        destroy_with_parent: true,
-                                       default_width: 100,
-                                       default_height: 200,
+                                       width_request: 335,
+                                       height_request: 200,
                                        margin_top: 5,
                                        title: _("Sharing Settings"),
                                        hexpand: true });
         this.widget.add_button(_("Done"), Gtk.ResponseType.OK);  // Label for Done button in Sharing dialog
-        this.widget.get_style_context().add_class('documents-dropdown');
 
         this.grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
                                    column_spacing: 6,
@@ -205,14 +207,13 @@ const SharingDialog = new Lang.Class({
         this._setButtons();
 
         this.grid.add(this._check);
-        rows++;
 
         this._close = new Gtk.Button({ label: _("Save"),
-                                       margin_left: 60 });  // Label for Done button for document permissions 
+                                       margin_left: 50 });  // Label for Save button for document permissions 
         this._close.connect('clicked', Lang.bind(this,
-            function() {             
+            function() {
+                this._close.set_sensitive(false);             
                 this._sendNewDocumentRule();
-                this._permissionPopUpDestroy();
             }));
 
         this.grid.attach(this._close, 1, rows, 2, 1);
@@ -232,7 +233,7 @@ const SharingDialog = new Lang.Class({
                                            halign: Gtk.Align.START });
         this._addContact.connect('changed', Lang.bind(this,
             function() {
-                let hasText = !!this._isValidEmail();//this._addContact.get_text();
+                let hasText = !!this._isValidEmail();
                 this._saveShare.sensitive = hasText;
                 this._comboBoxText.sensitive = hasText;
             }));
@@ -250,34 +251,65 @@ const SharingDialog = new Lang.Class({
                                            sensitive: false });
         this._saveShare.connect ('clicked', Lang.bind(this, this._onAddClicked));
         this.grid.attach_next_to(this._saveShare, this._comboBoxText, 1, 1, 1);
-        
+
+        this.noPermissionText = noPermissionText;
+        this._noPermissionLabel = this.noPermissionText;       
+        this._noPermission = new Gtk.Label({ label: _(this._noPermissionLabel),
+                                             halign: Gtk.Align.START,
+                                             hexpand: true });
+        this.grid.attach(this._noPermission, 0, rows, 3, 1);
+       
         this.widget.show_all();
-        this.button1.hide();
-        this.button2.hide();
-        this._check.hide();
-        this._close.hide();
+        this.isVisible = isVisible;
+        this._docPermissionButtons(this.isVisible);
+        this._addContact.hide();
+        this._comboBoxText.hide();
+        this._saveShare.hide();
     },
 
     _permissionPopUp: function() { 
-        this.dw.hide();
-        this.button1.show();
-        this.button2.show();
-        this._check.show();
-        this._close.show();
-        this._setButtons();
+        this.isVisible = false;
+        this._docPermissionButtons(this.isVisible);
     },
     
     _permissionPopUpDestroy: function() {
-        if(this.button1.get_active())
+        if (this.changeEdit == false) {
+        if (this.button1.get_active())
             this.docPrivate = "Private";
         else
             this.docPrivate = "Public";
+        } else {
+           this.docPrivate = "";
+        }
         this._setting.set_text(this.docPrivate);
-        this.dw.show();
-        this.button1.hide();
-        this.button2.hide();
-        this._check.hide();
-        this._close.hide();
+        this.isVisible = true;
+        this._docPermissionButtons(this.isVisible);
+        this._close.set_sensitive(true);//what does this do?
+    },
+
+    _docPermissionButtons: function(isVisible) {
+        this.isVisible = isVisible;
+
+        if (this.isVisible) {
+            this.dw.show();
+            this.button1.hide();
+            this.button2.hide();
+            this._check.hide();
+            this._close.hide();
+        }
+        
+        else {
+            this.dw.hide();
+            this.button1.show();
+            this.button2.show();
+            this._check.show();
+            this._close.show();  
+            if (this.docPrivate == "Public")
+                this.button2.set_active(true);
+            else if (this.docPrivate == "Private")
+                this.button1.set_active(true);            
+            this._setDoc();          
+        }
     },
 
     // Get the id of the selected doc from the sourceManager, give auth info to Google, and start the service
@@ -326,20 +358,25 @@ const SharingDialog = new Lang.Class({
 
                 if (value != null) {
                     values.push({ name: value, role: this._getUserRoleString(role) });
+
                     if ((this.accountName == value) && (role == 'writer' || role == 'owner'))
                         this.allowChanges = true;                  
-                }
-
-                else if (value == null) {
+                } else if (value == null) {
                     if (role != 'none')
-                        this.docPrivate = "Public";
-                    this._setting.set_text(this.docPrivate); // Text for document permission label
-                    if (role == 'writer')
-                        this.pubEdit = true; 
+                        this.docPrivate = "Public"; // Text for document permission label
+                    this._setting.set_text(this.docPrivate); 
+
+                    if (role == 'writer') {
+                        this.pubEdit = true;
+                    } 
                 }
+
+                if(role == 'owner')
+                   this.noPermissionText = value; 
              }));
 
         // Set values in the treemodel
+        if (this.changeEdit == false) {
         values.forEach(Lang.bind (this,
             function(value) {
                  let iter = this.model.append();
@@ -348,6 +385,7 @@ const SharingDialog = new Lang.Class({
                        SharingDialogColumns.ROLE ],
                      [ value.name, value.role ])
             }));
+         }
 
         this.grid.attach(this.sw, 0, 0, 3, 1);
         this.sw.set_visible(false);
@@ -355,10 +393,20 @@ const SharingDialog = new Lang.Class({
         this.sw.set_visible(true);
 
         if (this.docPrivate == "")
-            this.docPrivate = "Private";
-            this._setting.set_text(this.docPrivate);  // Text for document permission label
-        if(this.allowChanges)
-            this._changePermission.set_sensitive(true); 
+            this.docPrivate = "Private"; // Text for document permission label
+        this._setting.set_text(this.docPrivate);  
+
+        if(this.allowChanges) { 
+            this._changePermission.set_sensitive(true);
+            this._noPermission.hide();
+            this._addContact.show();
+            this._comboBoxText.show();
+            this._saveShare.show();
+        } else {
+            this._noPermission.set_text("You can ask " + 
+                                        this.noPermissionText + " for access");
+        }
+
     },
 
     // Get the roles, and make a new array containing strings that start with capital letters
@@ -426,6 +474,7 @@ const SharingDialog = new Lang.Class({
         let count = 0;
         let arrIndex = 0;
         let flag = "";
+        this.changeEdit = true;
 
         entries.forEach(Lang.bind(this,
             function(individualEntry) {
@@ -434,22 +483,23 @@ const SharingDialog = new Lang.Class({
 
                 if (type == "default") {
                     arrIndex = count;
+                    
                     if (docAccessRule == GData.ACCESS_SCOPE_USER)
                         flag = "deletePub";
-                    else if (newDocRole != role && role != 'none')
+                    else if (newDocRole != role && role != "none")
                         flag = "changePub";
-                    else if (role == 'none')
+                    else if (role == "none")
                         flag = "deleteLinkToPub";
                     else 
                         flag = "doNotSend";                           
-                 }
-                 count++;  
+                }
+                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
@@ -463,12 +513,15 @@ const SharingDialog = new Lang.Class({
                         function(service, res) {
                             try {
                                 let insertedAccessRule = service.insert_entry_finish(res);
+                                this._createGDataEntry();
+                               // this._setButtons();
                             } catch(e) {
                                 log("Error inserting new ACL scope for document " + e.message);
                                 this.errorStr = "The document was not updated";
                                 this._showErrorDialog(this.errorStr);
-		            }
-                        }));
+		            } 
+                this._permissionPopUpDestroy();                          
+                        }));               
             }
              
             if (flag == "changePub") { 
@@ -480,12 +533,15 @@ const SharingDialog = new Lang.Class({
                     accessRule, null, Lang.bind(this,
                         function(service, res) {
                             try {
-                                let updatedAccessRule = service.update_entry_finish(res);
+                                let updatedAccessRule = service.update_entry_finish(res); 
+                                this._createGDataEntry();
+                               // this._setButtons();
                             } catch(e) {
                                 log("Error updating ACL scope for document " + e.message);
                                 this.errorStr = "The document was not updated";
                                 this._showErrorDialog(this.errorStr);
 		            }
+                 this._permissionPopUpDestroy();
                         }));
             }
                       
@@ -498,15 +554,17 @@ const SharingDialog = new Lang.Class({
                         function(service, res) {
                             try {
                                 let afterDeletedAccessRule = service.delete_entry_finish(res);
+                                this._createGDataEntry();
                             } catch(e) {
                                 log("Error deleting ACL scope for document  " + e.message);
                                 this.errorStr = "The document was not updated";
                                 this._showErrorDialog(this.errorStr);
 		            }
+                                this._permissionPopUpDestroy();
                         }));
             }
-                 
-            if (flag == "deleteLinkToPub") {
+
+            if ( flag == "deleteLinkToPub") { 
             // Workaround if the doc is shared with link: step 1 delete shared with link permission.
                 let accessRule = entries[arrIndex];
 
@@ -522,7 +580,7 @@ const SharingDialog = new Lang.Class({
 		            }
                         }));
             }
-
+                
             if (flag == "deleteLinkToPub") {
             // Workaround if the doc is shared with link: step 2 add the new public permisssion.
                 let newAccessRule = new GData.AccessRule();
@@ -535,14 +593,24 @@ const SharingDialog = new Lang.Class({
                         function(service, res) {
                             try {
                                 let insertedAccessRule = service.insert_entry_finish(res);
+                                this._createGDataEntry();
                             } catch(e) {
                                 log("Error inserting new ACL scope for document " + e.message);
                                 this.errorStr = "The document was not updated";
                                 this._showErrorDialog(this.errorStr);
-		            }
+		            } 
+                this._permissionPopUpDestroy();                           
                         }));
             }
-        }    
+
+            if (flag == "doNotSend") {
+                this.changeEdit = false;
+                this._permissionPopUpDestroy();
+            } 
+        } else {
+            this.changeEdit = false;
+            this._permissionPopUpDestroy();
+        }  
     },
 
     // Get the role for the new contact from the combobox
@@ -558,37 +626,37 @@ const SharingDialog = new Lang.Class({
         return newContact;
     },
 
+    // Get the scope from the radiobuttons
     _getDocumentPermission: function() {
         let docAccRule = null; 
      
         if (this.button1.get_active()) {
         	this.docAccRule = GData.ACCESS_SCOPE_USER;
-        }
-        else if (this.button2.get_active()) {
+        } else if (this.button2.get_active()) {
         	this.docAccRule = GData.ACCESS_SCOPE_DEFAULT;   
         }
 
         return this.docAccRule;              
     },
 
+    // Get the role from the checkbox
     _getDocumentRole: function() {
         let newDocRole = null;
 
         if (this._check.get_active()) 
-            this.newDocRole = GData.DOCUMENTS_ACCESS_ROLE_WRITER;
-                           
+            this.newDocRole = GData.DOCUMENTS_ACCESS_ROLE_WRITER;                           
         else
             this.newDocRole = GData.DOCUMENTS_ACCESS_ROLE_READER;
 
         return this.newDocRole;
     },
 
-    _setDoc: function() {  
+    // Set the checkbox to the sensitive if the public radiobutton is active
+    _setDoc: function() { 
+ 
         if (this.button2.get_active()) {
             this._check.set_sensitive(true);
-        }
-
-        else {
+        } else {
             this._check.set_active(false);
             this._check.set_sensitive(false);
         }   
@@ -598,9 +666,7 @@ const SharingDialog = new Lang.Class({
 
         if (this.pubEdit == false) {
             this._check.set_active(false);
-        }
-
-        else {
+        } else {
             this._check.set_active(true);
         }
     



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