{"version":3,"file":"list_item_controller-C85mjncb.js","sources":["../../../app/javascript/controllers/channels/list_item_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\nimport {get} from \"@rails/request.js\";\n\nexport default class extends Controller {\n static values = {\n selectUrl: String,\n deselectUrl: String\n }\n\n connect() {\n if(document.querySelectorAll(\"[data-selected]\").length > 0) {\n this.dispatch(\"enableSubmit\")\n } else {\n this.dispatch(\"disableSubmit\")\n }\n }\n\n async select() {\n // if the user selects multiple channels and this request has not been finished\n // UI would end up in an inconsistent state.\n // Treat this item as selected before making the request\n this.element.setAttribute(\"data-selected\", \"\")\n\n let query = {\n selected_ids: Array.from(document.querySelectorAll(\"[data-selected]\"))\n .map(listItem => listItem.dataset.recordId),\n selected_count: document.querySelectorAll(\"[data-selected]\").length\n }\n\n if(document.querySelector(\"input[type='hidden'][name='quota_full']\")) {\n query.quota_full = 1\n }\n\n get(this.selectUrlValue, {\n responseKind: \"turbo-stream\",\n query,\n }).catch(() => {\n this.element.removeAttribute(\"data-selected\")\n })\n }\n\n async deselect() {\n // if the user deselects multiple channels and this request has not been finished\n // UI would end up in an inconsistent state.\n // Treat this item as deselected before making the request\n this.element.removeAttribute(\"data-selected\")\n\n get(this.deselectUrlValue, {\n responseKind: \"turbo-stream\",\n query: {\n selected_ids: Array.from(document.querySelectorAll(\"[data-selected]\"))\n .map(listItem => listItem.dataset.recordId)\n }\n }).catch(() => {\n this.element.setAttribute(\"data-selected\", \"\")\n })\n }\n}\n"],"names":["list_item_controller","Controller","query","listItem","get","__publicField"],"mappings":"+PAGe,MAAKA,UAASC,CAAW,CAMtC,SAAU,CACL,SAAS,iBAAiB,iBAAiB,EAAE,OAAS,EACvD,KAAK,SAAS,cAAc,EAE5B,KAAK,SAAS,eAAe,CAEnC,CAEE,MAAM,QAAS,CAIb,KAAK,QAAQ,aAAa,gBAAiB,EAAE,EAE7C,IAAIC,EAAQ,CACV,aAAc,MAAM,KAAK,SAAS,iBAAiB,iBAAiB,CAAC,EAClE,IAAIC,GAAYA,EAAS,QAAQ,QAAQ,EAC5C,eAAgB,SAAS,iBAAiB,iBAAiB,EAAE,MACnE,EAEO,SAAS,cAAc,yCAAyC,IACjED,EAAM,WAAa,GAGrBE,EAAI,KAAK,eAAgB,CACvB,aAAc,eACd,MAAAF,CACN,CAAK,EAAE,MAAM,IAAM,CACb,KAAK,QAAQ,gBAAgB,eAAe,CAC7C,CAAA,CACL,CAEE,MAAM,UAAW,CAIf,KAAK,QAAQ,gBAAgB,eAAe,EAE5CE,EAAI,KAAK,iBAAkB,CACzB,aAAc,eACd,MAAO,CACL,aAAc,MAAM,KAAK,SAAS,iBAAiB,iBAAiB,CAAC,EAClE,IAAID,GAAYA,EAAS,QAAQ,QAAQ,CACpD,CACA,CAAK,EAAE,MAAM,IAAM,CACb,KAAK,QAAQ,aAAa,gBAAiB,EAAE,CAC9C,CAAA,CACL,CACA,CArDEE,EADkBL,EACX,SAAS,CACd,UAAW,OACX,YAAa,MACjB"}