root / src / pithos / content / dialogs / selectlist.js @ 46:f16f6e0e5b69
History | View | Annotate | Download (2.7 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 |
items = null;
|
34 |
|
35 |
function initGroup() { |
36 |
$mb = jQuery.noConflict();
|
37 |
|
38 |
items = window.arguments[0].inp; |
39 |
populate(); |
40 |
} |
41 |
|
42 |
function okDo() { |
43 |
var username = $mb('#menulistid').attr('label'); |
44 |
|
45 |
retname = findItem(username); |
46 |
|
47 |
window.arguments[0].out = { 'name' : retname, 'username' : username }; |
48 |
window.close(); |
49 |
} |
50 |
|
51 |
function onCancel() { |
52 |
window.arguments[0].out = null; |
53 |
window.close(); |
54 |
} |
55 |
|
56 |
function populate() { |
57 |
items.forEach( function(i) {
|
58 |
var menuitem = document.createElement('menuitem'); |
59 |
$mb('#popupmenu').append(menuitem); |
60 |
|
61 |
$mb(menuitem).attr({
|
62 |
label: i.username,
|
63 |
thename: i.name
|
64 |
}); |
65 |
}); |
66 |
|
67 |
$mb('#menulistid').attr({ label: items[0].username}); |
68 |
} |
69 |
|
70 |
// find the 'name' based on the full username since we are unable to store the value in an attribute
|
71 |
// inside the menuitem ...
|
72 |
function findItem(usern) { |
73 |
for each(var i in items) { |
74 |
if (i.username == usern) {
|
75 |
return i.name;
|
76 |
} |
77 |
} |
78 |
} |