{# 'admin colorized (Prepare, Check,...) button JS hack'; corresponding css values in mini_buildd.css. #}
{% extends "admin/change_list.html" %}

{% block extrahead %}
{{ block.super }}
{{ media.js }}
{% if action_form %}{% if actions_on_top or actions_on_bottom %}
<script>
	// Initially from http://djangosnippets.org/snippets/2630/

	function fix_actions()
	{
		var container = $('div.actions');

		if (container.find('option').length < 10)
		{
			container.find('label, button').hide();

			var buttons = $('<div></div>')
					.prependTo(container)
					.css('display', 'inline');

			// Map action to classes from mini_buildd.css (for color only).
			let cssmap = {
				"mbd_action_prepare": "mbd-notice",
				"mbd_action_check": "mbd-info",
				"mbd_action_pc": "mbd-okay",
				"mbd_action_activate": "mbd-success",
				"mbd_action_pca": "mbd-success",
				"mbd_action_deactivate": "mbd-warning",
				"mbd_action_remove": "mbd-error",
			};

			container.find('option:gt(0)').each(function () {
				$('<button>')
					.appendTo(buttons)
					.attr('id', this.value.replace(/_/g, "-"))  // mbd-action-<foo>
					.attr('name', this.value)
					.addClass(cssmap[this.value])
					.text(this.text)
					.click(function () {
						container.find('select')
							.find(':selected').attr('selected', '').end()
							.find('[value=' + this.name + ']').attr('selected', 'selected');
						$('#changelist-form button[name="index"]').click();
					});
			});
		}
	};

	$(function () {
		fix_actions();
	});

</script>
{% endif %}{% endif %}
{% endblock %}
