Statistics
| Branch: | Revision:

root / src / pithos / content / share / addusertoshare.js @ 46:f16f6e0e5b69

History | View | Annotate | Download (4.5 kB)

1
// The Pithos File Manager Firefox Extension is funded by GRNET S.A.
2
// (http://www.grnet.gr)
3
//
4
// Copyright (c) 2009, Christos KK Loverdos, Vassilios Karakoidas.
5
// All rights reserved.
6
//
7
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are
9
// met:
10
//
11
//   - Redistributions of source code must retain the above copyright
12
//     notice, this list of conditions and the following disclaimer.
13
//   - Redistributions in binary form must reproduce the above
14
//     copyright notice, this list of conditions and the following
15
//     disclaimer in the documentation and/or other materials provided
16
//     with the distribution.
17
//   - Neither the name of GRNET S.A. nor the names of its contributors
18
//     may be used to endorse or promote products derived from this
19
//     software without specific prior written permission.
20
//
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32

    
33
// Check if the supplied user exists in the supplied groupname
34
function checkUserExistsInShare(username) {
35
    for each( var i in permissions) {
36
        if(i.hasOwnProperty('user') && (i.user == username) ) {
37
            return false;
38
        }
39
    }
40
    return(true);
41
}
42

    
43
// Find a username based on a name, e.g. search for 'ebstest' should return useruri e.g. ebstest@....
44
// on error return false
45
function findUser(username) {
46
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
47

    
48
    queryurl = connection_obj.rest_url+'/users/'+username;
49

    
50
        // Check if the user has supplied the complete username e.g. ebstest@mplampla
51
        var pos = username.indexOf('@');
52
        if (pos != -1) {
53
                var basename = username.substring(0,pos);
54
                queryurl = connection_obj.rest_url+'/users/'+basename;
55
        }
56
    var response = connection_obj.rest_request_get(queryurl,'');
57
    if (connection_obj.success(response.status)) {
58
        var jsonlist = JSON.parse(response.responseText);
59

    
60
        // empty array returned when nothing found
61
        if (jsonlist.length == 0) {
62
            return false;
63
        }
64
        // Bring up a window with the users found ...
65

    
66
        // Create an array of strings with the contents of jsonlist.username to supply in the prompt
67
        var usersArray = new Array();
68
        for each(var i in jsonlist) {
69
            if (i.hasOwnProperty('username')) {
70
                usersArray.push(i.username);
71
            }
72
        }
73
        var selected={};
74
        
75
        // Bring up a window with the usernames ...
76
        var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
77
                            .getService(Components.interfaces.nsIPromptService);
78

    
79
        var result = prompts.select(window,'','Choose user',usersArray.length,usersArray,selected);
80

    
81
        // Check if we have valid return values
82
        if (result) {
83
            // Ok has been clicked
84
            // return a new object with the value in 'username' property
85
            return ({ username : usersArray[selected.value]});
86
        }
87
        else {
88
            // No user selected ...
89
            return false;
90
        }
91
    } else {
92
        // Connection failure 
93
        return false;
94
    }
95
    
96
}
97

    
98
/* Alert functions */
99

    
100
function promptBox(message) {
101
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
102
    var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
103
    var result = prompts.confirm(window, "Confirm action", message);
104
    return(result);
105
}
106

    
107
function promptAlert(message) {
108
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
109
    var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
110
    .getService(Components.interfaces.nsIPromptService);
111
    prompts.alert(window, "Information", message);
112
}