viewacl.tpl 8.66 KB
Newer Older
1
<input type="hidden" name="accesslist" value="">
2
<div id="viewacl_lhs">
3
4
5
6
    <div id="potentialpresetitems"></div>
    <div>
        {{str tag=search}} <input type="text" name="search" id="search">
        <select name="type" id="type">
7
            <option value="group">{{str tag=groups}}</option>
8
            <option value="user" selected="selected">{{str tag=users}}</option>
9
10
11
12
13
        </select>
        <button id="dosearch" type="button">{{str tag=go}}</button>
        <table id="results">
            <thead>
                <tr>
14
                    <th></th>
15
                    <th>{{str tag=name}}</th>
16
                    <th></th>
17
18
19
20
21
22
23
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</div>
24
<h3>{{str tag=Added section=view}}</h3>
25
26
27
28
<div id="accesslistitems">
</div>

<script type="text/javascript">
29
30
var count = 0;

31
32
33
34
35
// Utility functions

// Given a row, render it on the left hand side
function renderPotentialPresetItem(item) {
    var addButton = BUTTON({'type': 'button'}, '{{str tag=add}}');
36
    var row = DIV(null, addButton, ' ', item.name);
37
    item.preset = true;
38
39
40
41
42
43
44
45
46
47
48
49

    connect(addButton, 'onclick', function() {
        appendChildNodes('accesslist', renderAccessListItem(item));
    });
    appendChildNodes('potentialpresetitems', row);

    return row;
}

// Given a row, render it on the right hand side
function renderAccessListItem(item) {
    var removeButton = BUTTON({'type': 'button'}, '{{str tag=remove}}');
50
    var dateInfo = TABLE(null,
51
52
53
54
55
56
57
58
59
        TBODY(null,
            TR(null,
                TH(null, get_string('From') + ':'),
                TD(null, makeCalendarInput(item, 'start'), makeCalendarLink(item, 'start'))
            ),
            TR(null,
                TH(null, get_string('To') + ':'),
                TD(null, makeCalendarInput(item, 'stop'), makeCalendarLink(item, 'stop'))
            )
60
        )
61
    );
62
63
64
65
    var cssClass = 'ai-container';
    if (item.preset) {
        cssClass += '  preset';
    }
66
67
68
69
70
    cssClass += ' ' + item.type + '-container';
    var name = item.name;
    if (item.type == 'user') {
        name = [IMG({'src': config.wwwroot + 'thumb.php?type=profileicon&id=' + item.id + '&maxwidth=20&maxheight=20'}), ' ', name];
    }
71
    var row = TABLE({'class': cssClass},
72
73
        TBODY(null, 
            TR(null,
74
                TH(null, name,  (item.role ? ' - ' + item.roledisplay : '')),
75
76
77
78
                TD({'class': 'right'}, removeButton)
            ),
            TR(null,
                TD({'colspan': 2},
79
                    dateInfo,
80
81
82
83
84
                    INPUT({
                        'type': 'hidden',
                        'name': 'accesslist[' + count + '][type]',
                        'value': item.type
                    }),
85
                    (item.id ?
86
87
88
                    INPUT({
                        'type': 'hidden',
                        'name': 'accesslist[' + count + '][id]',
89
90
91
92
93
                        'value': item.id
                    })
                    :
                    null
                    ),
94
                    (typeof(item.role) != 'undefined' ?
95
96
                    INPUT({
                        'type': 'hidden',
97
98
                        'name': 'accesslist[' + count + '][role]',
                        'value': item.role
99
100
101
102
                    })
                    :
                    null
                    )
103
                )
104
105
            )
        )
106
    );
107
108
109
110

    connect(removeButton, 'onclick', function() {
        removeElement(row);
    });
Martyn Smith's avatar
Martyn Smith committed
111
    appendChildNodes('accesslistitems', row);
112
113
114
    
    setupCalendar(item, 'start');
    setupCalendar(item, 'stop');
115
    count++;
116
117
}

118
119
120
function makeCalendarInput(item, type) {
    return INPUT({
        'type':'text',
121
122
        'name': 'accesslist[' + count + '][' + type + 'date]',
        'id'  :  type + 'date_' + count,
123
        'value': item[type + 'date'] ? item[type + 'date'] : '',
124
        'size': '15'
125
126
127
128
129
130
    });
}

function makeCalendarLink(item, type) {
    var link = A({
        'href'   : '',
131
132
        'id'     : type + 'date_' + count + '_btn',
        'onclick': 'return false;', // @todo do with mochikit connect
133
134
        'class'  : 'pieform-calendar-toggle'},
        IMG({
135
            'src': '{{theme_path location='images/calendar.gif'}}',
136
137
138
139
            'alt': ''})
    );
    return link;
}
140

141
function setupCalendar(item, type) {
142
    //log(type);
143
    var dateStatusFunc, selectedFunc;
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    //if (type == 'start') {
    //    dateStatusFunc = function(date) {
    //        startDateDisallowed(date, $(item.id + '_stopdate'));
    //    };
    //    selectedFunc = function(calendar, date) {
    //        startSelected(calendar, date, $(item.id + '_startdate'), $(item.id + '_stopdate'));
    //    }
    //}
    //else {
    //    dateStatusFunc = function(date) {
    //        stopDateDisallowed(date, $(item.id + '_startdate'));
    //    };
    //    selectedFunc = function(calendar, date) {
    //        stopSelected(calendar, date, $(item.id + '_startdate'), $(item.id + '_stopdate'));
    //    }
    //}
Martyn Smith's avatar
Martyn Smith committed
160
161
162
163
    if (!$(type + 'date_' + count)) {
        logWarn('Couldn\'t find element: ' + type + 'date_' + count);
        return;
    }
164
    Calendar.setup({
165
166
167
168
169
170
        "ifFormat"  :"%Y\/%m\/%d %H:%M",
        "daFormat"  :"%Y\/%m\/%d %H:%M",
        "inputField": type + 'date_' + count,
        "button"    : type + 'date_' + count + '_btn',
        //"dateStatusFunc" : dateStatusFunc,
        //"onSelect"       : selectedFunc
171
        "showsTime" : true
172
173
    });
}
174
175
176

// SETUP

177
// Left top: public, loggedin, friends
178
179
180
181
182
183
184
185
var potentialPresets = {{$potentialpresets}};
forEach(potentialPresets, function(preset) {
    renderPotentialPresetItem(preset);
});

// Left hand side
var searchTable = new TableRenderer(
    'results',
186
    'access.json.php',
187
    [
188
        undefined, undefined, undefined
189
190
191
192
    ]
);
searchTable.statevars.push('type');
searchTable.statevars.push('query');
193
searchTable.type = 'user';
194
195
196
197
198
199
200
201
202
203
searchTable.pagerOptions = {
    'firstPageString': '\u00AB',
    'previousPageString': '<',
    'nextPageString': '>',
    'lastPageString': '\u00BB',
    'linkOptions': {
        'href': '',
        'style': 'padding-left: 0.5ex; padding-right: 0.5ex;'
    }
}
204
205
searchTable.query = '';
searchTable.rowfunction = function(rowdata, rownumber, globaldata) {
206
    rowdata.type = searchTable.type;
207
208
209
    var buttonTD = TD({'style': 'white-space:nowrap;'});

    var addButton = BUTTON({'type': 'button', 'class': 'button'}, '{{str tag=add}}');
210
211
212
    connect(addButton, 'onclick', function() {
        appendChildNodes('accesslist', renderAccessListItem(rowdata));
    });
213
214
    appendChildNodes(buttonTD, addButton);

215
    var identityNodes = [], profileIcon = null, roleSelector = null;
216
    if (rowdata.type == 'user') {
217
        profileIcon = IMG({'src': config.wwwroot + 'thumb.php?type=profileicon&maxwidth=20&maxheight=20&id=' + rowdata.id});
218
        identityNodes.push(A({'href': config.wwwroot + 'user/view.php?id=' + rowdata.id, 'target': '_blank'}, rowdata.name));
219
    }
220
    else if (rowdata.type == 'group') {
221
        rowdata.role = null;
222
        var options = [OPTION({'value':null, 'selected':true}, '{{str tag=everyoneingroup section=view}}')];
223
224
        for (r in globaldata.roles[rowdata.grouptype]) {
            options.push(OPTION({'value':globaldata.roles[rowdata.grouptype][r].name}, globaldata.roles[rowdata.grouptype][r].display));
225
        }
226
227
228
        roleSelector = SELECT({'name':'role'}, options);
        connect(roleSelector, 'onchange', function() {
            rowdata.role = this.value;
229
230
231
            if (this.value) {
                rowdata.roledisplay = scrapeText(this.childNodes[this.selectedIndex]);
            }
232
        });
233
        identityNodes.push(A({'href': config.wwwroot + 'group/view.php?id=' + rowdata.id, 'target': '_blank'}, rowdata.name));
234
235
        identityNodes.push(" - ");
        identityNodes.push(roleSelector);
236
237
238
239
    }

    return TR({'class': 'r' + (rownumber % 2)},
        buttonTD,
240
        TD({'style': 'vertical-align: middle;'}, identityNodes),
241
        TD({'class': 'center', 'style': 'vertical-align: middle;width:20px;'}, profileIcon)
242
    );
243
244
245
246
247
248
249
250
251
252
253
254
}
searchTable.updateOnLoad();

function search(e) {
    searchTable.query = $('search').value;
    searchTable.type  = $('type').options[$('type').selectedIndex].value;
    searchTable.doupdate();
    e.stop();
}


// Right hand side
Martyn Smith's avatar
Martyn Smith committed
255
256
257
258
259
260
261
262
addLoadEvent(function () {
    var accesslist = {{$accesslist}};
    if (accesslist) {
        forEach(accesslist, function(item) {
            renderAccessListItem(item);
        });
    }
});
263
264
265
266
267
268
269
270
271
272
273
274
275

addLoadEvent(function() {
    // Populate the "potential access" things (public|loggedin|allfreidns)

    connect($('search'), 'onkeydown', function(e) {
        if (e.key().string == 'KEY_ENTER') {
            search(e);
        }
    });
    connect($('dosearch'), 'onclick', search);
});

</script>