actions.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var AdminModelActions = function(actionErrorMessage, actionConfirmations) {
  2. // Actions helpers. TODO: Move to separate file
  3. this.execute = function(name) {
  4. var selected = $('input.action-checkbox:checked').size();
  5. if (selected === 0) {
  6. alert(actionErrorMessage);
  7. return false;
  8. }
  9. var msg = actionConfirmations[name];
  10. if (!!msg)
  11. if (!confirm(msg))
  12. return false;
  13. // Update hidden form and submit it
  14. var form = $('#action_form');
  15. $('#action', form).val(name);
  16. $('input.action-checkbox', form).remove();
  17. $('input.action-checkbox:checked').each(function() {
  18. form.append($(this).clone());
  19. });
  20. form.submit();
  21. return false;
  22. };
  23. $(function() {
  24. $('.action-rowtoggle').change(function() {
  25. $('input.action-checkbox').prop('checked', this.checked);
  26. });
  27. });
  28. $(function() {
  29. var inputs = $('input.action-checkbox');
  30. inputs.change(function() {
  31. var allInputsChecked = true;
  32. for (var i = 0; i < inputs.length; i++) {
  33. if (!inputs[i].checked) {
  34. allInputsChecked = false;
  35. break;
  36. }
  37. }
  38. $('.action-rowtoggle').attr('checked', allInputsChecked);
  39. });
  40. });
  41. };