소스 검색

#6372: Fix bulk form action form handling

checktheroads 4 년 전
부모
커밋
cdc9753009
3개의 변경된 파일35개의 추가작업 그리고 2개의 파일을 삭제
  1. 0 0
      netbox/project-static/dist/netbox.js
  2. 0 0
      netbox/project-static/dist/netbox.js.map
  3. 35 2
      netbox/project-static/src/forms.ts

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
netbox/project-static/dist/netbox.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
netbox/project-static/dist/netbox.js.map


+ 35 - 2
netbox/project-static/src/forms.ts

@@ -1,10 +1,37 @@
-import { getElements, scrollTo } from './util';
+import { getElements, scrollTo, findFirstAdjacent, isTruthy } from './util';
 
 type ShowHideMap = {
   default: { hide: string[]; show: string[] };
   [k: string]: { hide: string[]; show: string[] };
 };
 
+/**
+ * Handle bulk add/edit/rename form actions.
+ *
+ * @param event Click Event
+ */
+function handleFormActionClick(event: Event): void {
+  event.preventDefault();
+  const element = event.currentTarget as HTMLElement;
+  if (element !== null) {
+    const form = findFirstAdjacent<HTMLFormElement>(element, 'form');
+    const href = element.getAttribute('href');
+    if (form !== null && isTruthy(href)) {
+      form.setAttribute('action', href);
+      form.submit();
+    }
+  }
+}
+
+/**
+ * Initialize bulk form action links.
+ */
+function initFormActions() {
+  for (const element of getElements<HTMLAnchorElement>('a.formaction')) {
+    element.addEventListener('click', handleFormActionClick);
+  }
+}
+
 /**
  * Get form data from a form element and transform it into a body usable by fetch.
  *
@@ -264,7 +291,13 @@ function initScopeSelector() {
 }
 
 export function initForms() {
-  for (const func of [initFormElements, initMoveButtons, initSpeedSelector, initScopeSelector]) {
+  for (const func of [
+    initFormElements,
+    initFormActions,
+    initMoveButtons,
+    initSpeedSelector,
+    initScopeSelector,
+  ]) {
     func();
   }
 }

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.