viewacl.tpl 7.4 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
24
25
26
27
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</div>
<div id="accesslistitems">
</div>

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

30
31
32
33
34
// Utility functions

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

    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}}');
48
49
50
51
52
53
    var dateDiv = DIV(null,
        makeCalendarInput(item, 'start'),
        makeCalendarLink(item, 'start'),
        makeCalendarInput(item, 'stop'),
        makeCalendarLink(item, 'stop')
    );
54
    var row = TABLE(null,
55
56
        TBODY(null, 
            TR(null,
57
                TH(null, item.name + (item.tutoronly ? ' ' + '{{str tag=tutors}}' : '')),
58
59
60
61
62
63
64
65
66
67
                TD({'class': 'right'}, removeButton)
            ),
            TR(null,
                TD({'colspan': 2},
                    dateDiv,
                    INPUT({
                        'type': 'hidden',
                        'name': 'accesslist[' + count + '][type]',
                        'value': item.type
                    }),
68
                    (item.id ?
69
70
71
                    INPUT({
                        'type': 'hidden',
                        'name': 'accesslist[' + count + '][id]',
72
73
74
75
76
77
78
79
80
81
82
83
84
85
                        'value': item.id
                    })
                    :
                    null
                    ),
                    (typeof(item.tutoronly) != 'undefined' ?
                    INPUT({
                        'type': 'hidden',
                        'name': 'accesslist[' + count + '][tutoronly]',
                        'value': item.tutoronly
                    })
                    :
                    null
                    )
86
                )
87
88
            )
        )
89
    );
90
91
92
93

    connect(removeButton, 'onclick', function() {
        removeElement(row);
    });
Martyn Smith's avatar
Martyn Smith committed
94
    appendChildNodes('accesslistitems', row);
95
96
97
    
    setupCalendar(item, 'start');
    setupCalendar(item, 'stop');
98
    count++;
99
100
}

101
102
103
function makeCalendarInput(item, type) {
    return INPUT({
        'type':'text',
104
105
        'name': 'accesslist[' + count + '][' + type + 'date]',
        'id'  :  type + 'date_' + count,
Martyn Smith's avatar
Martyn Smith committed
106
        'value': item[type + 'date'] ? item[type + 'date'] : ''
107
108
109
110
111
112
    });
}

function makeCalendarLink(item, type) {
    var link = A({
        'href'   : '',
113
114
        'id'     : type + 'date_' + count + '_btn',
        'onclick': 'return false;', // @todo do with mochikit connect
115
116
        'class'  : 'pieform-calendar-toggle'},
        IMG({
117
            'src': '{{theme_path location='images/calendar.gif'}}',
118
119
120
121
            'alt': ''})
    );
    return link;
}
122

123
function setupCalendar(item, type) {
124
    //log(type);
125
    var dateStatusFunc, selectedFunc;
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
    //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
142
143
144
145
    if (!$(type + 'date_' + count)) {
        logWarn('Couldn\'t find element: ' + type + 'date_' + count);
        return;
    }
146
    Calendar.setup({
147
148
149
150
151
152
        "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
153
        "showsTime" : true
154
155
    });
}
156
157
158

// SETUP

159
// Left top: public, loggedin, friends
160
161
162
163
164
165
166
167
var potentialPresets = {{$potentialpresets}};
forEach(potentialPresets, function(preset) {
    renderPotentialPresetItem(preset);
});

// Left hand side
var searchTable = new TableRenderer(
    'results',
168
    'access.json.php',
169
    [
170
        undefined, undefined, undefined
171
172
173
174
    ]
);
searchTable.statevars.push('type');
searchTable.statevars.push('query');
175
searchTable.type = 'user';
176
177
178
179
180
181
182
183
184
185
searchTable.pagerOptions = {
    'firstPageString': '\u00AB',
    'previousPageString': '<',
    'nextPageString': '>',
    'lastPageString': '\u00BB',
    'linkOptions': {
        'href': '',
        'style': 'padding-left: 0.5ex; padding-right: 0.5ex;'
    }
}
186
187
searchTable.query = '';
searchTable.rowfunction = function(rowdata, rownumber, globaldata) {
188
    rowdata.type = searchTable.type;
189
190
191
    var buttonTD = TD({'style': 'white-space:nowrap;'});

    var addButton = BUTTON({'type': 'button', 'class': 'button'}, '{{str tag=add}}');
192
    connect(addButton, 'onclick', function() {
193
        rowdata.tutoronly = 0;
194
195
        appendChildNodes('accesslist', renderAccessListItem(rowdata));
    });
196
197
198
    appendChildNodes(buttonTD, addButton);

    var profileIcon, tutorAddButton = null;
199
200
201
    if (rowdata.type == 'user') {
        profileIcon = IMG({'src': config.wwwroot + 'thumb.php?type=profileicon&size=40x40&id=' + rowdata.id});
    }
202
    else if (rowdata.type == 'group') {
203
204
205
206
207
208
209
210
211
212
213
214
        tutorAddButton = BUTTON({'type': 'button', 'class': 'button'}, '{{str tag=addtutors section=view}}');
        connect(tutorAddButton, 'onclick', function() {
            rowdata.tutoronly = 1;
            appendChildNodes('accesslist', renderAccessListItem(rowdata));
        });
        appendChildNodes(buttonTD, tutorAddButton);
    }

    return TR({'class': 'r' + (rownumber % 2)},
        buttonTD,
        TD({'class': 'fullwidth'}, rowdata.name),
        TD({'class': 'center', 'style': 'width:40px'}, profileIcon)
215
    );
216
217
218
219
220
221
222
223
224
225
226
227
}
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
228
229
230
231
addLoadEvent(function () {
    var accesslist = {{$accesslist}};
    if (accesslist) {
        forEach(accesslist, function(item) {
232
            log(item);
Martyn Smith's avatar
Martyn Smith committed
233
234
235
236
            renderAccessListItem(item);
        });
    }
});
237
238
239
240
241
242
243
244
245
246
247
248
249

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>