Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/webroot/js/editors.js
blob: 6a002924a7ff150f5e5a81b02ecdc36bf62d9a9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
function showMenu() {
    document.getElementById('showMenuItem').style.display = 'none';
    document.getElementById('hideMenuItem').style.display = '';
    $("#editorMenu").slideDown('medium');
}
function hideMenu() {
    $("#editorMenu").slideUp('medium');
    document.getElementById('showMenuItem').style.display = '';
    document.getElementById('hideMenuItem').style.display = 'none';
}
/*************************************************
*               editors/queue                  *
*************************************************/
//Expand/collapse the filter box
function toggleFilters() {
    var div = document.getElementById('filterTable');
    if (div.style.display == 'none') {
        div.style.display = '';
    }
    else {
        div.style.display = 'none';
    }
}

/*************************************************
*               editors/review                 *
*************************************************/
//Array of possible actions
var actions = ['public', 'sandbox', 'info', 'superreview'];

//Simulate radio button group for action icons
function selectAction(action) {
    var actionField = document.getElementById('actionField');
    actionField.value = action;
    
    //Select action and deselect other actions
    for (var i = 0; i < actions.length; i++) {
        if (actions[i] == action) {
            changeIcon(actions[i], 'color');
            document.getElementById('details-' + actions[i]).style.display = '';
        }
        else {
            changeIcon(actions[i], 'bw');
            document.getElementById('details-' + actions[i]).style.display = 'none';
        }
    }
    
    // when rejecting, pre-select notification box
    $('#subscribe input').attr('checked', (action=='sandbox'));
    // no canned responses/app/os for info request
    if (action=='info')
        $('#canned,#testing').hide();
    else
        $('#canned,#testing').show();
    
    $('#subform').show('medium');
}

//Turn an icon colored/bw
function changeIcon(action, colorbw) {
    var icon = document.getElementById(action + 'Icon');
    var span = document.getElementById(action);
   
    icon.src = icon.src.substring(0, icon.src.lastIndexOf('/')+1) + action + '-' + colorbw + '.png';
    span.className = 'action_'+colorbw;
}

//Get number of selected files
function selectedFileCount() {
    var filesSelected = 0;
    var elements = document.getElementsByTagName('input');
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].className == 'fileCheckbox' && elements[i].disabled == false) {
            if (elements[i].checked == true) {
                filesSelected++;
            }
        }
    }
    
    return filesSelected;
}

//Show notice if more than one file selected
function selectedFile() {
    var filesSelected = selectedFileCount();
    
    if (filesSelected > 1) {
        document.getElementById('multipleNotice').style.display = '';
    }
    else {
        document.getElementById('multipleNotice').style.display = 'none';
    }
}

//Validate review form
function validateReview(type) {
    //Make sure an action was selected
    var action = document.getElementById('actionField').value;
    if (action == '') {
        errors += '- ' + localized['action'] + '\n';
    }
    
    if (type == 'pending' && action!='info') {
        //Make sure at least one file is selected
        var filesSelected = selectedFileCount();
        
        if (filesSelected == 0) {
            alert(localized['files']);
            return false;
        }
    }
    
    var errors = '';
    
    //Make sure comments were entered
    if (document.getElementById('comments').value == '') {
        errors += '- ' + localized['comments'] + '\n';
    }
    if (type == 'pending' && action!='info') {
        //Make sure tested operating system was entered
        if (document.getElementById('ApprovalOs').value == '') {
            errors += '- ' + localized['os'] + '\n';
        }
        //Make sure tested application was entered
        if (document.getElementById('ApprovalApplications').value == '') {
            errors += '- ' + localized['applications'] + '\n';
        }
    }
    
    if (errors != '') {
        alert(localized['errors'] + '\n' + errors);
        return false;
    }
    else {
        return true;
    }
}

/*************************************************
*               editors/reviewlog                *
*************************************************/
//Show a review entry's comments
function showComments(id) {
    document.getElementById('reviewComment_' + id).style.display = '';
    document.getElementById('reviewShow_' + id).style.display = 'none';
    document.getElementById('reviewHide_' + id).style.display = '';
    document.getElementById('reviewEntry_' + id).className = 'reviewEntryActive';
}

//Hide a review entry's comments
function hideComments(id) {
    document.getElementById('reviewComment_' + id).style.display = 'none';
    document.getElementById('reviewShow_' + id).style.display = '';
    document.getElementById('reviewHide_' + id).style.display = 'none';
    document.getElementById('reviewEntry_' + id).className = '';
}

function clearInput(input) {
    if (input.value == 'YYYY-MM-DD') {
        input.value = '';
    }
}

/*************************************************
*               editors/featured                 *
*************************************************/


/*
    Creates new autocomplete object for whichever input that just recieved focus.
    Most likely done on focus to reduce # of objects instantiated on page load
*/
function prepAutocomplete(tagid) {
    $('#new-addon-id-' + tagid).autocomplete(autocompleteurl, {minChars:4, formatItem: formatResult, formatValue: formatData });
    $('#new-addon-id-' + tagid).focus();
}

//Formatting functions for autocomplete results returned from server
function formatResult(row) {
    return '<b>' + row[0] + '</b><br><i>' + row[1] + '</i>';
}

function formatData(row) {
    return row[2];
}

/*
    Parses input for addon id and name, then sends to server
*/
function addFeatureSubmit(tagid) {

    var addonid = document.getElementById('new-addon-id-' + tagid).value;

    addonname = addonid.substring(0, addonid.lastIndexOf('['));
    addonid = addonid.substring(addonid.lastIndexOf('[')+1, addonid.lastIndexOf(']'));
    
    if (addonid.length == 0) {
        editFeatureMessage(tagid, featureaddfailure, false);
        return false;
    }
    
    $.ajax({
        type: 'POST',
        url: featuredurl + '/add/ajax',
        data: $('#feature-add-form-'+tagid).serialize(),
        success : function() {
            $('#new-addon-id-' + tagid).attr('value', '');
            addNewFeatureRowBeforeElement($('#feature-add-tr-form-' + tagid), tagid, addonid, addonname);
        },
        error : function() {
            editFeatureMessage(tagid, featureaddfailure, false);
        }
    });
    
    return false;
}

/*
    After an addon is added to a featured list, it is added above the search box
*/
function addNewFeatureRowBeforeElement(sibling, tagid, addonid, addonname) {
    // Sure would be nice if we had a newer Prototype library :(

    var addonrow = document.createElement('tr');
    addonrow.setAttribute('id', 'feature-' + tagid + '-' + addonid);

    // First <td>
        var deletelink = document.createElement('a');
        deletelink.setAttribute('href', featuredurl + '/remove/' + tagid + '/' + addonid);
        deletelink.setAttribute('id', 'delete-' + tagid + '-' + addonid);
        deletelink.setAttribute('onclick', 'removeFeature(' + tagid + ',' + addonid + '); return false;');

        var deleteimage = document.createElement('img');
        deleteimage.setAttribute('src', imageurl + '/developers/delete.png');
        deleteimage.setAttribute('class', 'featureremove');
        deletelink.appendChild(deleteimage);

        var addonlink = document.createElement('a');
        addonlink.setAttribute('href', addonurl + '/' + addonid);
        addonlink.appendChild(document.createTextNode(addonname));

        var addontd1 = document.createElement('td');
        addontd1.appendChild(deletelink);
        addontd1.appendChild(addonlink);

    // Second <td>
        var addonform = document.createElement('form');
        addonform.setAttribute('id', 'feature-edit-form-' + tagid + '-' + addonid);
        addonform.setAttribute('onsubmit', 'editFeatureSubmit(' + tagid + ',' + addonid + '); return false;');
        addonform.setAttribute('action', featuredurl + '/edit');
        addonform.setAttribute('method', 'post');

        var addonforminputlocale = document.createElement('input');
        addonforminputlocale.setAttribute('name', 'data[AddonTag][feature_locales]');
        addonforminputlocale.setAttribute('id', 'edit-addon-locales-' + tagid + '-' + addonid);
        addonforminputlocale.setAttribute('size', '40');
        addonforminputlocale.setAttribute('type', 'text');
        addonform.appendChild(addonforminputlocale);

        var addonforminputsubmit = document.createElement('input');
        addonforminputsubmit.setAttribute('id', 'edit-feature-submit-' + tagid + '-' + addonid);
        addonforminputsubmit.setAttribute('value', featureeditsubmit);
        addonforminputsubmit.setAttribute('type', 'submit');
        addonforminputsubmit.setAttribute('value', featureeditsubmit);
        addonform.appendChild(addonforminputsubmit);

        var addonformfeaturemessage = document.createElement('span');
        addonformfeaturemessage.setAttribute('id', 'edit-feature-message-' + tagid + '-' + addonid);
        addonform.appendChild(addonformfeaturemessage);


        var addontd2 = document.createElement('td');
        addontd2.appendChild(addonform);

        addonrow.appendChild(addontd1);
        addonrow.appendChild(addontd2);

    sibling.before(addonrow);
    return true;
}


function editFeatureSubmit(tagid, addonid) {
    var locales = document.getElementById('edit-addon-locales-' + tagid + '-' + addonid).value;
    
    if (locales.match(/[^A-Za-z,-]/)) {
        editFeatureMessage(tagid, addedinvalidlocale, false);
        return false;
    }
    
    $.ajax({
        type: 'POST',
        url: featuredurl + '/edit/ajax',
        data: $('#feature-edit-form-'+tagid+'-'+addonid).serialize(),
        success : function(){
            editFeatureMessage(tagid, featureeditsuccess, true);
        },
        error : function(){
            editFeatureMessage(tagid, featureeditfailure, false);
        }
    });

    return false;
}

/*
    Shows a message when editing a featured addon, then hides after 5 seconds
*/
function editFeatureMessage(tagid, message, success) {
    var target = $('#edit-feature-message-' + tagid);
    if (success) {
        target.attr('class', 'success');
    } else {
        target.attr('class', 'failure');
    }
    target.html(message);

    var toclear = $('#edit-feature-message-' + tagid);

    setTimeout( function() {toclear.html('');} , 5000);
}


function removeFeature(tagid, addonid) {
    $.ajax({
        url: featuredurl + '/remove/ajax',
        type: 'POST',
        data: $('#feature-remove-form-'+tagid+'-'+addonid).serialize(),
        success: function(){
            $('#feature-' + tagid + '-' + addonid).fadeOut();
        },
        error : function(){
            editFeatureMessage(tagid, featureremovefailure, false);
        }
    });
    return false;
}