]> git.openstreetmap.org Git - osqa.git/blob - forum/skins/default/templates/osqaadmin/nodeman.html
Merge pull request #2 from udacity/update_django
[osqa.git] / forum / skins / default / templates / osqaadmin / nodeman.html
1 {% extends basetemplate %}
2
3 {% load i18n user_tags extra_tags extra_filters admin_static %}
4
5 {% block adminjs %}
6     <script type="text/javascript">
7         $(function() {
8             var $form = $('#changelist-search');
9
10             $('#all-node-type-link').click(function() {
11                 $('#type-filter-container').find('input').remove();
12                 $form.submit();
13             });
14
15             $('.node-type-link').click(function() {
16                 var link_type = $(this).attr('href').substring(1);
17
18                 if ($('#type-filter-container').find('input[value=' + link_type + ']').length == 0) {
19                     $('#type-filter-container').append($("<input name=\"node_type\" type=\"hidden\" value=\"" + link_type + "\" />"));
20                 } else {
21                     $('#type-filter-container').find('input[value=' + link_type + ']').remove();
22                 }
23
24                 $form.submit();                
25             });
26
27             $('#all-state-link').click(function() {
28                 $('#state-filter-container').find('input').remove();
29                 $form.submit();
30             });
31
32             $('.state-type-link').click(function() {
33                 var state_type = $(this).attr('href').substring(1);
34
35                 if ($('#state-filter-container').find('input[value=' + state_type + ']').length == 0) {
36                     $('#state-filter-container').append($("<input name=\"state_type\" type=\"hidden\" value=\"" + state_type + "\" />"));
37                 } else {
38                     $('#state-filter-container').find('input[value=' + state_type + ']').remove();
39                 }
40
41                 $form.submit();
42             });
43
44             $('.action-select').change(function() {
45                 $('#action-toggle').removeAttr('checked');
46                 var $tr = $(this).parents('tr');
47                 if ($(this).attr('checked')) {
48                     $tr.addClass('selected');
49                 } else {
50                     $tr.removeClass('selected');
51                 }
52             }).change();
53
54             $('#action-toggle').change(function() {
55                 var $rows = $('#result_list').find('tbody').find('tr');
56                 var $boxes = $('#result_list').find('tbody').find('input');
57
58                 if ($(this).attr('checked')) {
59                     $rows.addClass('selected');
60                     $boxes.attr('checked', 'checked')
61                 } else {
62                     $rows.removeClass('selected');
63                     $boxes.removeAttr('checked');
64                 }
65             });
66
67             $('#author-selector').autocomplete('{% url "matching_users" %}', {
68                 minChars: 1,
69                 matchContains: true,
70                 max: 10,
71
72                 formatItem: function(row, i, max, value) {
73                     return row[1] + ' (' + row[2] + ' {% trans "rep" %})';
74                 },
75
76                 formatResult: function(row, i, max, value){
77                     return row[1];
78                 }
79             });
80
81             $('#author-selector').result(function(event, data, formatted) {
82                 if ($('#author-filter-container').find('input[value=' + data[0] + ']').length == 0) {
83                     $('#author-filter-container').append($("<input name=\"authors\" type=\"hidden\" value=\"" + data[0] + "\" />"));
84                     $form.submit();
85                 }
86             });
87
88             $('.author-filter-remover').click(function() {
89                 var id = $(this).attr('rel');
90                 if ($('#author-filter-container').find('input[value=' + id + ']').length > 0) {
91                     $('#author-filter-container').find('input[value=' + id + ']').remove();
92                     $form.submit();
93                 }
94             });
95
96             $('#tag-selector').autocomplete('{% url "matching_tags" %}', {
97                 minChars: 1,
98                 matchContains: true,
99                 max: 10,
100
101                 formatItem: function(row, i, max, value) {
102                     return row[1] + ' (' + row[2] + ' {% trans "uses" %})';
103                 },
104
105                 formatResult: function(row, i, max, value){
106                     return row[1];
107                 }
108             });
109
110             $('#tag-selector').result(function(event, data, formatted) {
111                 if ($('#tag-filter-container').find('input[value=' + data[0] + ']').length == 0) {
112                     $('#tag-filter-container').append($("<input name=\"tags\" type=\"hidden\" value=\"" + data[0] + "\" />"));
113                     $form.submit();
114                 }
115             });
116
117             $('.tag-filter-remover').click(function() {
118                 var id = $(this).attr('rel');
119                 if ($('#tag-filter-container').find('input[value=' + id + ']').length > 0) {
120                     $('#tag-filter-container').find('input[value=' + id + ']').remove();
121                     $form.submit();
122                 }
123             });
124
125             $('#filter-name-box').one('focus', function() {
126                 $(this).val('');
127                 $(this).css('color', 'black');
128             });
129
130             $('#filter-name-box').keyup(function() {
131                 if ($(this).val().trim().length > 0) {
132                     $('#save-filter-button').removeAttr('disabled');
133                     $('#save-filter-button').css('color', 'black');
134                 } else {
135                     $('#save-filter-button').css('color', '#AAA');
136                     $('#save-filter-button').attr('disabled', 'disabled');
137                 }
138             });
139
140             var resize_data = null;
141
142             $('.col-resizer').mousedown(function(e) {
143                 var $to_resize = $(this).prev();
144
145                 resize_data = {
146                     resizer: $(this),
147                     to_resize: $to_resize,
148                     start_width: $to_resize.innerWidth(),
149                     x_start: e.pageX,
150                 }
151             });
152
153             $('body').mousemove(function(e) {
154                 if (resize_data != null) {
155                     var new_size = (resize_data.start_width - (resize_data.x_start - e.pageX)) + 'px';
156                     resize_data.to_resize.css({'max-width': new_size, 'min-width': new_size})
157                     resize_data.resizer.css('max-width', '3px');
158                 }
159             });
160
161             $('body').mouseup(function() {
162                 if (resize_data != null)
163                     resize_data = null;
164             });
165
166             $('#filter-panel-header').click(function() {
167                 $('#filter-panel').slideToggle();
168             });
169
170             $('#state-filter-type').change(function() {
171                 $('#state-filter-type-hidden').val($(this).val());
172                 $form.submit();
173             });
174             
175             $('#reset-text-filter').click(function() {
176                 $('#text-filter-input').val('');
177                 $form.submit();
178                 return false;
179             });
180         });
181     </script>
182     <style>
183         #toolbar ul li {
184             list-style-type: none;
185             display: inline;
186             margin-right: 12px;
187         }
188
189         #result_list tr td.deleted {
190             background-color: #FDD;
191             border-bottom: 1px solid #a9a9a9;
192         }
193
194         #result_list tr td.accepted {
195             background-color: #DFD;
196             border-bottom: 1px solid #a9a9a9;
197         }
198
199         span.question-deleted {
200             text-decoration: line-through;
201         }
202
203         .col-resizer {
204             width: 2px;
205             min-width: 2px;
206             min-width: 2px;
207             cursor: col-resize;
208             padding: 0 0 0 0;
209         }
210     </style>
211     <link href="{% static 'admin/css/base.css' %}" rel="stylesheet" type="text/css" media="screen" />
212     <script type="text/javascript">
213     /* gettext identity library */
214
215     function gettext(msgid) { return msgid; }
216     function ngettext(singular, plural, count) { return (count == 1) ? singular : plural; }
217     function gettext_noop(msgid) { return msgid; }
218
219     function interpolate(fmt, obj, named) {
220       if (named) {
221         return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
222       } else {
223         return fmt.replace(/%s/g, function(match){return String(obj.shift())});
224       }
225     }
226
227     /* formatting library */
228
229     var formats = new Array();
230
231     formats['DATETIME_FORMAT'] = 'N j, Y, P';
232     formats['DATE_FORMAT'] = 'N j, Y';
233     formats['DECIMAL_SEPARATOR'] = '.';
234     formats['MONTH_DAY_FORMAT'] = 'F j';
235     formats['NUMBER_GROUPING'] = '0';
236     formats['TIME_FORMAT'] = 'P';
237     formats['FIRST_DAY_OF_WEEK'] = '0';
238     formats['TIME_INPUT_FORMATS'] = ['%H:%M:%S', '%H:%M'];
239     formats['THOUSAND_SEPARATOR'] = ',';
240     formats['DATE_INPUT_FORMATS'] = ['%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y', '%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y'];
241     formats['YEAR_MONTH_FORMAT'] = 'F Y';
242     formats['SHORT_DATE_FORMAT'] = 'm/d/Y';
243     formats['SHORT_DATETIME_FORMAT'] = 'm/d/Y P';
244     formats['DATETIME_INPUT_FORMATS'] = ['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', '%Y-%m-%d', '%m/%d/%Y %H:%M:%S', '%m/%d/%Y %H:%M', '%m/%d/%Y', '%m/%d/%y %H:%M:%S', '%m/%d/%y %H:%M', '%m/%d/%y'];
245
246     function get_format(format_type) {
247         var value = formats[format_type];
248         if (typeof(value) == 'undefined') {
249           return msgid;
250         } else {
251           return value;
252         }
253     }
254     
255     </script>
256     <script type="text/javascript" src="{% static 'admin/js/core.js' %}"></script>
257 {% endblock %}
258
259 {% block subtitle %}
260     {% trans "Node manager" %}
261 {% endblock %}
262 {% block description %}
263     {% trans "Nodes bulk management" %}
264 {% endblock %}
265
266 {% block admincontent %}
267     <div id="changelist" class="module filtered">
268         <div id="toolbar">
269             <form method="get" action="" id="changelist-search">
270             {% csrf_token %}
271             <div>
272                 <div>
273                     <label><img alt="Search" src="{% static 'admin/img/admin/icon_searchbox.png' %}"></label>
274                     <input type="text" size="40" name="text" id="text-filter-input" value="{{ text }}">
275                     <input type="submit" value="{% trans "Search" %}">
276                     {% if text %}
277                         <small><a href="#" id="reset-text-filter">{% trans "reset text filter" %}</a></small>
278                     {% endif %}
279                     <br />
280                     <ul>
281                         <li>
282                             <label>
283                                 <input type="radio" name="text_in" value="title"{% ifequal text_in "title" %} checked="checked"{% endifequal %} />
284                             {% trans "Title" %}</label>
285                         </li>
286                         <li>
287                             <label>
288                                 <input type="radio" name="text_in" value="body"{% ifequal text_in "body" %} checked="checked"{% endifequal %} />
289                             {% trans "Body" %}</label>
290                         </li>
291                         <li>
292                             <label>
293                                 <input type="radio" name="text_in" value="both"{% ifequal text_in "both" %} checked="checked"{% endifequal %} />
294                             {% trans "Title and Body" %}</label>
295                        </li>
296                     </ul>
297                 </div>
298             </div>
299             <input type="hidden" name="sort" value="{{ nodes.paginator.current_sort }}" />
300             <input type="hidden" id="state-filter-type-hidden" name="state_filter_type" value="" />
301             <div style="display: none;" id="author-filter-container">
302                 {% for u in authors %}
303                 <input name="authors" type="hidden" value="{{ u.id }}" />
304                 {% endfor %}
305             </div>
306             <div style="display: none;" id="tag-filter-container">
307                 {% for t in tags %}
308                 <input name="tags" type="hidden" value="{{ t.id }}" />
309                 {% endfor %}
310             </div>
311             <div id="type-filter-container" style="display: none;">
312                 {% for type in type_filter %}
313                 <input name="node_type" type="hidden" value="{{ type }}" />
314                 {% endfor %}
315             </div>
316             <div id="state-filter-container" style="display: none;">
317                 {% for type in state_filter %}
318                 <input name="state_type" type="hidden" value="{{ type }}" />
319                 {% endfor %}
320             </div>
321             </form>
322         </div>
323         <div id="changelist-filter">
324             <h2 id="filter-panel-header">{% trans "Filter" %}<small> ({% trans "Click to show/hide" %})</small></h2>
325             <div id="filter-panel">
326             <h3>{% trans "By type" %}</h3>
327             <ul>
328                 <li {% if not type_filter %} class="selected"{% endif %}>
329                     <a id="all-node-type-link" href="#all" title="{% trans "click to clear the type filter" %}">{% trans "all" %}</a>
330                 </li>
331                 {% for type, name in node_types %}
332                 <li{% if type|contained_in:type_filter %} class="selected" title="{% trans "click to remove from the filter" %}"{% else %} title="{% trans "click to add to the filter" %}"{% endif %}>
333                     <a class="node-type-link" href="#{{ type }}">{{ name }}</a>
334                 </li>
335                 {% endfor %}
336             </ul>
337             <h3>{% trans "By state" %}</h3>
338             <ul>
339                 <li {% if not state_filter %} class="selected"{% endif %}>
340                     <a id="all-state-link" href="#any" title="{% trans "click to clear the state filter" %}">{% trans "any" %}</a>
341                 </li>
342                 {% for state_type in state_types %}
343                     <li{% if state_type|contained_in:state_filter %} class="selected" title="{% trans "click to remove from the filter" %}"{% else %} title="{% trans "click to add to the filter" %}"{% endif %}>
344                         <a class="state-type-link" href="#{{ state_type }}">{{ state_type }}</a>
345                     </li>
346                 {% endfor %}
347                 <li>
348                     <select id="state-filter-type">
349                         <option value="any"{% ifequal state_filter_type "any" %} selected="selected"{% endifequal %}>{% trans "Match any selected" %}</option>
350                         <option value="all"{% ifequal state_filter_type "all" %} selected="selected"{% endifequal %}>{% trans "Match all selected" %}</option>
351                     </select>
352                 </li>
353             </ul>
354             <h3>{% trans "By author(s)" %}</h3>
355             {% if not authors.count %}
356                 <small>{% trans "No users selected, use the box bellow to add users to the filter." %}</small>
357             {% else %}
358                 <ul>
359                     {% for u in authors %}
360                         <li class="selected">
361                             <img class="author-filter-remover" rel="{{ u.id }}" src="{% media "/media/images/close-small-dark.png" %}">
362                             {{ u.decorated_name }} ({{ u.reputation }})
363                         </li>
364                     {% endfor %}
365                 </ul>
366                 <small>{% trans "Click on the cross next to a user name to remove it from the filter." %}</small>
367             {% endif %}
368             <input type="text" size="20" autocomplete="off" id="author-selector" />
369
370             <h3>{% trans "By tag(s)" %}</h3>
371             {% if not tags.count %}
372                 <small>{% trans "No tags selected, use the box bellow to add tags to the filter." %}</small>
373             {% else %}
374                 <ul>
375                     {% for t in tags %}
376                         <li class="selected">
377                             <img class="tag-filter-remover" rel="{{ t.id }}" src="{% media "/media/images/close-small-dark.png" %}">
378                             {{ t.name }} ({{ t.used_count }})
379                         </li>
380                     {% endfor %}
381                 </ul>
382                 <small>{% trans "Click on the cross next to a tag name to remove it from the filter." %}</small>
383             {% endif %}
384             <input type="text" size="20" autocomplete="off" id="tag-selector" />
385
386             <h3>{% trans "Pre defined" %}</h3>
387             {% if not settings.NODE_MAN_FILTERS %}
388                 <small>{% trans "There are no saved filters. Click bellow to add." %}</small>
389             {% endif %}
390             <ul id="pre-filter-container">
391                 {% for name, uri in settings.NODE_MAN_FILTERS %}
392                 <li class="selected"><a href="{% url "admin_tools" "nodeman" %}?{{ uri }}">{{ name }}</a></li>
393                 {% endfor %}
394             </ul>
395             <form action="" method="POST">
396                 {% csrf_token %}
397                 <input name="filter_name" type="text" size="20" id="filter-name-box" style="color: #AAA;" value="{% trans "Filter name..." %}" />
398                 <button name="save_filter" value="0" style="color: #AAA;" title="{% trans "Click to save the current filter" %}" id="save-filter-button" disabled="disabled" class="button">{% trans "Save" %}</button>
399             </form>
400
401             {% comment %}<h3>{% trans "Show" %}</h3>
402             <form action="" method="get">
403                 {% csrf_token %}
404                 <div>{{ show_form.show }}</div>
405                 <input type="submit" value="{% trans "Refresh" %}" />
406             </form>{% endcomment %}
407             </div>
408         </div>
409         <form id="changelist-form" method="POST" action="">
410             {% csrf_token %}
411             <div class="actions">
412                 <label>
413                     {% trans "Action" %}:
414                     <select name="action">
415                         <option selected="selected" value="">---------</option>
416                         <option value="delete_selected">{% trans "Mark deleted" %}</option>
417                         <option value="undelete_selected">{% trans "Undelete" %}</option>
418                         <option value="hard_delete_selected">{% trans "Delete completely" %}</option>
419                         <option value="close_selected">{% trans "Close (questions only)" %}</option>
420                     </select>
421                 </label>
422                 <button value="0" name="execute" title="{% trans "Run the selected action" %}" class="button" type="submit">{% trans "Go" %}</button>
423             </div>
424             <table id="result_list" cellspacing="0">
425                 <thead>
426                     <tr>
427                         {% declare %}
428                             current_sort = nodes.paginator.current_sort
429                             added_at = current_sort == "added_at" and "ascending" or (current_sort == "added_at_asc" and "descending" or "")
430                             author = current_sort == "author" and "ascending" or (current_sort == "author_asc" and "descending" or "")
431                             score = current_sort == "score" and "ascending" or (current_sort == "score_asc" and "descending" or "")
432                             act_at = current_sort == "act_at" and "ascending" or (current_sort == "act_at_asc" and "descending" or "")
433                             act_by = current_sort == "act_by" and "ascending" or (current_sort == "act_by_asc" and "descending" or "")
434
435                             added_at_link = current_sort == "added_at" and nodes.paginator.added_at_asc_sort_link or nodes.paginator.added_at_sort_link
436                             author_link = current_sort == "author_asc" and nodes.paginator.author_sort_link or nodes.paginator.author_asc_sort_link
437                             act_at_link = current_sort == "act_at" and nodes.paginator.act_at_asc_sort_link or nodes.paginator.act_at_sort_link
438                             act_by_link = current_sort == "act_by_asc" and nodes.paginator.act_by_sort_link or nodes.paginator.act_by_asc_sort_link
439                         {% enddeclare %}
440                         {% spaceless %}
441                         <th class="action-checkbox-column">
442                             <input type="checkbox" id="action-toggle" style="display: inline;" />
443                         </th>                        
444                         <th>{% trans "Type" %}</th>
445                         <th>{% trans "Summary" %}</th>
446                         <th class="col-resizer"></th>
447                         <th>{% trans "State" %}</th>
448                         <th class="sorted {{ author }}">
449                             <a href="{{ author_link }}">{% trans "Author" %}</a>
450                         </th>
451                         <th class="sorted {{ added_at }}">
452                             <a href="{{ added_at_link }}">{% trans "Added at" %}</a>
453                         </th>
454                         {% comment %}
455                         <th class="sorted {{ score }}">
456                             <a href="{{ score_link }}">{% trans "Score" %}</a>
457                         </th>
458                         {% endcomment %}
459                         <th class="sorted {{ act_by }}">
460                             <a href="{{ act_by_link }}">{% trans "Last activity by" %}</a>
461                         </th>
462                         <th class="sorted {{ act_at }}">
463                             <a href="{{ act_at_link }}">{% trans "Last activity at" %}</a>
464                         </th>
465                         <th>{% trans "Tags" %}</th>
466                         {% endspaceless %}
467                     </tr>
468                 </thead>
469                 <tbody>
470                 {% with filter_form.state_type.data as state_type %}
471                 {% for node in nodes.paginator.page %}
472                     <tr class="{% cycle 'row1' 'row2' %}">
473                         <td><input type="checkbox" name="_selected_node" value="{{ node.id }}" class="action-select"></td>
474                         <td>{{ node.friendly_name }}</td>
475                         {% declare %}
476                             is_root = node.abs_parent == None
477                             title = is_root and node.title or node.abs_parent.title
478
479                             anchor = "<strong>%s</strong>" % html.hyperlink(node.get_absolute_url(), title)
480                             anchor = ((not is_root) and node.abs_parent.nis.deleted) and "<span class=\"question-deleted\">%s</span>" % anchor or anchor
481                             anchor = is_root and anchor or "(%s)" % anchor
482                             anchor = html.mark_safe(anchor)
483
484                             td_class = ""
485                             td_class = node.nis.accepted and "accepted" or td_class
486                             td_class = node.nis.deleted and "deleted" or td_class
487                         {% enddeclare %}
488                         <td class="{{ td_class }}" colspan="2">
489                             {{ anchor }}<br />
490                             {{ node.summary }}
491                         </td>
492                         <td>
493                             {% for state in node.states.all %}
494                             <b>{{ state.state_type }}</b> {% diff_date state.action.at %} {% trans "by" %}
495                             <a target="_blank" href="{{ state.action.by.get_absolute_url }}">{{ state.action.by.decorated_name }}</a><br />
496                             {% endfor %}
497                         </td>
498                         <td><a href="{{ node.author.get_absolute_url  }}">{{ node.author.decorated_name }}</a></td>
499                         <td>{% diff_date node.added_at %}</td>
500                         <!--<td>{{ node.score }}</td>-->
501                         <td><a href="{{ node.last_activity_by.get_absolute_url  }}">{{ node.last_activity_by.decorated_name }}</a></td>
502                         <td>{% diff_date node.last_activity_at %}</td>
503                         <td>
504                             {% for t in node.tags.all %}
505                                 {% if t|contained_in:tags %}<b>{{ t.name }}</b>
506                                 {% else %}{{ t.name }}{% endif %}
507                             {% endfor %}
508                         </td>
509                     </tr>
510                 {% endfor %}
511                 {% endwith %}
512                 </tbody>
513             </table>
514             {{ nodes.paginator.page_numbers }}
515         </form>
516     </div>
517 {% endblock %}