PageSourceSearch

https://cloud.mysteryscience.com/raw/upload/assets/controllers/adm…0ea106a78e99b031b7bff15a436db7bdef2e5160.js

js mysteryscience.com collected 2026-09-24 09:22:47 UTC 5,573 bytes, 1 lines download raw bytes

1import{Controller}from"@hotwired/stimulus";import{debounce}from"helpers/timing_helpers";import{get,post}from"@rails/request.js";import{AccountSearchable}from"helpers/account_searchable";const PREVIEW_AUTO_UPDATE_EXCLUDED_PARAMS=["source_sales_team","renewal_sales_team","organization_search","creator_search"],DISCOUNT_PANEL_RESET_PARAMS=["product","account_id","sales_year"];export default class extends(AccountSearchable(Controller)){static targets=["input","results","accountId","accountType","creatorInput","creatorResults","creatorId","quantityInput","quantityTotal","formErrors"];static values={searchUrl:String,selectUrl:String,previewUrl:String,userSearchUrl:String,selectCreatorUrl:String,resetPreviewUrl:String,accountTypeUrl:String,accountType:{type:String,default:"school"}};connect(){super.connect(),this.debouncedCreatorSearch=debounce(this.performCreatorSearch.bind(this),300),this.debouncedAutoPreview=debounce(this.autoPreview.bind(this),300),this.boundPreventEnterSubmit=this.preventEnterSubmit.bind(this),this.element.addEventListener("keydown",this.boundPreventEnterSubmit),this.boundValidateOnSubmit=this.validateOnSubmit.bind(this),this.element.addEventListener("submit",this.boundValidateOnSubmit),this.boundHandleFormChange=this.handleFormChange.bind(this),this.element.addEventListener("change",this.boundHandleFormChange),this.element.addEventListener("input",this.boundHandleFormChange);const e=this.hasAccountIdTarget?this.accountIdTarget.value:"",t=this.element.querySelector('[name="product"]')?.value;e&&t&&this.autoPreview()}disconnect(){this.element.removeEventListener("keydown",this.boundPreventEnterSubmit),this.element.removeEventListener("submit",this.boundValidateOnSubmit),this.element.removeEventListener("change",this.boundHandleFormChange),this.element.removeEventListener("input",this.boundHandleFormChange)}preventEnterSubmit(e){if("Enter"!==e.key)return;"submit"===e.target.type||e.preventDefault()}handleFormChange(e){if(PREVIEW_AUTO_UPDATE_EXCLUDED_PARAMS.includes(e.target.id))return;if(DISCOUNT_PANEL_RESET_PARAMS.includes(e.target.name)){const e=document.getElementById("discount-options");e&&(e.innerHTML="")}(this.hasAccountIdTarget?this.accountIdTarget.value:"")&&this.debouncedAutoPreview()}autoPreview(){if(!(this.hasAccountIdTarget?this.accountIdTarget.value:""))return void this.resetPreview();const e=new FormData(this.element);e.delete("_method"),post(this.previewUrlValue,{body:e,responseKind:"turbo-stream"})}resetPreview(){get(this.resetPreviewUrlValue,{responseKind:"turbo-stream"})}extraSelectParams(){return{product:this.element.querySelector('[name="product"]')?.value||""}}afterAccountSelected(){this.debouncedAutoPreview()}afterSelectionCleared(){const e=document.getElementById("selected-organization");e&&(e.innerHTML="");const t=document.getElementById("js-org-roles-partial");t&&(t.innerHTML="");const r=document.getElementById("js-org-roles-description");r&&(r.textContent="Select an organization above to see their roles.");const n=document.getElementById("segment_type_field");n&&(n.value="");const a=document.getElementById("quantity-fields");a&&(a.innerHTML=""),this.resetPreview()}searchCreator(){this.debouncedCreatorSearch()}performCreatorSearch(){if(!this.hasCreatorInputTarget)return;const e=this.creatorInputTarget.value.trim();if(e.length<2)return void this.clearCreatorResults();const t=this.userSearchUrlValue.replace(":query",encodeURIComponent(e)),r=this.hasAccountIdTarget?this.accountIdTarget.value:"",n=this.accountTypeValue,a=new URLSearchParams;r&&a.append("account_id",r),n&&a.append("account_type",n),get(`${t}?${a}`,{responseKind:"turbo-stream"})}async selectCreator(e){const t=e.currentTarget.dataset.userId;await get(`${this.selectCreatorUrlValue}?user_id=${t}`,{responseKind:"turbo-stream"}),this.hasCreatorInputTarget&&(this.creatorInputTarget.value=""),this.clearCreatorResults()}clearCreator(e){e.preventDefault(),this.hasCreatorIdTarget&&(this.creatorIdTarget.value="");const t=document.getElementById("selected-creator");t&&(t.innerHTML=""),this.hasCreatorInputTarget&&this.creatorInputTarget.focu
1s()}clearCreatorResults(){this.hasCreatorResultsTarget&&(this.creatorResultsTarget.innerHTML="")}updateQuantityTotal(){if(!this.hasQuantityTotalTarget)return;const e=this.quantityInputTargets.reduce((e,t)=>e+(parseInt(t.value,10)||0),0);this.quantityTotalTarget.value=e}quantityTotalTargetConnected(){this.updateQuantityTotal()}quantityInputTargetConnected(e){e.addEventListener("wheel",this.preventWheelChange,{passive:!1})}quantityInputTargetDisconnected(e){e.removeEventListener("wheel",this.preventWheelChange,{passive:!1})}preventWheelChange(e){e.preventDefault()}validateOnSubmit(e){const t=[];(this.hasAccountIdTarget?this.accountIdTarget.value:"")||t.push("Select an organization.");(this.hasCreatorIdTarget?this.creatorIdTarget.value:"")||t.push("Select a creator.");const r=this.element.querySelector('[name="product"]')?.value;r||t.push("Choose a product."),this.hasQuantityTotalTarget&&0===parseInt(this.quantityTotalTarget.value,10)&&t.push("At least one school quantity (Standard, Small, or Micro) must be greater than zero."),0!==t.length?(e.preventDefault(),this.showFormErrors(t)):this.clearFormErrors()}showFormErrors(e){this.hasFormErrorsTarget&&(this.formErrorsTarget.innerHTML=e.map(e=>`<li>${e}</li>`).join(""),this.formErrorsTarget.style.display="",this.formErrorsTarget.scrollIntoView({behavior:"smooth",block:"center"}))}clearFormErrors(){this.hasFormErrorsTarget&&(this.formErrorsTarget.innerHTML="",this.formErrorsTarget.style.display="none")}}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.