Proyectos de Subversion Moodle

Rev

Rev 1226 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1226 Rev 1227
Línea 34... Línea 34...
34
    'input[type="checkbox"][data-togglegroup="report-select-all"][data-toggle="slave"]',
34
    'input[type="checkbox"][data-togglegroup="report-select-all"][data-toggle="slave"]',
35
  masterCheckbox:
35
  masterCheckbox:
36
    'input[type="checkbox"][data-togglegroup="report-select-all"][data-toggle="master"]',
36
    'input[type="checkbox"][data-togglegroup="report-select-all"][data-toggle="master"]',
37
  checkedRows:
37
  checkedRows:
38
    '[data-togglegroup="report-select-all"][data-toggle="slave"]:checked',
38
    '[data-togglegroup="report-select-all"][data-toggle="slave"]:checked',
39
  filtersForm: 'form#filters-form', // Seleccionamos el formulario de filtros
-
 
40
};
39
};
Línea 41... Línea 40...
41
 
40
 
42
/**
-
 
43
 * Función para resetear los filtros
-
 
44
 */
-
 
45
const resetFilters = () => {
-
 
46
  const filterForm = document.querySelector(Selectors.filtersForm); // Asegúrate de que el selector coincide con los filtros
-
 
47
  if (!filterForm) return;
-
 
48
 
-
 
49
  // Crear un objeto FormData que contendrá todos los valores del formulario
-
 
50
  const formData = new FormData(filterForm);
-
 
51
  
-
 
52
  // Iterar sobre cada elemento de input en el formulario
-
 
53
  filterForm.querySelectorAll("input, select").forEach((element) => {
-
 
54
    if (element.type === "checkbox" || element.type === "radio") {
-
 
55
      // Si es un checkbox o radio, desmarcarlo
-
 
56
      element.checked = false;
-
 
57
    } else {
-
 
58
      // Si es un input de texto o select, limpiar el valor
-
 
59
      element.value = "";
-
 
60
    }
-
 
61
 
-
 
62
    // Opcional: para asegurarse de que los valores del FormData también se reseteen
-
 
63
    formData.set(element.name, ""); 
-
 
64
  });
-
 
65
 
-
 
66
  // Si hay algún elemento select, deseleccionar la opción seleccionada
-
 
67
  filterForm.querySelectorAll("select").forEach((select) => {
-
 
68
    select.selectedIndex = -1; // Deseleccionar la opción seleccionada
-
 
69
  });
-
 
70
};
-
 
71
 
-
 
72
/**
41
/**
73
 * Initialize module
42
 * Initialise module
74
 */
43
 */
75
export const init = () => {
44
export const init = () => {
76
  const userBulkForm = document.querySelector(Selectors.bulkActionsForm);
45
  const userBulkForm = document.querySelector(Selectors.bulkActionsForm);
77
  const userReport = userBulkForm
46
  const userReport = userBulkForm
Línea 92... Línea 61...
92
        userBulkForm.submit();
61
        userBulkForm.submit();
93
      }
62
      }
94
    }
63
    }
95
  });
64
  });
Línea 96... Línea 65...
96
 
65
 
97
  // Cada vez que los checkboxes en el informe cambien, actualizamos la lista de usuarios en los valores del formulario
66
  // Every time the checkboxes in the report are changed, update the list of users in the form values
98
  // y habilitamos/deshabilitamos el select de acciones.
67
  // and enable/disable the action select.
99
  const updateUserIds = () => {
68
  const updateUserIds = () => {
100
    const selectedUsers = [
69
    const selectedUsers = [
101
      ...userReport.querySelectorAll(Selectors.checkedRows),
70
      ...userReport.querySelectorAll(Selectors.checkedRows),
102
    ];
71
    ];
103
    const selectedUserIds = selectedUsers.map((check) => parseInt(check.value));
72
    const selectedUserIds = selectedUsers.map((check) => parseInt(check.value));
104
    userBulkForm.querySelector('[name="userids"]').value =
73
    userBulkForm.querySelector('[name="userids"]').value =
Línea 105... Línea 74...
105
      selectedUserIds.join(",");
74
      selectedUserIds.join(",");
106
 
75
 
107
    // Deshabilitar el selector de acción si no se seleccionan usuarios, y resetear la selección actual.
76
    // Disable the action selector if nothing selected, and reset the current selection.
108
    actionSelect.disabled = selectedUsers.length === 0;
77
    actionSelect.disabled = selectedUsers.length === 0;
109
    if (actionSelect.disabled) {
78
    if (actionSelect.disabled) {
Línea 110... Línea 79...
110
      actionSelect.value = "0";
79
      actionSelect.value = "0";
111
    }
80
    }
112
 
81
 
113
    const selectedUsersNames = selectedUsers.map(
82
    const selectedUsersNames = selectedUsers.map(
114
      (check) => document.querySelector(`label[for="${check.id}"]`).textContent
83
      (check) => document.querySelector(`label[for="${check.id}"]`).textContent
115
    );
84
    );
116
    // Agregar los ids y nombres de los usuarios a los atributos de datos del formulario para que estén disponibles desde
85
    // Add the user ids and names to the form data attributes so they can be available from the
117
    // otros módulos JS que escuchen el evento de submit del formulario.
86
    // other JS modules that listen to the form submit event.
118
    userBulkForm.data = {
87
    userBulkForm.data = {
119
      userids: selectedUserIds,
88
      userids: selectedUserIds,
Línea 120... Línea 89...
120
      usernames: selectedUsersNames,
89
      usernames: selectedUsersNames,
Línea 121... Línea 90...
121
    };
90
    };
122
  };
91
  };
123
 
92
 
124
  updateUserIds();
93
  updateUserIds();
125
 
94
 
126
  document.addEventListener("change", (event) => {
95
  document.addEventListener("change", (event) => {
127
    // Cuando los checkboxes son marcados junto a usuarios individuales o el toggle maestro (Seleccionar todo/nada).
96
    // When checkboxes are checked next to individual users or the master toggle (Select all/none).
128
    if (
97
    if (
129
      (event.target.matches(Selectors.checkbox) ||
98
      (event.target.matches(Selectors.checkbox) ||
130
        event.target.matches(Selectors.masterCheckbox)) &&
99
        event.target.matches(Selectors.masterCheckbox)) &&
Línea 131... Línea 100...
131
      userReport.contains(event.target)
100
      userReport.contains(event.target)
132
    ) {
101
    ) {
133
      updateUserIds();
102
      updateUserIds();
134
    }
103
    }
135
  });
-
 
136
 
104
  });
137
  document.addEventListener(tableEvents.tableContentRefreshed, (event) => {
105
 
138
    // Cuando el contenido del informe se actualiza (es decir, se cambia la página, se aplican filtros, etc.).
106
  document.addEventListener(tableEvents.tableContentRefreshed, (event) => {