diff --git a/shimatta_kenkyusho/parts/models.py b/shimatta_kenkyusho/parts/models.py index 0c317b4..cb19175 100644 --- a/shimatta_kenkyusho/parts/models.py +++ b/shimatta_kenkyusho/parts/models.py @@ -85,7 +85,10 @@ class Storage(models.Model): if Storage.objects.exclude(id=self.id).filter(name=self.name, parent_storage__isnull=True).exists(): if self.parent_storage is None: raise ValidationError('The fields name, parent_storage must make a unique set') - super(Storage, self).validate_unique(exclude) + try: + super(Storage, self).validate_unique(exclude) + except: + raise def get_total_stock_amount(self): stocks = Stock.objects.filter(storage=self) diff --git a/shimatta_kenkyusho/parts/views.py b/shimatta_kenkyusho/parts/views.py index bf3fe68..bcf8e89 100644 --- a/shimatta_kenkyusho/parts/views.py +++ b/shimatta_kenkyusho/parts/views.py @@ -100,6 +100,10 @@ class ComponentView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): base_title = 'Components' navbar_selected = 'Components' +class AddSubStorageForm(forms.Form): + storage_name = forms.CharField(label="storage_name", initial='') + responsible = forms.CharField(label='responsible_user') + class StockView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): template_name = 'parts/stocks.html' base_title = 'Stocks' @@ -122,13 +126,45 @@ class StockView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): context['low_stocks'] = low_stock_paginator.get_page(low_stock_page) context['storages'] = storage_paginator.get_page(storage_page) - + add_stor_form = AddSubStorageForm() + add_stor_form.fields['responsible'].initial = self.request.user.username + context['add_storage_form'] = add_stor_form return context - -class AddSubStorageForm(forms.Form): - storage_name = forms.CharField(label="storage_name", initial='') - responsible = forms.CharField(label='responsible_user') + def handle_add_storage(self, request, **kwargs): + return_invalid_form = False + + f = AddSubStorageForm(data=request.POST) + if f.is_valid(): + new_storage_name = f.cleaned_data['storage_name'] + try: + resp_user = User.objects.get(username=f.cleaned_data['responsible']) + except Exception as _: + resp_user = None + f.add_error('responsible', 'Invalid Responsible User') + return_invalid_form = True + + if resp_user is not None: + try: + Storage.objects.create(name=new_storage_name, responsible=resp_user, parent_storage=None) + except ValidationError as verr: + return_invalid_form = True + f.add_error('storage_name', ' .'.join(verr.messages)) + else: + return_invalid_form = True + + context = self.get_context_data(**kwargs) + if return_invalid_form: + context['add_storage_form'] = f + + return self.render_to_response(context) + + def post(self, request, **kwargs): + if 'submit-add-storage' in request.POST: + return self.handle_add_storage(request, **kwargs) + + return super().post(request, **kwargs) + class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView): template_name = 'parts/stocks-detail.html' model = Storage @@ -157,6 +193,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView): add_storage_form = AddSubStorageForm() add_storage_form.fields['responsible'].initial = self.request.user.username context['add_storage_form'] = add_storage_form + context['delete_storage_error'] = None return context def handle_add_storage_post(self, request, **kwargs): @@ -175,10 +212,26 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView): context['add_storage_form'] = f return self.render_to_response(context) + def handle_del_storage_post(self, request, **kwargs): + parent = self.object.parent_storage + try: + self.object.delete() + except: + context = self.get_context_data(**kwargs) + context['delete_storage_errors'] = ['Error deleting Storage '+str(self.object)] + return self.render_to_response(context) + + if parent is None: + return redirect('parts-stocks') + else: + return redirect(reverse('parts-stocks-detail', kwargs={'uuid':parent.id})) + def post(self, request, *args, **kwargs): self.object = self.get_object() if 'submit-add-storage' in request.POST: - return self.handle_add_storage_post(request) + return self.handle_add_storage_post(request, **kwargs) + elif 'submit-delete-storage' in request.POST: + return self.handle_del_storage_post(request, **kwargs) return super().post(request, *args, **kwargs) \ No newline at end of file diff --git a/shimatta_kenkyusho/static/css/autocomplete.css b/shimatta_kenkyusho/static/css/autocomplete.css new file mode 100644 index 0000000..904ca6d --- /dev/null +++ b/shimatta_kenkyusho/static/css/autocomplete.css @@ -0,0 +1 @@ +:root{--close-button:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M18.984 6.422 13.406 12l5.578 5.578-1.406 1.406L12 13.406l-5.578 5.578-1.406-1.406L10.594 12 5.016 6.422l1.406-1.406L12 10.594l5.578-5.578z'/%3E%3C/svg%3E");--loupe-icon:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23929292' d='M16.041 15.856a.995.995 0 0 0-.186.186A6.97 6.97 0 0 1 11 18c-1.933 0-3.682-.782-4.95-2.05S4 12.933 4 11s.782-3.682 2.05-4.95S9.067 4 11 4s3.682.782 4.95 2.05S18 9.067 18 11a6.971 6.971 0 0 1-1.959 4.856zm5.666 4.437-3.675-3.675A8.967 8.967 0 0 0 20 11c0-2.485-1.008-4.736-2.636-6.364S13.485 2 11 2 6.264 3.008 4.636 4.636 2 8.515 2 11s1.008 4.736 2.636 6.364S8.515 20 11 20a8.967 8.967 0 0 0 5.618-1.968l3.675 3.675a.999.999 0 1 0 1.414-1.414z'/%3E%3C/svg%3E")}.auto-search{display:block;position:relative;width:100%}.auto-search input{border:1px solid #d7d7d7;box-shadow:none;box-sizing:border-box;font-size:16px;padding:12px 45px 12px 10px;width:100%}.auto-search input:focus{border:1px solid #858585;outline:none}.auto-search input::-ms-clear{display:none}.auto-search ul{box-sizing:border-box;list-style:none;overflow:auto;padding:0}.auto-search ul li{cursor:pointer;margin:0;overflow:hidden;padding:10px;position:relative}.auto-search ul li:not(:last-child){border-top:none}.auto-search ul li[disabled]{background:#ececec;opacity:.5;pointer-events:none}.auto-search .auto-expanded{border:1px solid #858585;outline:none}.auto-search.loupe:before{filter:invert(60%)}.auto-is-loading:after{animation:auto-spinner .6s linear infinite;border-color:#d9d9d9 grey grey #d9d9d9;border-radius:50%;border-style:solid;border-width:2px;bottom:0;box-sizing:border-box;content:"";height:20px;margin:auto;position:absolute;right:10px;top:0;width:20px}.auto-is-loading .auto-clear{display:none}@keyframes auto-spinner{to{transform:rotate(1turn)}}li.loupe:before{bottom:auto;top:15px}.loupe input{padding:12px 45px 12px 40px}.loupe:before{background-image:var(--loupe-icon);bottom:0;content:"";height:17px;left:10px;margin:auto;position:absolute;top:0;width:17px}.auto-selected:before{opacity:1}.auto-clear{align-items:center;background-color:transparent;border:none;bottom:0;cursor:pointer;display:flex;height:auto;justify-content:center;margin:auto;position:absolute;right:0;top:0;width:40px}.auto-clear:before{content:var(--close-button);height:24px;line-height:100%;width:24px}.auto-clear span{display:none}.auto-wrapper{background-color:#fff;border:1px solid #858585;border-top:none;display:none;overflow:hidden}.auto-wrapper ul>.loupe{padding-left:40px}.auto-wrapper.auto-is-active{display:block;margin-top:-1px;position:absolute;width:100%;z-index:99999}.auto-selected{background-color:#e6e6e6}.auto-selected+li:before{border-top:none}.auto-error{border:1px solid #ff3838}.auto-error::placeholder{color:#f66;opacity:1}.hidden{display:none} \ No newline at end of file diff --git a/shimatta_kenkyusho/static/js/autocomplete.min.js b/shimatta_kenkyusho/static/js/autocomplete.min.js new file mode 100644 index 0000000..a0cad09 --- /dev/null +++ b/shimatta_kenkyusho/static/js/autocomplete.min.js @@ -0,0 +1 @@ +var Autocomplete=function(){"use strict";function t(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}return class{constructor(e,{delay:s=500,clearButton:i=!0,howManyCharacters:h=1,selectFirst:r=!1,insertToInput:o=!1,showAllValues:l=!1,cache:n=!1,disableCloseOnSelect:a=!1,classGroup:c,classPreventClosing:d,classPrefix:u,onSearch:p,onResults:m=(()=>{}),onSubmit:L=(()=>{}),onOpened:v=(()=>{}),onReset:f=(()=>{}),onRender:x=(()=>{}),onClose:A=(()=>{}),noResults:g=(()=>{}),onSelectedItem:b=(()=>{})}){var T;t(this,"init",()=>{const t=this.root;this.clearbutton(),this.output(),t.addEventListener("input",this.handleInput),this.showAll&&t.addEventListener("click",this.handleInput),this.onRender({element:t,results:this.resultList})}),t(this,"cacheAct",(t,e)=>{const s=this.root;this.cache&&("update"===t?s.setAttribute(this.cacheData,e.value):"remove"===t?s.removeAttribute(this.cacheData):s.value=s.getAttribute(this.cacheData))}),t(this,"handleInput",({target:t,type:e})=>{if("true"===this.root.getAttribute("aria-expanded")&&"click"===e)return;const s=t.value.replace(this.regex,"\\$&");if(this.cacheAct("update",t),this.showAll&&"click"===e)return this.reset(),void this.searchItem(s.trim());clearTimeout(this.timeout),this.timeout=setTimeout(()=>{this.searchItem(s.trim())},this.delay)}),t(this,"output",()=>{this.setAttr(this.resultList,{id:this.outputUl,tabIndex:"0",role:"listbox"}),this.setAttr(this.resultWrap,{addClass:this.prefix+"-wrapper"}),this.resultWrap.insertAdjacentElement("beforeend",this.resultList),this.root.parentNode.insertBefore(this.resultWrap,this.root.nextSibling)}),t(this,"reset",()=>{var t;this.setAttr(this.root,{"aria-owns":this.id+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),this.resultWrap.classList.remove(this.isActive),this.scrollResultsToTop(),(0==(null===(t=this.matches)||void 0===t?void 0:t.length)&&!this.toInput||this.showAll)&&(this.resultList.innerHTML=""),this.index=this.selectFirst?0:-1,this.onClose()}),t(this,"scrollResultsToTop",()=>{this.resultList.scrollTop=this.resultList.offsetTop-this.resultWrap.offsetHeight}),t(this,"searchItem",t=>{this.value=t,this.onLoading(!0),this.showBtn(),0==t.length&&this.clearButton&&this.cBtn.classList.add("hidden"),this.characters>t.length&&!this.showAll?this.onLoading():this.onSearch({currentValue:t,element:this.root}).then(e=>{const s=this.root.value.length,i=e.length;this.matches=Array.isArray(e)?[...e]:JSON.parse(JSON.stringify(e)),this.onLoading(),this.error(),0==i&&0==s&&this.cBtn.classList.add("hidden"),0==i&&s?(this.root.classList.remove("auto-expanded"),this.reset(),this.noResults({element:this.root,currentValue:t,template:this.results}),this.events()):(i>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(e))&&(this.index=this.selectFirst?0:-1,this.results(),this.events())}).catch(()=>{this.onLoading(),this.reset()})}),t(this,"onLoading",t=>this.root.parentNode.classList[t?"add":"remove"](this.isLoading)),t(this,"error",()=>this.root.classList.remove(this.err)),t(this,"events",()=>{this.root.addEventListener("keydown",this.handleKeys),this.root.addEventListener("click",this.handleShowItems),["mousemove","click"].map(t=>{this.resultList.addEventListener(t,this.handleMouse)}),document.addEventListener("click",this.handleDocClick)}),t(this,"results",t=>{this.setAttr(this.root,{"aria-expanded":"true",addClass:this.prefix+"-expanded"}),this.resultList.innerHTML=0===this.matches.length?this.onResults({currentValue:this.value,matches:0,template:t}):this.onResults({currentValue:this.value,matches:this.matches,classGroup:this.classGroup}),this.resultWrap.classList.add(this.isActive),this.scrollResultsToTop();const e=this.classGroup?`:not(.${this.classGroup})`:"";this.itemsLi=document.querySelectorAll(`#${this.outputUl} > li${e}`),this.selectFirstEl(),this.onOpened({type:"results",element:this.root,results:this.resultList}),this.addAria()}),t(this,"handleDocClick",({target:t})=>{let e=null;(t.closest("ul")&&this.disable||t.closest("."+this.prevClosing))&&(e=!0),t.id===this.id||e||this.reset()}),t(this,"addAria",()=>{for(let t=0;t{if(this.remAria(document.querySelector("."+this.activeList)),!this.selectFirst)return;const{firstElementChild:t}=this.resultList,e=this.classGroup&&this.matches.length>0&&this.selectFirst?t.nextElementSibling:t;this.setAttr(e,{id:this.selectedOption+"-0",addClass:this.activeList,"aria-selected":"true"}),this.setAriaDes(this.selectedOption+"-0"),this.follow(t)}),t(this,"showBtn",()=>{this.cBtn&&(this.cBtn.classList.remove("hidden"),this.cBtn.addEventListener("click",this.destroy))}),t(this,"setAttr",(t,e)=>{for(let s in e)"addClass"===s?t.classList.add(e[s]):"removeClass"===s?t.classList.remove(e[s]):t.setAttribute(s,e[s])}),t(this,"handleShowItems",()=>{const t=this.resultWrap;this.resultList.textContent.length>0&&!t.classList.contains(this.isActive)&&(this.setAttr(this.root,{"aria-expanded":"true",addClass:this.prefix+"-expanded"}),t.classList.add(this.isActive),this.scrollResultsToTop(),this.selectFirstEl(),this.onOpened({type:"showItems",element:this.root,results:this.resultList}))}),t(this,"handleMouse",t=>{t.preventDefault();const{target:e,type:s}=t,i=e.closest("li"),h=null==i?void 0:i.hasAttribute("role"),r=this.activeList,o=document.querySelector("."+r);i&&h&&("click"===s&&this.getTextFromLi(i),"mousemove"!==s||i.classList.contains(r)||(this.remAria(o),this.setAria(i),this.index=this.indexLiSelected(i),this.onSelected({index:this.index,element:this.root,object:this.matches[this.index]})))}),t(this,"getTextFromLi",t=>{t&&0!==this.matches.length?(this.addToInput(t),this.onSubmit({index:this.index,element:this.root,object:this.matches[this.index],results:this.resultList}),this.disable||(this.remAria(t),this.reset()),this.clearButton&&this.cBtn.classList.remove("hidden"),this.cacheAct("remove")):!this.disable&&this.reset()}),t(this,"firstElement",t=>t.firstElementChild||t),t(this,"addToInput",t=>{this.root.value=this.firstElement(t).textContent.trim()}),t(this,"indexLiSelected",t=>Array.prototype.indexOf.call(this.itemsLi,t)),t(this,"handleKeys",t=>{const e=this.keyCodes,{keyCode:s}=t,i=this.resultWrap.classList.contains(this.isActive),h=this.matches.length+1;switch(this.selectedLi=document.querySelector("."+this.activeList),s){case e.UP:case e.DOWN:if(t.preventDefault(),h<=1&&this.selectFirst||!i)return;s===e.UP?(this.index<0&&(this.index=h-1),this.index-=1):(this.index+=1,this.index>=h&&(this.index=0)),this.remAria(this.selectedLi),h>0&&this.index>=0&&this.index{const e=`${this.selectedOption}-${this.indexLiSelected(t)}`;this.setAttr(t,{id:e,"aria-selected":"true",addClass:this.activeList}),this.setAriaDes(e),this.follow(t)}),t(this,"getClassGroupHeight",()=>{const t=document.querySelectorAll(`#${this.outputUl} > li:not(.${this.classGroup})`);let e=0;return[].slice.call(t).map(t=>e+=t.offsetHeight),e}),t(this,"follow",t=>{const e=this.resultList,s=e.previousSibling,i=s?s.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(e.scrollTop=t.offsetTop-this.getClassGroupHeight()),t.offsetTop-ie.scrollTop+e.offsetHeight&&(e.scrollTop=s-e.offsetHeight)}}),t(this,"remAria",t=>{t&&this.setAttr(t,{id:"",removeClass:this.activeList,"aria-selected":"false"})}),t(this,"setAriaDes",t=>this.root.setAttribute("aria-activedescendant",t||"")),t(this,"clearbutton",()=>{this.clearButton&&(this.setAttr(this.cBtn,{class:this.prefix+"-clear hidden",type:"button","aria-label":"claar text from input"}),this.root.insertAdjacentElement("afterend",this.cBtn))}),t(this,"destroy",()=>{this.clearButton&&this.cBtn.classList.add("hidden"),this.root.value="",this.root.focus(),this.resultList.textContent="",this.reset(),this.error(),this.onReset(this.root),this.root.removeEventListener("keydown",this.handleKeys),this.root.removeEventListener("click",this.handleShowItems),document.removeEventListener("click",this.handleDocClick)}),this.id=e,this.root=document.getElementById(this.id),this.onSearch=(T=p,Boolean(T&&"function"==typeof T.then)?p:({currentValue:t,element:e})=>Promise.resolve(p({currentValue:t,element:e}))),this.onResults=m,this.onRender=x,this.onSubmit=L,this.onSelected=b,this.onOpened=v,this.onReset=f,this.noResults=g,this.onClose=A,this.delay=s,this.characters=h,this.clearButton=i,this.selectFirst=r,this.toInput=o,this.showAll=l,this.classGroup=c,this.prevClosing=d,this.prefix=u?u+"-auto":"auto",this.disable=a,this.cache=n,this.outputUl=`${this.prefix}-${this.id}-results`,this.cacheData="data-cache-auto-"+this.id,this.isLoading=this.prefix+"-is-loading",this.isActive=this.prefix+"-is-active",this.activeList=this.prefix+"-selected",this.selectedOption=this.prefix+"-selected-option",this.err=this.prefix+"-error",this.regex=/[|\\{}()[\]^$+*?.]/g,this.timeout=null,this.resultWrap=document.createElement("div"),this.resultList=document.createElement("ul"),this.cBtn=document.createElement("button"),this.keyCodes={ESC:27,ENTER:13,UP:38,DOWN:40,TAB:9},this.init()}}}(); diff --git a/shimatta_kenkyusho/static/js/autocomplete.umd.min.js b/shimatta_kenkyusho/static/js/autocomplete.umd.min.js new file mode 100644 index 0000000..e702731 --- /dev/null +++ b/shimatta_kenkyusho/static/js/autocomplete.umd.min.js @@ -0,0 +1 @@ +var t,e;t=this,e=function(){function t(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}return class{constructor(e,{delay:s=500,clearButton:i=!0,howManyCharacters:h=1,selectFirst:r=!1,insertToInput:o=!1,showAllValues:l=!1,cache:n=!1,disableCloseOnSelect:a=!1,classGroup:c,classPreventClosing:d,classPrefix:u,onSearch:p,onResults:m=(()=>{}),onSubmit:f=(()=>{}),onOpened:L=(()=>{}),onReset:v=(()=>{}),onRender:x=(()=>{}),onClose:A=(()=>{}),noResults:g=(()=>{}),onSelectedItem:b=(()=>{})}){var y;t(this,"init",()=>{const t=this.root;this.clearbutton(),this.output(),t.addEventListener("input",this.handleInput),this.showAll&&t.addEventListener("click",this.handleInput),this.onRender({element:t,results:this.resultList})}),t(this,"cacheAct",(t,e)=>{const s=this.root;this.cache&&("update"===t?s.setAttribute(this.cacheData,e.value):"remove"===t?s.removeAttribute(this.cacheData):s.value=s.getAttribute(this.cacheData))}),t(this,"handleInput",({target:t,type:e})=>{if("true"===this.root.getAttribute("aria-expanded")&&"click"===e)return;const s=t.value.replace(this.regex,"\\$&");if(this.cacheAct("update",t),this.showAll&&"click"===e)return this.reset(),void this.searchItem(s.trim());clearTimeout(this.timeout),this.timeout=setTimeout(()=>{this.searchItem(s.trim())},this.delay)}),t(this,"output",()=>{this.setAttr(this.resultList,{id:this.outputUl,tabIndex:"0",role:"listbox"}),this.setAttr(this.resultWrap,{addClass:this.prefix+"-wrapper"}),this.resultWrap.insertAdjacentElement("beforeend",this.resultList),this.root.parentNode.insertBefore(this.resultWrap,this.root.nextSibling)}),t(this,"reset",()=>{var t;this.setAttr(this.root,{"aria-owns":this.id+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),this.resultWrap.classList.remove(this.isActive),this.scrollResultsToTop(),(0==(null===(t=this.matches)||void 0===t?void 0:t.length)&&!this.toInput||this.showAll)&&(this.resultList.innerHTML=""),this.index=this.selectFirst?0:-1,this.onClose()}),t(this,"scrollResultsToTop",()=>{this.resultList.scrollTop=this.resultList.offsetTop-this.resultWrap.offsetHeight}),t(this,"searchItem",t=>{this.value=t,this.onLoading(!0),this.showBtn(),0==t.length&&this.clearButton&&this.cBtn.classList.add("hidden"),this.characters>t.length&&!this.showAll?this.onLoading():this.onSearch({currentValue:t,element:this.root}).then(e=>{const s=this.root.value.length,i=e.length;this.matches=Array.isArray(e)?[...e]:JSON.parse(JSON.stringify(e)),this.onLoading(),this.error(),0==i&&0==s&&this.cBtn.classList.add("hidden"),0==i&&s?(this.root.classList.remove("auto-expanded"),this.reset(),this.noResults({element:this.root,currentValue:t,template:this.results}),this.events()):(i>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(e))&&(this.index=this.selectFirst?0:-1,this.results(),this.events())}).catch(()=>{this.onLoading(),this.reset()})}),t(this,"onLoading",t=>this.root.parentNode.classList[t?"add":"remove"](this.isLoading)),t(this,"error",()=>this.root.classList.remove(this.err)),t(this,"events",()=>{this.root.addEventListener("keydown",this.handleKeys),this.root.addEventListener("click",this.handleShowItems),["mousemove","click"].map(t=>{this.resultList.addEventListener(t,this.handleMouse)}),document.addEventListener("click",this.handleDocClick)}),t(this,"results",t=>{this.setAttr(this.root,{"aria-expanded":"true",addClass:this.prefix+"-expanded"}),this.resultList.innerHTML=0===this.matches.length?this.onResults({currentValue:this.value,matches:0,template:t}):this.onResults({currentValue:this.value,matches:this.matches,classGroup:this.classGroup}),this.resultWrap.classList.add(this.isActive),this.scrollResultsToTop();const e=this.classGroup?`:not(.${this.classGroup})`:"";this.itemsLi=document.querySelectorAll(`#${this.outputUl} > li${e}`),this.selectFirstEl(),this.onOpened({type:"results",element:this.root,results:this.resultList}),this.addAria()}),t(this,"handleDocClick",({target:t})=>{let e=null;(t.closest("ul")&&this.disable||t.closest("."+this.prevClosing))&&(e=!0),t.id===this.id||e||this.reset()}),t(this,"addAria",()=>{for(let t=0;t{if(this.remAria(document.querySelector("."+this.activeList)),!this.selectFirst)return;const{firstElementChild:t}=this.resultList,e=this.classGroup&&this.matches.length>0&&this.selectFirst?t.nextElementSibling:t;this.setAttr(e,{id:this.selectedOption+"-0",addClass:this.activeList,"aria-selected":"true"}),this.setAriaDes(this.selectedOption+"-0"),this.follow(t)}),t(this,"showBtn",()=>{this.cBtn&&(this.cBtn.classList.remove("hidden"),this.cBtn.addEventListener("click",this.destroy))}),t(this,"setAttr",(t,e)=>{for(let s in e)"addClass"===s?t.classList.add(e[s]):"removeClass"===s?t.classList.remove(e[s]):t.setAttribute(s,e[s])}),t(this,"handleShowItems",()=>{const t=this.resultWrap;this.resultList.textContent.length>0&&!t.classList.contains(this.isActive)&&(this.setAttr(this.root,{"aria-expanded":"true",addClass:this.prefix+"-expanded"}),t.classList.add(this.isActive),this.scrollResultsToTop(),this.selectFirstEl(),this.onOpened({type:"showItems",element:this.root,results:this.resultList}))}),t(this,"handleMouse",t=>{t.preventDefault();const{target:e,type:s}=t,i=e.closest("li"),h=null==i?void 0:i.hasAttribute("role"),r=this.activeList,o=document.querySelector("."+r);i&&h&&("click"===s&&this.getTextFromLi(i),"mousemove"!==s||i.classList.contains(r)||(this.remAria(o),this.setAria(i),this.index=this.indexLiSelected(i),this.onSelected({index:this.index,element:this.root,object:this.matches[this.index]})))}),t(this,"getTextFromLi",t=>{t&&0!==this.matches.length?(this.addToInput(t),this.onSubmit({index:this.index,element:this.root,object:this.matches[this.index],results:this.resultList}),this.disable||(this.remAria(t),this.reset()),this.clearButton&&this.cBtn.classList.remove("hidden"),this.cacheAct("remove")):!this.disable&&this.reset()}),t(this,"firstElement",t=>t.firstElementChild||t),t(this,"addToInput",t=>{this.root.value=this.firstElement(t).textContent.trim()}),t(this,"indexLiSelected",t=>Array.prototype.indexOf.call(this.itemsLi,t)),t(this,"handleKeys",t=>{const e=this.keyCodes,{keyCode:s}=t,i=this.resultWrap.classList.contains(this.isActive),h=this.matches.length+1;switch(this.selectedLi=document.querySelector("."+this.activeList),s){case e.UP:case e.DOWN:if(t.preventDefault(),h<=1&&this.selectFirst||!i)return;s===e.UP?(this.index<0&&(this.index=h-1),this.index-=1):(this.index+=1,this.index>=h&&(this.index=0)),this.remAria(this.selectedLi),h>0&&this.index>=0&&this.index{const e=`${this.selectedOption}-${this.indexLiSelected(t)}`;this.setAttr(t,{id:e,"aria-selected":"true",addClass:this.activeList}),this.setAriaDes(e),this.follow(t)}),t(this,"getClassGroupHeight",()=>{const t=document.querySelectorAll(`#${this.outputUl} > li:not(.${this.classGroup})`);let e=0;return[].slice.call(t).map(t=>e+=t.offsetHeight),e}),t(this,"follow",t=>{const e=this.resultList,s=e.previousSibling,i=s?s.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(e.scrollTop=t.offsetTop-this.getClassGroupHeight()),t.offsetTop-ie.scrollTop+e.offsetHeight&&(e.scrollTop=s-e.offsetHeight)}}),t(this,"remAria",t=>{t&&this.setAttr(t,{id:"",removeClass:this.activeList,"aria-selected":"false"})}),t(this,"setAriaDes",t=>this.root.setAttribute("aria-activedescendant",t||"")),t(this,"clearbutton",()=>{this.clearButton&&(this.setAttr(this.cBtn,{class:this.prefix+"-clear hidden",type:"button","aria-label":"claar text from input"}),this.root.insertAdjacentElement("afterend",this.cBtn))}),t(this,"destroy",()=>{this.clearButton&&this.cBtn.classList.add("hidden"),this.root.value="",this.root.focus(),this.resultList.textContent="",this.reset(),this.error(),this.onReset(this.root),this.root.removeEventListener("keydown",this.handleKeys),this.root.removeEventListener("click",this.handleShowItems),document.removeEventListener("click",this.handleDocClick)}),this.id=e,this.root=document.getElementById(this.id),this.onSearch=(y=p,Boolean(y&&"function"==typeof y.then)?p:({currentValue:t,element:e})=>Promise.resolve(p({currentValue:t,element:e}))),this.onResults=m,this.onRender=x,this.onSubmit=f,this.onSelected=b,this.onOpened=L,this.onReset=v,this.noResults=g,this.onClose=A,this.delay=s,this.characters=h,this.clearButton=i,this.selectFirst=r,this.toInput=o,this.showAll=l,this.classGroup=c,this.prevClosing=d,this.prefix=u?u+"-auto":"auto",this.disable=a,this.cache=n,this.outputUl=`${this.prefix}-${this.id}-results`,this.cacheData="data-cache-auto-"+this.id,this.isLoading=this.prefix+"-is-loading",this.isActive=this.prefix+"-is-active",this.activeList=this.prefix+"-selected",this.selectedOption=this.prefix+"-selected-option",this.err=this.prefix+"-error",this.regex=/[|\\{}()[\]^$+*?.]/g,this.timeout=null,this.resultWrap=document.createElement("div"),this.resultList=document.createElement("ul"),this.cBtn=document.createElement("button"),this.keyCodes={ESC:27,ENTER:13,UP:38,DOWN:40,TAB:9},this.init()}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Autocomplete=e(); diff --git a/shimatta_kenkyusho/templates/base.html b/shimatta_kenkyusho/templates/base.html index 43076d5..c75c865 100644 --- a/shimatta_kenkyusho/templates/base.html +++ b/shimatta_kenkyusho/templates/base.html @@ -6,6 +6,7 @@ + {{ base.title }} {% block customhead %} {% endblock customhead %} @@ -53,7 +54,7 @@ {% endblock content %} - + {% block custom_scripts %} {% endblock custom_scripts %} diff --git a/shimatta_kenkyusho/templates/parts/modals/delete-storage-modal.html b/shimatta_kenkyusho/templates/parts/modals/delete-storage-modal.html new file mode 100644 index 0000000..298cfcb --- /dev/null +++ b/shimatta_kenkyusho/templates/parts/modals/delete-storage-modal.html @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/shimatta_kenkyusho/templates/parts/modals/new-substorage-modal.html b/shimatta_kenkyusho/templates/parts/modals/new-substorage-modal.html new file mode 100644 index 0000000..a0216d8 --- /dev/null +++ b/shimatta_kenkyusho/templates/parts/modals/new-substorage-modal.html @@ -0,0 +1,43 @@ + \ No newline at end of file diff --git a/shimatta_kenkyusho/templates/parts/stocks-detail.html b/shimatta_kenkyusho/templates/parts/stocks-detail.html index 759e5cb..e9c4d8f 100644 --- a/shimatta_kenkyusho/templates/parts/stocks-detail.html +++ b/shimatta_kenkyusho/templates/parts/stocks-detail.html @@ -21,6 +21,7 @@

Sub-Storages Parent Storage {% else %}

Sub-Storages Stock Overview {% endif %} +

@@ -41,49 +42,13 @@
{% with add_storage_form as form %} - {% endblock content %} @@ -91,9 +56,16 @@ {% if add_storage_form.errors %} {% endif %} +{% if delete_storage_errors %} + + + + {% with add_storage_form as form %} + {% include 'parts/modals/new-substorage-modal.html' %} + {% endwith %} + -{% endblock content %} \ No newline at end of file +{% endblock content %} + +{% block custom_scripts %} +{% if add_storage_form.errors %} + +{% endif %} +{% endblock custom_scripts %} +