tryton-sao 7.0.21 → 7.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +10 -0
- package/dist/tryton-sao.css +4 -4
- package/dist/tryton-sao.js +15 -15
- package/dist/tryton-sao.min.css +4 -4
- package/dist/tryton-sao.min.js +2 -2
- package/package.json +1 -1
- package/src/model.js +1 -2
- package/src/sao.js +1 -1
- package/src/sao.less +1 -1
- package/src/screen.js +6 -9
- package/src/tab.js +1 -1
- package/src/view/form.js +5 -2
- package/src/window.js +1 -0
package/dist/tryton-sao.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! tryton-sao-7.0.
|
|
1
|
+
/*! tryton-sao-7.0.23 | GPL-3
|
|
2
2
|
This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
3
3
|
this repository contains the full copyright notices and license terms. */
|
|
4
|
-
var Sao={__version__:"7.0.21"};function eval_pyson(value){with(Sao.PYSON.eval)return eval("("+value+")")}!function(){"use strict";"contains"in String.prototype||(String.prototype.contains=function(e,t){return-1!==String.prototype.indexOf.call(this,e,t)}),String.prototype.startsWith||Object.defineProperty(String.prototype,"startsWith",{enumerable:!1,configurable:!1,writable:!1,value:function(e,t){return this.indexOf(e,t=t||0)===t}}),String.prototype.endsWith||Object.defineProperty(String.prototype,"endsWith",{enumerable:!1,configurable:!1,writable:!1,value:function(e,t){t=t||this.length,t-=e.length;e=this.lastIndexOf(e);return-1!==e&&e===t}}),String.prototype.padEnd||(String.prototype.padEnd=function(e,t){return e>>=0,t=String(void 0!==t?t:" "),this.length>e?String(this):((e-=this.length)>t.length&&(t+=t.repeat(e/t.length)),String(this)+t.slice(0,e))}),String.prototype.padStart||(String.prototype.padStart=function(e,t){return e>>=0,t=String(void 0!==t?t:" "),this.length>e?String(this):((e-=this.length)>t.length&&(t+=t.repeat(e/t.length)),t.slice(0,e)+String(this))}),Array.prototype.some||(Array.prototype.some=function(e){if(null===this)throw new TypeError;var t,i,n=Object(this),o=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(t=arguments[1],i=0;i<o;i++)if(i in n&&e.call(t,n[i],i,n))return!0;return!1}),Array.from||(Array.from=function(e){var t=[];for(const i of e)t.push(i);return t}),Sao.setdefault=function(e,t,i){return e.hasOwnProperty(t)||(e[t]=i),e[t]};try{document.execCommand("styleWithCSS",!1,!1)}catch(e){}try{document.execCommand("useCSS",!1,!0)}catch(e){}jQuery.fn.extend({uniqueId:(e=0,function(){return this.each(function(){this.id||(this.id="ui-id-"+ ++e)})})}),window.onbeforeunload=function(e){var t;if(Sao.main_menu_screen&&Sao.main_menu_screen.save_tree_state(!0),Sao.Tab.tabs.length)return t=Sao.i18n.gettext("Are your sure to leave?"),e.returnValue=t},Sao.class_=function(e,t){function i(){if(!(this instanceof i))throw new Error("Constructor function requires new operator");this.Class=i,this.init&&this.init.apply(this,arguments)}if(i.prototype=Object.create(e.prototype),i._super=e.prototype,t)for(var n in t)Object.defineProperty(i.prototype,n,Object.getOwnPropertyDescriptor(t,n));function o(e){return i.apply(this,e)}return o.prototype=i.prototype,i.new_=function(e){return new o(e)},i},Sao.Logging=Sao.class_(Object,{init:function(){this.level=Sao.Logging.ERROR},set_level:function(e){this.level=e},_log:function(e,t,i){this.level<=e&&t.apply(console,i)},debug:function(){this._log(Sao.Logging.DEBUG,console.log,arguments)},info:function(){this._log(Sao.Logging.INFO,console.info,arguments)},warn:function(){this._log(Sao.Logging.WARNING,console.warn,arguments)},error:function(){this._log(Sao.Logging.ERROR,console.error,arguments)},critical:function(){this._log(Sao.Logging.CRITICAL,console.error,arguments)},assert:function(){this.level<=Sao.Logging.DEBUG&&console.assert.apply(console,arguments)}}),Sao.Logging.CRITICAL=50,Sao.Logging.ERROR=40,Sao.Logging.WARNING=30,Sao.Logging.INFO=20,Sao.Logging.DEBUG=10,Sao.Logging.NOTSET=0,Sao.Logger=new Sao.Logging,Sao.Decimal=Number;var e,t=moment.prototype.toString,i=(moment.prototype.toString=function(){return this.isDate?this.format("YYYY-MM-DD"):this.isDateTime?this.milliseconds()?this.format("YYYY-MM-DD HH:mm:ss.SSSSSS"):this.format("YYYY-MM-DD HH:mm:ss"):this.isTime?this.milliseconds()?this.format("HH:mm:ss.SSSSSS"):this.format("HH:mm:ss"):t.call(this)},Sao.Date=function(e,t,i){var n;return void 0===t?(n=moment(e),e=void 0):n=moment(),n.year(e),n.month(t),n.date(i),n.set({hour:0,minute:0,second:0,millisecond:0}),n.isDate=!0,n},Sao.Date.min=moment(new Date(864e5*(1-1e8))),Sao.Date.min.set({hour:0,minute:0,second:0,millisecond:0}),Sao.Date.min.isDate=!0,Sao.Date.max=moment(new Date(864e13)),Sao.Date.max.set({hour:0,minute:0,second:0,millisecond:0}),Sao.Date.max.isDate=!0,Sao.DateTime=function(e,t,i,n=0,o=0,s=0,a=0,r=!1){var l;return void 0===t?(l=moment(e),e=void 0):l=moment(),r&&l.utc(),l.year(e),l.month(t),l.date(i),void 0!==t&&(l.hour(n),l.minute(o),l.second(s),l.milliseconds(a)),l.isDateTime=!0,l.local(),l.todate=function(){return Sao.Date(this.year(),this.month(),this.date())},l.totime=function(){return Sao.Time(this.hour(),this.minute(),this.second(),this.millisecond())},l},Sao.DateTime.combine=function(e,t){return Sao.DateTime(e.year(),e.month(),e.date(),t.hour(),t.minute(),t.second(),t.millisecond())},Sao.DateTime.min=moment(new Date(-864e13)).local(),Sao.DateTime.min.isDateTime=!0,Sao.DateTime.max=moment(new Date(864e13)).local(),Sao.DateTime.max.isDateTime=!0,Sao.Time=function(e,t,i,n){e=moment({hour:e,minute:t,second:i,millisecond:n||0});return e.isTime=!0,e},Sao.TimeDelta=function(e,t,i,n,o,s){e=moment.duration({days:e,seconds:t,milliseconds:i,minutes:n,hours:o,weeks:s});return e.isTimeDelta=!0,e},Sao.config={},Sao.config.limit=1e3,Sao.config.display_size=20,Sao.__version__.split(".").slice(0,2)),i=parseInt(i[1],10)%2?"latest":i.join("."),s=(Sao.config.doc_url="https://docs.tryton.org/"+i,Sao.config.bug_url="https://bugs.tryton.org/",Sao.config.title="Tryton",Sao.config.icon_colors="#267f82,#3e4950,#e78e42".split(","),Sao.config.calendar_colors="#fff,#267f82".split(","),Sao.config.graph_color="#267f82",Sao.config.bus_timeout=6e5,Sao.config.image_max_size=Math.pow(10,6),Sao.i18n=i18n(),Sao.i18n.setlang=function(i){return i=i||(navigator.language||navigator.browserLanguage||navigator.userLanguage||"en").replace("-","_"),jQuery("html").attr("lang",i),Sao.i18n.setLocale(i),moment.locale(i.slice(0,2)),jQuery.getJSON("locale/"+i+".json").then(function(e){for(var t in e[""].language||(e[""].language=i),e[""]["plural-forms"]||(e[""]["plural-forms"]="nplurals=2; plural=(n!=1);"),e)""!==t&&(e[t]=2==e[t].length?e[t][1]:e[t].slice(1));Sao.i18n.loadJSON(e)},function(){if(~i.indexOf("_"))return Sao.i18n.setlang(i.split("_").slice(0,-1).join("_"))})},Sao.i18n.getlang=function(){return Sao.i18n.getLocale()},Sao.i18n.BC47=function(e){return e.replace("_","-")},Sao.i18n.set_direction=function(e){Sao.i18n.rtl="rtl"===e,jQuery("html").attr("dir",e),jQuery(".row-offcanvas").removeClass("row-offcanvas-left row-offcanvas-right").addClass(Sao.i18n.rtl?"row-offcanvas-right":"row-offcanvas-left")},Sao.i18n.locale={},Sao.BOM_UTF8="\ufeff",Sao.get_preferences=function(){var e=Sao.Session.current_session;return e.reload_context().then(function(){return Sao.rpc({method:"model.res.user.get_preferences",params:[!1,{}]},e).then(function(n){var e=[];return e.push(Sao.common.MODELACCESS.load_models()),e.push(Sao.common.ICONFACTORY.load_icons()),e.push(Sao.common.MODELHISTORY.load_history()),e.push(Sao.common.MODELNOTIFICATION.load_names()),e.push(Sao.common.VIEW_SEARCH.load_searches()),jQuery.when.apply(jQuery,e).then(function(){for(const i of n.actions||[])Sao.Action.execute(i,{},null,{});Sao.set_title();var e=n.language!=Sao.i18n.getLocale(),t=jQuery.Deferred();return Sao.i18n.setlang(n.language).always(function(){e&&Sao.user_menu(n),t.resolve(n)}),Sao.i18n.set_direction(n.language_direction),Sao.i18n.locale=n.locale,Sao.common.MODELNAME.clear(),t})})})},Sao.set_title=function(e){e=[e,Sao.config.title];document.title=e.filter(function(e){return e}).join(" - "),jQuery("#title").text(Sao.config.title)},Sao.set_url=function(e,t){var i=Sao.Session.current_session;i&&(i="#"+i.database,e&&(i+="/"+e),window.location=i),Sao.set_title(t)},window.onhashchange=function(){var e=Sao.Session.current_session;if(e){var t,i,e="#"+e.database;if(window.location.hash==e)t="";else{if(!window.location.hash.startsWith(e+"/"))return;t=window.location.hash.substr(e.length+1)}if(t){t=decodeURIComponent(t);for(const i of Sao.Tab.tabs)if(decodeURIComponent(i.get_url())==t)return void i.show();Sao.open_url()}else(i=Sao.Tab.tabs.get_current())&&Sao.set_url(i.get_url(),i.name)}},Sao.open_url=function(e){function i(e){return Sao.rpc.convertJSONObject(jQuery.parseJSON(e))}var t,n,o=(e=void 0===e?window.location.hash.substr(1):e).indexOf(";"),s={};if(0<=o){n=e.substring(0,o);for(const a of e.substring(o+1).split("&"))a&&(t=a.split("=").map(decodeURIComponent),s[t[0]]=t[1])}else n=e;switch((n=n.split("/").slice(1)).shift()){case"model":!function(e){var t={};if(t.model=e.shift(),t.model){try{t.view_ids=i(s.views||"[]"),void 0!==s.limit&&(t.limit=i(s.limit||"null")),t.name=i(s.name||'""'),t.search_value=i(s.search_value||"[]"),t.domain=i(s.domain||"[]"),t.context=i(s.context||"{}"),t.context_model=s.context_model,t.tab_domain=i(s.tab_domain||"[]")}catch(e){return}e=e.shift();if(e){if(e=Number(e),isNaN(e))return;t.res_id=e,t.mode=["form","tree"]}try{Sao.Tab.create(t)}catch(e){}}}(n);break;case"wizard":!function(e){var t={};if(t.action=e[0],t.action){try{t.data=i(s.data||"{}"),t.direct_print=i(s.direct_print||"false"),t.name=i(s.name||'""'),t.window=i(s.window||"false"),t.context=i(s.context||"{}")}catch(e){return}try{Sao.Wizard.create(t)}catch(e){}}}(n);break;case"report":!function(e){var t={};if(t.name=e[0],t.name){try{t.data=i(s.data||"{}"),t.direct_print=i(s.direct_print||"false"),t.context=i(s.context||"{}")}catch(e){return}try{Sao.Action.exec_report(t)}catch(e){}}}(n);break;case"url":!function(){var e;try{e=i(s.url||"false")}catch(e){return}e&&window.open(e,"_blank","noreferrer,noopener")}()}},Sao.login=function(){Sao.set_title(),Sao.i18n.setlang().always(function(){Sao.Session.server_version().then(function(e){JSON.stringify(e.split(".").slice(0,2))!==JSON.stringify(Sao.__version__.split(".").slice(0,2))?Sao.common.warning.run(Sao.i18n.gettext("Incompatible version of the server."),Sao.i18n.gettext("Version mismatch")):Sao.Session.get_credentials().then(function(e){return(Sao.Session.current_session=e).reload_context()}).then(Sao.get_preferences).then(function(e){Sao.menu(e),Sao.user_menu(e),Sao.open_url(),Sao.Bus.listen()})},function(){Sao.common.warning.run(Sao.i18n.gettext("Could not connect to the server."),Sao.i18n.gettext("Connection error"))})})},Sao.logout=function(){var e=Sao.Session.current_session;e&&e.session||(Sao.main_menu_screen=null),Sao.Tab.tabs.close(!0).done(function(){jQuery("#user-preferences").empty(),jQuery("#global-search").empty(),jQuery("#menu").empty(),e.do_logout().always(Sao.login),Sao.set_title()})},Sao.preferences=function(){return Sao.Tab.tabs.close(!0).then(function(){jQuery("#user-preferences").empty(),jQuery("#global-search").empty(),jQuery("#menu").empty(),new Sao.Window.Preferences(function(){Sao.Session.current_session.reset_context(),Sao.get_preferences().then(function(e){Sao.menu(e),Sao.user_menu(e)})})})},Sao.favorites_menu=function(){var e,t,s;jQuery(window).click(function(){Sao.favorites_menu_clear()}),jQuery("#user-favorites").children(".dropdown-menu").length||(t=Sao.main_menu_screen.model_name+".favorite",e=Sao.Session.current_session,t={method:"model."+t+".get"},s=jQuery("<ul/>",{class:"dropdown-menu","aria-expanded":"false","aria-labelledby":"user-favorites"}),jQuery("#user-favorites").append(s),Sao.rpc(t,e).then(function(e){e.forEach(function(e){var t=jQuery("<a/>",{href:"#"}),i=e[0],n=jQuery("<li/>",{role:"presentation"}),o=Sao.common.ICONFACTORY.get_icon_img(e[2],{class:"favorite-icon"});t.append(o),n.append(t),t.append(e[1]),t.click(function(e){e.preventDefault(),Sao.favorites_menu_clear(),Sao.Action.exec_keyword("tree_open",{model:Sao.main_menu_screen.model_name,id:i})}),s.append(n)}),s.append(jQuery("<li/>",{class:"divider"})),jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{href:"#"}).click(function(e){e.preventDefault(),Sao.favorites_menu_clear(),Sao.Tab.create({model:Sao.main_menu_screen.model_name+".favorite",mode:["tree","form"],name:Sao.i18n.gettext("Favorites")})}).text(Sao.i18n.gettext("Manage..."))).appendTo(s)}))},Sao.favorites_menu_clear=function(){jQuery("#user-favorites").children(".dropdown-menu").remove()},Sao.user_menu=function(e){jQuery("#user-preferences").empty();var t=jQuery("<a/>",{href:"#",title:e.status_bar}).click(function(e){e.preventDefault(),t.prop("disabled",!0),Sao.preferences().then(()=>t.prop("disabled",!1))}).text(e.status_bar),e=(jQuery("#user-preferences").append(t),e.avatar_badge_url&&t.prepend(jQuery("<img/>",{src:e.avatar_badge_url+"?s=15",class:"img-circle img-badge"})),e.avatar_url&&t.prepend(jQuery("<img/>",{src:e.avatar_url+"?s=30",class:"img-circle"})),Sao.i18n.gettext("Logout"));jQuery("#user-logout > a").attr("title",e).attr("aria-label",e).off().click(Sao.logout).find("span:not(.icon)").text(e)},Sao.main_menu_row_activate=function(){var e=Sao.main_menu_screen;e.get_id()&&Sao.Action.exec_keyword("tree_open",{model:e.model_name,id:e.get_id()},null,!1)},Sao.menu=function(e){var t,i,n,o;e?(e=(n=new Sao.PYSON.Decoder).decode(e.pyson_menu),t=!1,jQuery.isEmptyObject(e.views)?e.view_id&&(t=[e.view_id[0]]):t=e.views.map(function(e){return e[0]}),i=(n=new Sao.PYSON.Decoder(Sao.Session.current_session.context)).decode(e.pyson_context||"{}"),n=n.decode(e.pyson_domain),o=new Sao.Tab.Form(e.res_model,{mode:["tree"],view_ids:t,domain:n,context:i,selection_mode:Sao.common.SELECTION_NONE,limit:null,row_activate:Sao.main_menu_row_activate}),Sao.main_menu_screen=o.screen,Sao.main_menu_screen.switch_callback=null,Sao.Tab.tabs.splice(Sao.Tab.tabs.indexOf(o),1),o.view_prm.done(function(){var e=o.screen.current_view,e=(e.table.removeClass("table table-bordered"),e.table.addClass("no-responsive"),e.table.find("thead").hide(),e.table.find("colgroup > col.tree-menu").css("width",0),new Sao.GlobalSearch),e=(jQuery("#global-search").empty(),jQuery("#global-search").append(e.el),jQuery("#menu").empty(),jQuery("#menu").append(o.screen.screen_container.content_box.detach()),new s(o.screen.model.fields.favorite));o.screen.views[0].table.find("> colgroup").append(e.col),o.screen.views[0].table.find("> thead > tr").append(e.header),o.screen.views[0].columns.push(e)})):(e=Sao.Session.current_session,Sao.rpc({method:"model.res.user.get_preferences",params:[!1,{}]},e).then(Sao.menu))},Sao.main_menu_screen=null,Sao.class_(Object,{init:function(e){this.field=e,this.col=jQuery("<col/>",{class:"favorite"}),this.header=jQuery("<th/>"),this.footers=[],this.attributes=jQuery.extend({},this.field.description),this.attributes.name=this.field.name},get_cell:function(){return jQuery("<img/>",{class:"column-affix",tabindex:0})},render:function(t,i){return i=i||this.get_cell(),t.load(this.field.name).done(()=>{var e;null!==t._values.favorite&&(e="tryton-star",t._values.favorite||(e+="-border"),i.data("star",Boolean(t._values.favorite)),Sao.common.ICONFACTORY.get_icon_url(e).then(e=>{i.attr("src",e)}),i.click({record:t,button:i},this.favorite_click))}),i},set_visible:function(){},get_visible:function(){return!0},favorite_click:function(e){e.stopImmediatePropagation();var t=e.data.button,i=t.data("star"),n=i?(o="tryton-star-border","unset"):(o="tryton-star","set"),i=(t.data("star",!i),Sao.common.ICONFACTORY.get_icon_url(o).then(function(e){t.attr("src",e)}),Sao.main_menu_screen.model_name+".favorite"),o=Sao.Session.current_session,i={method:"model."+i+"."+n,params:[e.data.record.id,o.context]};Sao.rpc(i,o),Sao.favorites_menu_clear()}}));function l(){return[{shortcut:"alt+n",label:Sao.i18n.gettext("New"),id:"new_"},{shortcut:"ctrl+s",label:Sao.i18n.gettext("Save"),id:"save"},{shortcut:"ctrl+l",label:Sao.i18n.gettext("Switch"),id:"switch_"},{shortcut:"ctrl+r",label:Sao.i18n.gettext("Reload/Undo"),id:"reload"},{shortcut:"ctrl+shift+d",label:Sao.i18n.gettext("Duplicate"),id:"copy"},{shortcut:"ctrl+d",label:Sao.i18n.gettext("Delete"),id:"delete_"},{shortcut:"ctrl+up",label:Sao.i18n.gettext("Previous"),id:"previous"},{shortcut:"ctrl+down",label:Sao.i18n.gettext("Next"),id:"next"},{shortcut:"ctrl+f",label:Sao.i18n.gettext("Search"),id:"search"},{shortcut:"alt+w",label:Sao.i18n.gettext("Close Tab"),id:"close"},{shortcut:"ctrl+shift+t",label:Sao.i18n.gettext("Attachment"),id:"attach"},{shortcut:"ctrl+shift+o",label:Sao.i18n.gettext("Note"),id:"note"},{shortcut:"ctrl+e",label:Sao.i18n.gettext("Action"),id:"action"},{shortcut:"ctrl+shift+r",label:Sao.i18n.gettext("Relate"),id:"relate"},{shortcut:"ctrl+p",label:Sao.i18n.gettext("Print"),id:"print"},{shortcut:"ctrl+shift+e",label:Sao.i18n.gettext("E-Mail"),id:"email"},{shortcut:"alt+shift+tab",label:Sao.i18n.gettext("Previous tab"),callback:function(){Sao.Tab.previous_tab()}},{shortcut:"alt+tab",label:Sao.i18n.gettext("Next tab"),callback:function(){Sao.Tab.next_tab()}},{shortcut:"ctrl+k",label:Sao.i18n.gettext("Global search"),callback:function(){jQuery("#main_navbar:hidden").collapse("show"),jQuery("#global-search-entry").focus()}},{shortcut:"f1",label:Sao.i18n.gettext("Show this help"),callback:function(){var e,t=new Sao.Dialog(Sao.i18n.gettext("Help"),"help-dialog","md",!0,Sao.__version__),i=(jQuery("<button>",{class:"close","data-dismiss":"modal","aria-label":Sao.i18n.gettext("Close")}).append(jQuery("<span>",{"aria-hidden":!0}).append("×")).prependTo(t.header),jQuery("<a/>",{class:"btn btn-link",href:Sao.config.doc_url,target:"_blank"}).text(Sao.i18n.gettext("Documentation...")).appendTo(t.footer),jQuery("<h4/>").text(Sao.i18n.gettext("Keyboard shortcuts")).appendTo(t.body),jQuery("<div/>",{class:"row"}).appendTo(t.body)),n=jQuery("<dl/>",{class:"dl-horizontal col-md-6"}).append(jQuery("<h5/>").text(Sao.i18n.gettext("Global shortcuts"))).appendTo(i),o=jQuery("<dl/>",{class:"dl-horizontal col-md-6"}).append(jQuery("<h5/>").text(Sao.i18n.gettext("Tab shortcuts"))).appendTo(i);for(const r of l()){var s=jQuery("<dt/>").text(r.label),a=jQuery("<dd/>").append(jQuery("<kbd>").text(r.shortcut));e=r.id?o:n,s.appendTo(e),a.appendTo(e)}t.modal.on("hidden.bs.modal",function(){jQuery(this).remove()}),t.modal.modal("show")}},{shortcut:"ctrl+f1",label:Sao.i18n.gettext("Show/Hide access keys"),callback:function(){jQuery("html").toggleClass("accesskey")}}]}function n(){var i=1040;jQuery(".modal.in").each(function(e){var t=jQuery(this);i++,t.css("zIndex",i),t.next(".modal-backdrop.in").addClass("hidden").css("zIndex",i-1)}),jQuery(".modal.in:visible:last").focus().next(".modal-backdrop.in").removeClass("hidden")}Sao.Dialog=Sao.class_(Object,{init:function(e,t,i="sm",n=!0,o=null){this.modal=jQuery("<div/>",{class:t+" modal fade",role:"dialog","data-backdrop":"static","data-keyboard":n}),this.content=jQuery("<form/>",{class:"modal-content"}).appendTo(jQuery("<div/>",{class:"modal-dialog modal-"+i}).appendTo(this.modal)),this.header=jQuery("<div/>",{class:"modal-header"}).appendTo(this.content),e&&this.add_title(e,o),this.body=jQuery("<div/>",{class:"modal-body"}).appendTo(this.content),this.footer=jQuery("<div/>",{class:"modal-footer"}).appendTo(this.content),this.modal.on("shown.bs.modal",function(){0<jQuery(document.activeElement).closest(this.el)||jQuery(this).find(':input:visible:not([readonly]):not([tabindex^="-"]):first').focus()})},add_title:function(e,t=null){e=jQuery("<h4/>",{class:"modal-title",title:e}).text(Sao.common.ellipsize(e,120)+(t?" ":""));t&&e.append(jQuery("<small/>").text(t)),this.header.append(e)}}),Sao.GlobalSearch=Sao.class_(Object,{init:function(){this.el=jQuery("<div/>",{class:"global-search-container"});var e=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el),t=(jQuery("<div/>",{id:"user-favorites",class:"input-group-btn"}).append(jQuery("<button/>",{class:"btn btn-default dropdown-toggle","data-toggle":"dropdown","aria-haspopup":!0,"aria-expanded":!1,title:Sao.i18n.gettext("Favorites"),"aria-label":Sao.i18n.gettext("Favorites")}).click(Sao.favorites_menu).append(Sao.common.ICONFACTORY.get_icon_img("tryton-bookmarks"))).appendTo(e),this.search_entry=jQuery("<input>",{id:"global-search-entry",class:"form-control mousetrap",placeholder:Sao.i18n.gettext("Action")}).appendTo(e),new Sao.common.InputCompletion(this.el,this.update.bind(this),this.match_selected.bind(this),this.format.bind(this)));t.input.keydown(function(e){e.which!=Sao.common.RETURN_KEYCODE||t.dropdown.hasClass("open")||(e.preventDefault(),t.menu.dropdown("toggle"))})},format:function(e){var t=jQuery("<div/>");return Sao.common.ICONFACTORY.get_icon_img(e.icon,{class:"global_search-icon"}).appendTo(t),jQuery("<span/>",{class:"global-search-text"}).text(e.record_name).appendTo(t),t},update:function(e){var t=new Sao.Model("ir.model");return e?t.execute("global_search",[e,Sao.config.limit,Sao.main_menu_screen.model_name],Sao.main_menu_screen.context).then(e=>{var t=[];for(const i of e)t.push({model:i[1],model_name:i[2],record_id:i[3],record_name:i[4],icon:i[5]});return t}):jQuery.when([])},match_selected:function(e){e.model==Sao.main_menu_screen.model_name?Sao.Action.exec_keyword("tree_open",{model:e.model,id:e.record_id}):(e={model:e.model,res_id:e.record_id,mode:["form","tree"],name:e.model_name},Sao.Tab.create(e)),this.search_entry.val("")}}),jQuery(document).ready(function(){var e=new URL(window.location);if(e.searchParams.has("session")){var t=e.searchParams.get("database"),i={login_service:e.searchParams.get("login_service"),login:e.searchParams.get("login"),user_id:parseInt(e.searchParams.get("user_id"),10),session:e.searchParams.get("session")};if(e.searchParams.has("renew")){e=parseInt(e.searchParams.get("renew"),10);if(i.user_id!==e)return void window.close()}i=JSON.stringify(i),localStorage.setItem("sao_session_"+t,i),window.close()}else{"undefined"!=typeof Mousetrap&&l().forEach(function(i){Mousetrap.bind(i.shortcut,function(){var e,t;return i.id?(e=Sao.Tab.tabs.get_current())&&((t=jQuery(":focus")).blur(),e.el.find('a[id="'+i.id+'"]').click(),t.focus()):i.callback&&jQuery.when().then(i.callback),!1})});try{Notification.requestPermission()}catch(e){Sao.Logger.error(e.message,e.stack)}Sao.login()}}),Sao.Plugins=[],jQuery(document).on("show.bs.modal",".modal",function(e){jQuery(this).appendTo(jQuery("body"))}).on("shown.bs.modal",".modal.in",function(e){n()}).on("hidden.bs.modal",".modal",function(e){n(),jQuery(".modal:visible").length&&jQuery(document.body).addClass("modal-open")}),jQuery(document).on("keydown","textarea",function(e){var t;"PageUp"!==e.key&&"PageDown"!==e.key||(e.preventDefault(),t="PageUp"===e.key?0:e.target.textLength,e.target.setSelectionRange(t,t))})}(),!function(){"use strict";Sao.rpc=function(l,c=null,d=!0,h=!0){var u,_=jQuery.Deferred(),m=(c=c||new Sao.Session,jQuery.extend([],l.params));if(m.push(jQuery.extend({},c.context,m.pop())),c.cache&&c.cache.cached(l.method)&&void 0!==(u=c.cache.get(l.method,JSON.stringify(Sao.rpc.prepareObject(m)))))return d?jQuery.when(u):u;var e=Sao.common.processing.show();if(jQuery.ajax({async:d,headers:{Authorization:"Session "+c.get_auth()},contentType:"application/json",data:JSON.stringify(Sao.rpc.prepareObject({id:Sao.rpc.id++,method:l.method,params:m})),dataType:"json",url:"/"+(c.database||"")+"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}],success:function(e,t,i){var n,o,s,a,r;null===e?Sao.common.warning.run("",Sao.i18n.gettext("Unable to reach the server.")).always(_.reject):e.error&&!h?(console.debug(`RPC error calling ${l}: ${e.error[0]}: ${e.error[1]}.`),_.reject(e.error)):e.error&&h?"UserWarning"==e.error[0]?(n=e.error[1][0],o=e.error[1][1],s=e.error[1][2],Sao.common.userwarning.run(s,o).then(function(e){~["always","ok"].indexOf(e)?Sao.rpc({method:"model.res.user.warning.skip",params:[n,"always"==e,{}]},c).done(function(){d?Sao.rpc(l,c).then(_.resolve,_.reject):_.resolve()}):_.reject()},_.reject)):"UserError"==e.error[0]?(o=e.error[1][0],s=e.error[1][1],r=e.error[1][2],jQuery.isEmptyObject(r)||(a=r[1],r=r[0],(a=new Sao.common.DomainParser(a)).stringable(r)&&(s+="\n"+a.string(r))),Sao.common.warning.run(s,o).always(_.reject)):"ConcurrencyException"==e.error[0]?d&&l.method.startsWith("model.")&&(l.method.endsWith(".write")||l.method.endsWith(".delete"))&&1==l.params[0].length?(a=l.method.split(".").slice(1,-1).join("."),Sao.common.concurrency.run(a,l.params[0][0],l.params.slice(-1)[0]).then(function(){delete l.params.slice(-1)[0]._timestamp,Sao.rpc(l,c).then(_.resolve,_.reject)},_.reject)):Sao.common.message.run("Concurrency Exception","tryton-warning").always(_.reject):Sao.common.error.run(e.error[0],e.error[1]).always(_.reject):(u=e.result,c.cache&&(r=i.getResponseHeader("X-Tryton-Cache"))&&(r=parseInt(r,10),c.cache.set(l.method,JSON.stringify(Sao.rpc.prepareObject(m)),r,u)),_.resolve(u))},error:function(e,t,i){401==e.status?Sao.Session.renew(c).then(function(){d?Sao.rpc(l,c,d,h).then(_.resolve,_.reject):_.resolve()},_.reject):(429==e.status?Sao.common.message.run(Sao.i18n.gettext("Too many requests. Try again later."),"tryton-error"):Sao.common.error.run(t,i)).always(_.reject)}}),d)return _.promise();if(void 0===u)throw _;return u},Sao.rpc.id=0,Sao.rpc.convertJSONObject=function(e,t,i){if(e instanceof Array)for(var n=0,o=e.length;n<o;n++)Sao.rpc.convertJSONObject(e[n],n,e);else if("string"!=typeof e&&"number"!=typeof e&&null!==e)if(e&&e.__class__){switch(e.__class__){case"datetime":e=Sao.DateTime(e.year,e.month-1,e.day,e.hour,e.minute,e.second,Math.ceil(e.microsecond/1e3),!0);break;case"date":e=Sao.Date(e.year,e.month-1,e.day);break;case"time":e=Sao.Time(e.hour,e.minute,e.second,Math.ceil(e.microsecond/1e3));break;case"timedelta":e=Sao.TimeDelta(null,e.seconds);break;case"bytes":e=Sao.common.atob(e);break;case"Decimal":e=new Sao.Decimal(e.decimal)}i&&(i[t]=e)}else for(var s in e)Sao.rpc.convertJSONObject(e[s],s,e);return i||e},Sao.rpc.prepareObject=function(e,t,i){if(e instanceof Array)for(var n=0,o=(e=jQuery.extend([],e)).length;n<o;n++)Sao.rpc.prepareObject(e[n],n,e);else if("string"!=typeof e&&"number"!=typeof e&&"boolean"!=typeof e&&null!=e)if(e.isDate)e={__class__:"date",year:e.year(),month:e.month()+1,day:e.date()};else if(e.isDateTime)e={__class__:"datetime",year:(e=e.clone()).utc().year(),month:e.utc().month()+1,day:e.utc().date(),hour:e.utc().hour(),minute:e.utc().minute(),second:e.utc().second(),microsecond:1e3*e.utc().millisecond()};else if(e.isTime)e={__class__:"time",hour:e.hour(),minute:e.minute(),second:e.second(),microsecond:1e3*e.millisecond()};else if(e.isTimeDelta)e={__class__:"timedelta",seconds:e.asSeconds()};else if(e instanceof Sao.Decimal)e={__class__:"Decimal",decimal:e.toString()};else if(e instanceof Uint8Array)e={__class__:"bytes",base64:Sao.common.btoa(e)};else for(var s in e=jQuery.extend({},e))Sao.rpc.prepareObject(e[s],s,e);return i&&(i[t]=e),i||e},jQuery.ajaxSetup({converters:{"text json":function(e){return Sao.rpc.convertJSONObject(jQuery.parseJSON(e))}}})}(),!function(){"use strict";Sao.PYSON={},Sao.PYSON.eval={True:!0,False:!1},Sao.PYSON.toString=function(t){return t instanceof Sao.PYSON.PYSON?t.toString():t instanceof Array?"["+t.map(Sao.PYSON.toString).join(", ")+"]":t instanceof Object?"{"+Object.keys(t).map(e=>Sao.PYSON.toString(e)+": "+Sao.PYSON.toString(t[e])).join(", ")+"}":JSON.stringify(t)},Sao.PYSON.PYSON=Sao.class_(Object,{init:function(){},pyson:function(){throw"NotImplementedError"},types:function(){throw"NotImplementedError"},get:function(e,t=""){return new Sao.PYSON.Get(this,e,t)},in_:function(e){return new Sao.PYSON.In(this,e)},contains:function(e){return new Sao.PYSON.In(e,this)},toString:function(){return this.pyson().__class__+"("+this.__string_params__().map(Sao.PYSON.toString).join(", ")+")"},__string_params__:function(){throw"NotImplementedError"}}),Sao.PYSON.PYSON.eval_=function(e,t){throw"NotImplementedError"},Sao.PYSON.PYSON.init_from_object=function(e){throw"NotImplementedError"},Sao.PYSON.Encoder=Sao.class_(Object,{prepare:function(e,t,i){if(null!=e)if(e instanceof Array)for(var n=0,o=(e=jQuery.extend([],e)).length;n<o;n++)this.prepare(e[n],n,e);else if(moment.isMoment(e))e=(e.isDate?new Sao.PYSON.Date(e.year(),e.month()+1,e.date()):new Sao.PYSON.DateTime(e.year(),e.month()+1,e.date(),e.hours(),e.minutes(),e.seconds(),1e3*e.milliseconds())).pyson();else if(moment.isDuration(e))e=new Sao.PYSON.TimeDelta(Math.round(e.asDays()),e.seconds(),1e3*e.milliseconds()).pyson();else if(e instanceof Sao.Decimal)e=e.valueOf();else if(e instanceof Object&&!(e instanceof Sao.PYSON.PYSON))for(var s in e=jQuery.extend({},e))this.prepare(e[s],s,e);return i&&(i[t]=e),i||e},encode:function(e){return e=this.prepare(e),JSON.stringify(e,(e,t)=>t instanceof Sao.PYSON.PYSON?this.prepare(t.pyson()):null==t?null:t)}}),Sao.PYSON.Decoder=Sao.class_(Object,{init:function(e,t){this.__context=e||{},this.noeval=t||!1},decode:function(e){return JSON.parse(e,(e,t)=>{if("object"==typeof t&&null!==t){var i,n=Sao.PYSON[t.__class__];if(n)return this.noeval?(delete(i=jQuery.extend({},t)).__class__,Sao.PYSON[t.__class__].init_from_object(i)):n.eval_(t,this.__context)}return t})}}),Sao.PYSON.eval.Eval=function(e,t){return new Sao.PYSON.Eval(e,t)},Sao.PYSON.Eval=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t=""){Sao.PYSON.Eval._super.init.call(this),this._value=e,this._default=t},pyson:function(){return{__class__:"Eval",v:this._value,d:this._default}},types:function(){return this._default instanceof Sao.PYSON.PYSON?this._default.types():[typeof this._default]},__string_params__:function(){return[this._value,this._default]},get basename(){var e=this._value,t=(e=e.startsWith("_parent_")?e.slice("_parent_".length):e).indexOf(".");return e=0<=t?e.substring(0,t):e}}),Sao.PYSON.Eval.eval_=function(e,t){var i=e.v.indexOf(".");return 0<=i&&!(e.v in t)?Sao.PYSON.Eval.eval_({v:e.v.substring(i+1),d:e.d},t[e.v.substring(0,i)]||{}):e.v in t&&void 0!==t[e.v]?t[e.v]:e.d},Sao.PYSON.Eval.init_from_object=function(e){return new Sao.PYSON.Eval(e.v,e.d)},Sao.PYSON.eval.Not=function(e){return new Sao.PYSON.Not(e)},Sao.PYSON.Not=Sao.class_(Sao.PYSON.PYSON,{init:function(e){Sao.PYSON.Not._super.init.call(this),e instanceof Sao.PYSON.PYSON?(jQuery(e.types()).not(["boolean","object"]).length||jQuery(["boolean"]).not(e.types()).length)&&(e=new Sao.PYSON.Bool(e)):"boolean"!=typeof e&&(e=new Sao.PYSON.Bool(e)),this._value=e},pyson:function(){return{__class__:"Not",v:this._value}},types:function(){return["boolean"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Not.eval_=function(e,t){return!Sao.PYSON.Bool.eval_(e,t)},Sao.PYSON.Not.init_from_object=function(e){return new Sao.PYSON.Not(e.v)},Sao.PYSON.eval.Bool=function(e){return new Sao.PYSON.Bool(e)},Sao.PYSON.Bool=Sao.class_(Sao.PYSON.PYSON,{init:function(e){Sao.PYSON.Bool._super.init.call(this),this._value=e},pyson:function(){return{__class__:"Bool",v:this._value}},types:function(){return["boolean"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Bool.eval_=function(e,t){return moment.isMoment(e.v)&&e.v.isTime?Boolean(e.v.hour()||e.v.minute()||e.v.second()||e.v.millisecond()):moment.isDuration(e.v)||e.v instanceof Number?Boolean(e.v.valueOf()):e.v instanceof Object?!jQuery.isEmptyObject(e.v):Boolean(e.v)},Sao.PYSON.Bool.init_from_object=function(e){return new Sao.PYSON.Bool(e.v)},Sao.PYSON.eval.And=function(){return Sao.PYSON.And.new_(arguments)},Sao.PYSON.And=Sao.class_(Sao.PYSON.PYSON,{init:function(){var e=jQuery.extend([],arguments);Sao.PYSON.And._super.init.call(this);for(var t=0,i=e.length;t<i;t++){var n=e[t];n instanceof Sao.PYSON.PYSON?(jQuery(n.types()).not(["boolean"]).length||jQuery(["boolean"]).not(n.types()).length)&&(e[t]=new Sao.PYSON.Bool(n)):"boolean"!=typeof n&&(e[t]=new Sao.PYSON.Bool(n))}if(e.length<2)throw"must have at least 2 statements";this._statements=e},pyson:function(){return{__class__:"And",s:this._statements}},types:function(){return["boolean"]},__string_params__:function(){return this._statements}}),Sao.PYSON.And.eval_=function(e,t){var i=!0;for(const n of e.s)i=i&&n;return i},Sao.PYSON.And.init_from_object=function(e){return Sao.PYSON.And.new_(e.s)},Sao.PYSON.eval.Or=function(){return Sao.PYSON.Or.new_(arguments)},Sao.PYSON.Or=Sao.class_(Sao.PYSON.And,{pyson:function(){var e=Sao.PYSON.Or._super.pyson.call(this);return e.__class__="Or",e}}),Sao.PYSON.Or.eval_=function(e,t){var i=!1;for(const n of e.s)i=i||n;return i},Sao.PYSON.Or.init_from_object=function(e){return new Sao.PYSON.Or.new_(e.s)},Sao.PYSON.eval.Equal=function(e,t){return new Sao.PYSON.Equal(e,t)},Sao.PYSON.Equal=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t){var i,n;if(Sao.PYSON.Equal._super.init.call(this),i=e instanceof Sao.PYSON.PYSON?e.types():[typeof e],n=t instanceof Sao.PYSON.PYSON?t.types():[typeof t],jQuery(i).not(n).length||jQuery(n).not(i).length)throw"statements must have the same type";this._statement1=e,this._statement2=t},pyson:function(){return{__class__:"Equal",s1:this._statement1,s2:this._statement2}},types:function(){return["boolean"]},__string_params__:function(){return[this._statement1,this._statement2]}}),Sao.PYSON.Equal.eval_=function(e,t){return e.s1 instanceof Array&&e.s2 instanceof Array?Sao.common.compare(e.s1,e.s2):moment.isMoment(e.s1)&&moment.isMoment(e.s2)?e.s1.isDate==e.s2.isDate&&e.s1.isDateTime==e.s2.isDateTime&&e.s1.valueOf()==e.s2.valueOf():moment.isDuration(e.s1)&&moment.isDuration(e.s2)?e.s1.valueOf()==e.s2.value():e.s1==e.s2},Sao.PYSON.Equal.init_from_object=function(e){return new Sao.PYSON.Equal(e.s1,e.s2)},Sao.PYSON.eval.Greater=function(e,t,i){return new Sao.PYSON.Greater(e,t,i)},Sao.PYSON.Greater=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t,i=!1){Sao.PYSON.Greater._super.init.call(this);for(var n=[e,t],o=0;o<2;o++){var s=n[o];if(s instanceof Sao.PYSON.PYSON){if(!(s instanceof Sao.PYSON.DateTime||s instanceof Sao.PYSON.Date||s instanceof Sao.PYSON.TimeDelta)&&jQuery(s.types()).not(["number","object"]).length)throw"statement must be an integer, float, date, datetime or timedelta"}else if(!~["number","object"].indexOf(typeof s))throw"statement must be an integer, float, date, datetime or timedelta"}i instanceof Sao.PYSON.PYSON?(jQuery(i.types()).not(["boolean"]).length||jQuery(["boolean"]).not(i.types()).length)&&(i=new Sao.PYSON.Bool(i)):"boolean"!=typeof i&&(i=new Sao.PYSON.Bool(i)),this._statement1=e,this._statement2=t,this._equal=i},pyson:function(){return{__class__:"Greater",s1:this._statement1,s2:this._statement2,e:this._equal}},types:function(){return["boolean"]},__string_params__:function(){return[this._statement1,this._statement2,this._equal]}}),Sao.PYSON.Greater._convert=function(e){for(var t=[(e=jQuery.extend({},e)).s1,e.s2],i=0;i<2;i++)moment.isMoment(t[i])||moment.isDuration(t[i])?t[i]=t[i].valueOf():t[i]=Number(t[i]);return e.s1=t[0],e.s2=t[1],e},Sao.PYSON.Greater.eval_=function(e,t){return null!=e.s1&&null!=e.s2&&((e=Sao.PYSON.Greater._convert(e)).e?e.s1>=e.s2:e.s1>e.s2)},Sao.PYSON.Greater.init_from_object=function(e){return new Sao.PYSON.Greater(e.s1,e.s2,e.e)},Sao.PYSON.eval.Less=function(e,t,i){return new Sao.PYSON.Less(e,t,i)},Sao.PYSON.Less=Sao.class_(Sao.PYSON.Greater,{pyson:function(){var e=Sao.PYSON.Less._super.pyson.call(this);return e.__class__="Less",e}}),Sao.PYSON.Less._convert=Sao.PYSON.Greater._convert,Sao.PYSON.Less.eval_=function(e,t){return null!=e.s1&&null!=e.s2&&((e=Sao.PYSON.Less._convert(e)).e?e.s1<=e.s2:e.s1<e.s2)},Sao.PYSON.Less.init_from_object=function(e){return new Sao.PYSON.Less(e.s1,e.s2,e.e)},Sao.PYSON.eval.If=function(e,t,i){return new Sao.PYSON.If(e,t,i)},Sao.PYSON.If=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t,i=null){Sao.PYSON.If._super.init.call(this),e instanceof Sao.PYSON.PYSON?(jQuery(e.types()).not(["boolean"]).length||jQuery(["boolean"]).not(e.types()).length)&&(e=new Sao.PYSON.Bool(e)):"boolean"!=typeof e&&(e=new Sao.PYSON.Bool(e)),t instanceof Sao.PYSON.PYSON&&t.types(),i instanceof Sao.PYSON.PYSON&&i.types(),this._condition=e,this._then_statement=t,this._else_statement=i},pyson:function(){return{__class__:"If",c:this._condition,t:this._then_statement,e:this._else_statement}},types:function(){var e=this._then_statement instanceof Sao.PYSON.PYSON?this._then_statement.types():[typeof this._then_statement];if(this._else_statement instanceof Sao.PYSON.PYSON)for(const i of this._else_statement.types())~e.indexOf(i)||e.push(i);else{var t=typeof this._else_statement;~e.indexOf(t)||e.push(t)}return e},__string_params__:function(){return[this._condition,this._then_statement,this._else_statement]}}),Sao.PYSON.If.eval_=function(e,t){return e.c?e.t:e.e},Sao.PYSON.If.init_from_object=function(e){return new Sao.PYSON.If(e.c,e.t,e.e)},Sao.PYSON.eval.Get=function(e,t,i){return new Sao.PYSON.Get(e,t,i)},Sao.PYSON.Get=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t,i=null){if(Sao.PYSON.Get._super.init.call(this),e instanceof Sao.PYSON.PYSON){if(jQuery(e.types()).not(["object"]).length||jQuery(["object"]).not(e.types()).length)throw"obj must be a dict"}else if(!(e instanceof Object))throw"obj must be a dict";if(this._obj=e,t instanceof Sao.PYSON.PYSON){if(jQuery(t.types()).not(["string"]).length||jQuery(["string"]).not(t.types()).length)throw"key must be a string"}else if("string"!=typeof t)throw"key must be a string";this._key=t,this._default=i},pyson:function(){return{__class__:"Get",v:this._obj,k:this._key,d:this._default}},types:function(){return this._default instanceof Sao.PYSON.PYSON?this._default.types():[typeof this._default]},__string_params__:function(){return[this._obj,this._key,this._default]}}),Sao.PYSON.Get.eval_=function(e,t){return e.k in e.v?e.v[e.k]:e.d},Sao.PYSON.Get.init_from_object=function(e){return new Sao.PYSON.Get(e.v,e.k,e.d)},Sao.PYSON.eval.In=function(e,t){return new Sao.PYSON.In(e,t)},Sao.PYSON.In=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t){if(Sao.PYSON.In._super.init.call(this),e instanceof Sao.PYSON.PYSON){if(jQuery(e.types()).not(["string","number"]).length)throw"key must be a string or a number"}else if(!~["string","number"].indexOf(typeof e))throw"key must be a string or a number";if(t instanceof Sao.PYSON.PYSON){if(jQuery(t.types()).not(["object"]).length||jQuery(["object"]).not(t.types()).length)throw"obj must be a dict or a list"}else if(!(t instanceof Object))throw"obj must be a dict or a list";this._key=e,this._obj=t},pyson:function(){return{__class__:"In",k:this._key,v:this._obj}},types:function(){return["boolean"]},__string_params__:function(){return[this._key,this._obj]}}),Sao.PYSON.In.eval_=function(e,t){return!!e.v&&(e.v.indexOf?Boolean(~e.v.indexOf(e.k)):!!e.v[e.k])},Sao.PYSON.In.init_from_object=function(e){return new Sao.PYSON.In(e.k,e.v)},Sao.PYSON.eval.Date=function(e,t,i,n,o,s){return new Sao.PYSON.Date(e,t,i,n,o,s)},Sao.PYSON.Date=Sao.class_(Sao.PYSON.PYSON,{init:function(e=null,t=null,i=null,n=0,o=0,s=0,a=null){Sao.PYSON.Date._super.init.call(this),this._test(e,"year"),this._test(t,"month"),this._test(i,"day"),this._test(n,"delta_years"),this._test(s,"delta_days"),this._test(o,"delta_months"),this._year=e,this._month=t,this._day=i,this._delta_years=n,this._delta_months=o,this._delta_days=s,this._start=a},pyson:function(){return{__class__:"Date",y:this._year,M:this._month,d:this._day,dy:this._delta_years,dM:this._delta_months,dd:this._delta_days,start:this._start}},types:function(){return["object"]},_test:function(e,t){if(e instanceof Sao.PYSON.PYSON){if(jQuery(e.types()).not(["number","object"]).length)throw t+" must be an integer or None"}else if("number"!=typeof e&&null!==e)throw t+" must be an integer or None"},__string_params__:function(){return[this._year,this._month,this._day,this._delta_years,this._delta_months,this._delta_days,this._start]}}),Sao.PYSON.Date.eval_=function(e,t){var i=e.start;return(i=i&&i.isDateTime?Sao.Date(i.year(),i.month(),i.date()):i)&&i.isDate||(i=Sao.Date()),e.y&&i.year(e.y),e.M&&i.month(e.M-1),e.d&&i.date(e.d),e.dy&&i.add(e.dy,"y"),e.dM&&i.add(e.dM,"M"),e.dd&&i.add(e.dd,"d"),i},Sao.PYSON.Date.init_from_object=function(e){return new Sao.PYSON.Date(e.y,e.M,e.d,e.dy,e.dM,e.dd,e.start)},Sao.PYSON.eval.DateTime=function(e,t,i,n,o,s,a,r,l,c,d,h,u,_){return new Sao.PYSON.DateTime(e,t,i,n,o,s,a,r,l,c,d,h,u,_)},Sao.PYSON.DateTime=Sao.class_(Sao.PYSON.Date,{init:function(e=null,t=null,i=null,n=null,o=null,s=null,a=null,r=0,l=0,c=0,d=0,h=0,u=0,_=0,m=null){Sao.PYSON.DateTime._super.init.call(this,e,t,i,r,l,c,m),this._test(n,"hour"),this._test(o,"minute"),this._test(s,"second"),this._test(a,"microsecond"),this._test(d,"delta_hours"),this._test(h,"delta_minutes"),this._test(u,"delta_seconds"),this._test(_,"delta_microseconds"),this._hour=n,this._minute=o,this._second=s,this._microsecond=a,this._delta_hours=d,this._delta_minutes=h,this._delta_seconds=u,this._delta_microseconds=_},pyson:function(){var e=Sao.PYSON.DateTime._super.pyson.call(this);return e.__class__="DateTime",e.h=this._hour,e.m=this._minute,e.s=this._second,e.ms=this._microsecond,e.dh=this._delta_hours,e.dm=this._delta_minutes,e.ds=this._delta_seconds,e.dms=this._delta_microseconds,e},__string_params__:function(){var e=Sao.PYSON.DateTime._super.__string_params__.call(this);return[e[0],e[1],e[2],this._hour,this._minute,this._second,this._microsecond,e[3],e[4],e[5],this._delta_hours,this._delta_minutes,this._delta_seconds,this._delta_microseconds,e[6]]}}),Sao.PYSON.DateTime.eval_=function(e,t){var i=e.start;return(i=i&&i.isDate?Sao.DateTime.combine(i,Sao.Time()):i)&&i.isDateTime||(i=Sao.DateTime()).utc(),e.y&&i.year(e.y),e.M&&i.month(e.M-1),e.d&&i.date(e.d),null!==e.h&&i.hour(e.h),null!==e.m&&i.minute(e.m),null!==e.s&&i.second(e.s),null!==e.ms&&i.milliseconds(e.ms/1e3),e.dy&&i.add(e.dy,"y"),e.dM&&i.add(e.dM,"M"),e.dd&&i.add(e.dd,"d"),e.dh&&i.add(e.dh,"h"),e.dm&&i.add(e.dm,"m"),e.ds&&i.add(e.ds,"s"),e.dms&&i.add(e.dms/1e3,"ms"),i},Sao.PYSON.DateTime.init_from_object=function(e){return new Sao.PYSON.DateTime(e.y,e.M,e.d,e.h,e.m,e.s,e.ms,e.dy,e.dM,e.dd,e.dh,e.dm,e.ds,e.dms)},Sao.PYSON.eval.TimeDelta=function(e,t,i){return new Sao.PYSON.TimeDelta(e,t,i)},Sao.PYSON.TimeDelta=Sao.class_(Sao.PYSON.PYSON,{init:function(e=0,t=0,i=0){function n(e,t){if(e instanceof Sao.PYSON.TimeDelta){if(jQuery(e.types()).not(["number"]).length)throw t+" must be an integer"}else if("number"!=typeof e)throw t+" must be an integer";return e}Sao.PYSON.TimeDelta._super.init.call(this),this._days=n(e,"days"),this._seconds=n(t,"seconds"),this._microseconds=n(i,"microseconds")},pyson:function(){return{__class__:"TimeDelta",d:this._days,s:this._seconds,m:this._microseconds}},types:function(){return["object"]},__string_params__:function(){return[this._days,this._seconds,this._microseconds]}}),Sao.PYSON.TimeDelta.eval_=function(e,t){return Sao.TimeDelta(e.d,e.s,e.m/1e3)},Sao.PYSON.TimeDelta.init_from_object=function(e){return new Sao.PYSON.TimeDelta(e.d,e.s,e.microseconds)},Sao.PYSON.eval.Len=function(e){return new Sao.PYSON.Len(e)},Sao.PYSON.Len=Sao.class_(Sao.PYSON.PYSON,{init:function(e){if(Sao.PYSON.Len._super.init.call(this),e instanceof Sao.PYSON.PYSON){if(jQuery(e.types()).not(["object","string"]).length||jQuery(["object","string"]).not(e.types()).length)throw"value must be an object or a string"}else if("object"!=typeof e&&"string"!=typeof e)throw"value must be an object or a string";this._value=e},pyson:function(){return{__class__:"Len",v:this._value}},types:function(){return["integer"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Len.eval_=function(e,t){return("object"==typeof e.v?Object.keys(e.v):e.v).length},Sao.PYSON.Len.init_from_object=function(e){return new Sao.PYSON.Len(e.v)}}(),!function(){"use strict";Sao.Session=Sao.class_(Object,{init:function(e,t){this.login_service=null,this.user_id=null,this.session=null,this.cache=new i,this.prm=jQuery.when(),this.database=e,this.login=t,this.restore(),this.context={},this.restore_context(),Sao.Session.current_session||(Sao.Session.current_session=this)},get_auth:function(){return e=this.login+":"+this.user_id+":"+this.session,window.btoa(unescape(encodeURIComponent(e)));var e},do_login:function(e){var t=jQuery.Deferred(),i=this.login,n=JSON.parse(localStorage.getItem("sao_device_cookies")),o=null;n&&n[this.database]&&(o=n[this.database][this.login]);return new Sao.Login(function(e){return e.device_cookie=o,{method:"common.db.login",params:[i,e,Sao.i18n.getlang()]}},this).run().then(e=>{this.login=i,this.user_id=e[0],this.session=e[1],this.store(),this.renew_device_cookie(),t.resolve()},()=>{this.user_id=null,this.session=null,this.store(),t.reject()}),t.promise()},do_logout:function(){var e;return this.user_id&&this.session?(e=jQuery.ajax({headers:{Authorization:"Session "+this.get_auth()},contentType:"application/json",data:JSON.stringify({id:0,method:"common.db.logout",params:[]}),dataType:"json",url:"/"+this.database+"/",type:"post"}),this.unstore(),this.database=null,this.login=null,this.user_id=null,this.session=null,Sao.Session.current_session===this&&(Sao.Session.current_session=null),e):jQuery.when()},reload_context:function(){var e={method:"model.res.user.get_preferences",params:[!0,this.context]};return this.reset_context(),Sao.rpc(e,this).then(e=>{jQuery.extend(this.context,e),this.store_context()})},reset_context:function(){this.context={client:Sao.Bus.id}},restore_context:function(){this.reset_context();var e=sessionStorage.getItem("sao_context_"+this.database);null!==e&&jQuery.extend(this.context,Sao.rpc.convertJSONObject(JSON.parse(e)))},store_context:function(){var e=jQuery.extend({},this.context);delete e.client,e=JSON.stringify(Sao.rpc.prepareObject(e)),sessionStorage.setItem("sao_context_"+this.database,e)},restore:function(){var e;this.database&&!this.session&&null!==(e=localStorage.getItem("sao_session_"+this.database))&&(e=JSON.parse(e),this.login&&this.login!=e.login||(this.login_service=e.login_service,this.login=e.login,this.user_id=e.user_id,this.session=e.session))},store:function(){var e={login:this.login,user_id:this.user_id,session:this.session},e=JSON.stringify(e);localStorage.setItem("sao_session_"+this.database,e)},unstore:function(){localStorage.removeItem("sao_session_"+this.database)},renew_device_cookie:function(){var t=JSON.parse(localStorage.getItem("sao_device_cookies")),e=t&&this.database in t?t[this.database][this.login]:null,e=Sao.rpc({method:"model.res.user.device.renew",params:[e,{}]},this);e.done(e=>{t=(t=JSON.parse(localStorage.getItem("sao_device_cookies")))||{},this.database in t||(t[this.database]={}),t[this.database][this.login]=e,localStorage.setItem("sao_device_cookies",JSON.stringify(t))}),e.fail(()=>{Sao.Logger.error("Cannot renew device cookie")})}}),Sao.Session.server_version=function(){var e=Sao.common.processing.show();return jQuery.ajax({contentType:"application/json",data:JSON.stringify({id:0,method:"common.server.version",params:[]}),dataType:"json",url:"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}).then(function(e){return e.result})},Sao.Session.login_dialog=function(){var e=new Sao.Dialog(Sao.i18n.gettext("Login"),"login-dialog","md",!0,Sao.__version__);return e.database_select=jQuery("<select/>",{class:"form-control",id:"database",name:"database"}).hide(),e.database_input=jQuery("<input/>",{class:"form-control",id:"database",name:"database"}).hide(),e.login_input=jQuery("<input/>",{class:"form-control",id:"login",name:"login"}),e.button=jQuery("<button/>",{class:"btn btn-primary btn-block",type:"submit",title:Sao.i18n.gettext("Login")}).text(" "+Sao.i18n.gettext("Login")),e.body.append(jQuery("<div/>",{class:"form-group"}).append(jQuery("<label/>",{class:"control-label",for:"database"}).text(Sao.i18n.gettext("Database"))).append(e.database_select).append(e.database_input)).append(jQuery("<div/>",{class:"panel panel-default"}).append(jQuery("<div/>",{class:"panel-body"}).append(jQuery("<div/>",{class:"form-group"}).append(jQuery("<label/>",{class:"control-label",for:"login"}).text(Sao.i18n.gettext("User name"))).append(e.login_input)).append(e.button))),e},Sao.Session.get_credentials=function(){function a(){return window.location.hash.replace(/^(#(!|))/,"").split("/",1)[0]||null}var r,l,c,o,d=jQuery.Deferred(),i=a(),h=new Sao.Session(i,null);return h.session?(d.resolve(h),d):(r=Sao.Session.login_dialog(),l=function(){return r.modal.find("input,select").filter(":visible:not([readonly])").filter(function(){return!jQuery(this).val()})},r.modal.modal({backdrop:!(o=function(e){var t=r.database_select.val()||r.database_input.val();if(r.modal.find(".has-error").removeClass("has-error"),t){c();var i=window.location.protocol+"//"+window.location.host,n=new URL(i+"/"),i=(n.searchParams.append("login_service",e.data),new URL(i+"/"+t+e.data)),o=(i.searchParams.append("next",n.href),window.open(i.href,"_blank","popup=1"));const s=window.setInterval(()=>{o.closed&&(window.clearInterval(s),h.database=t,h.restore(),h.session?(d.resolve(h),r.modal.remove(),a()!=t&&(window.location="#"+t)):(c(!1),l().first().focus()))},500)}else r.database_select.closest(".form-group").addClass("has-error")}),keyboard:!(c=function(e=!0){r.body.find("input,select,button").prop("disabled",e)})}),r.modal.find("form").unbind().submit(function(e){var t;e.preventDefault(),e=r.login_input.val(),t=r.database_select.val()||r.database_input.val(),r.modal.find(".has-error").removeClass("has-error"),e&&t?(r.button.focus(),c(),h.database=t,h.login=e,h.restore(),(h.session?jQuery.when():h.do_login()).then(function(){r.modal.modal("hide"),d.resolve(h),r.modal.remove(),a()!=t&&(window.location="#"+t)},function(){c(!1),l().closest(".form-group").addClass("has-error"),l().first().focus()})):l().closest(".form-group").addClass("has-error")}),r.modal.on("shown.bs.modal",function(){l().first().focus()}),jQuery.when(Sao.DB.list()).then(function(e){var t;if(1==(e=e||[]).length)i=e[0],t=r.database_input;else{t=r.database_select;for(const i of e)t.append(jQuery("<option/>",{value:i,text:i}))}t.prop("readonly",1==e.length),t.show(),t.val(i||"")},function(){r.database_input.show()}),jQuery.when(Sao.Authentication.services()).then(function(e){if(e.length){var t,i,n=jQuery("<div/>",{class:"panel-body"}).append(jQuery("<p/>").text(Sao.i18n.gettext("Login with")));r.body.append(jQuery("<div/>",{class:"panel panel-default"}).append(n));for([t,i]of e)n.append(jQuery("<button/>",{class:"btn btn-block btn-default",type:"button"}).text(t).click(i,o))}}),d.promise())},Sao.Session.renew=function(e){if("pending"!=e.prm.state()){var t=jQuery.Deferred();if(e.session=null,e.prm=t.promise(),e.login_service){e.unstore();var i=window.location.protocol+"//"+window.location.host,n=new URL(i+"/"),i=(n.searchParams.append("login_service",e.login_service),n.searchParams.append("renew",e.user_id),new URL(i+"/"+e.database+e.login_service)),o=(i.searchParams.append("next",n.href),window.open(i.href,"_blank","popup=1"));const s=window.setInterval(()=>{o.closed&&(window.clearInterval(s),e.restore(),e.session?t.resolve():(Sao.logout(),t.reject()))},500)}else e.do_login().then(t.resolve,function(){Sao.logout(),t.reject()});t.done(function(){Sao.Bus.listen()})}return e.prm},Sao.Session.current_session=null,Sao.Login=Sao.class_(Object,{init:function(e,t){this.func=e,this.session=t||Sao.Session.current_session},run:function(o={}){var s=jQuery.Deferred(),e=Sao.common.processing.show(),t=this.func(o),t=(t.id=0,{contentType:"application/json",data:JSON.stringify(t),dataType:"json",url:"/"+this.session.database+"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}),t=(this.session.user_id&&this.session.session&&(t.headers={Authorization:"Session "+this.session.get_auth()}),jQuery.ajax(t));return t.done(function(e){if(null===e)Sao.common.warning.run("",Sao.i18n.gettext("Unable to reach the server.")),s.reject();else if(e.error){if(e.error[0].startsWith("401"))return this.run({}).then(s.resolve,s.reject);var t,i,n;e.error[0].startsWith("429")?Sao.common.message.run(Sao.i18n.gettext("Too many requests. Try again later."),"tryton-error").always(s.resolve):e.error[0].startsWith("404")?Sao.common.message.run(Sao.i18n.gettext("Not found."),"tryton-error").always(s.reject):"LoginException"!=e.error[0]?Sao.common.error.run(e.error[0],e.error[1]).always(s.reject):(t=e.error[1],i=t[0],n=t[1],this["get_"+t[2]](n,i).then(e=>(o[i]=e,this.run(o).then(s.resolve,s.reject)),s.reject))}else s.resolve(e.result)}.bind(this)),t.fail(function(e,t,i){401==e.status?this.run({}).then(s.resolve,s.reject):429==e.status?Sao.common.message.run(Sao.i18n.gettext("Too many requests. Try again later."),"tryton-error").always(s.resolve):(404==e.status?Sao.common.message.run(Sao.i18n.gettext("Not found."),"tryton-error"):Sao.common.error.run(t,i)).always(s.reject)}.bind(this)),s.promise()},get_char:function(e,t){return Sao.common.ask.run(e,t)},get_password:function(e,t){return Sao.common.ask.run(e,t,!1)}});var i=Sao.class_(Object,{init:function(){this.store={}},cached:function(e){return e in this.store},set:function(e,t,i,n){i=new Date((new Date).getTime()+1e3*i),Sao.setdefault(this.store,e,{})[t]={expire:i,value:JSON.stringify(Sao.rpc.prepareObject(n))}},get:function(e,t){var i=new Date,n=Sao.setdefault(this.store,e,{})[t];if(n){if(!(n.expire<i))return Sao.Logger.info("(cached)",e,t),Sao.rpc.convertJSONObject(jQuery.parseJSON(n.value));delete this.store[e][t]}},clear:function(e){e?this.store[e]={}:this.store={}}});Sao.DB={},Sao.DB.list=function(){var e=Sao.common.processing.show();return jQuery.ajax({contentType:"application/json",data:JSON.stringify({id:0,method:"common.db.list",params:[]}),dataType:"json",url:"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}).then(function(e){return e.result})},Sao.Authentication={},Sao.Authentication.services=function(){var e=Sao.common.processing.show();return jQuery.ajax({contentType:"application/json",data:JSON.stringify({id:0,method:"common.authentication.services",params:[]}),dataType:"json",url:"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}).then(function(e){return Sao.Authentication.services=function(){return e.result},e.result})}}(),!function(){"use strict";Sao.common={},Sao.common.BACKSPACE_KEYCODE=8,Sao.common.TAB_KEYCODE=9,Sao.common.RETURN_KEYCODE=13,Sao.common.ESC_KEYCODE=27,Sao.common.UP_KEYCODE=38,Sao.common.DOWN_KEYCODE=40,Sao.common.DELETE_KEYCODE=46,Sao.common.F2_KEYCODE=113,Sao.common.F3_KEYCODE=114,Sao.common.SELECTION_NONE=1,Sao.common.SELECTION_SINGLE=2,Sao.common.SELECTION_MULTIPLE=3,Sao.common.compare=function(e,t){if(e.length!=t.length)return!1;for(var i=0;i<e.length;i++){var n=e[i],o=t[i];if(n instanceof Array&&o instanceof Array){if(!Sao.common.compare(n,o))return!1}else if(moment.isMoment(n)&&moment.isMoment(o)){if(n.isDate!=o.isDate&&n.isDateTime!=o.isDateTime&&n.valueOf()!=o.valueOf())return!1}else if(moment.isDuration(n)&&moment.isDuration(o)){if(n.valueOf()!=o.valueOf())return!1}else if(n instanceof Number||o instanceof Number){if(Number(n)!==Number(o))return!1}else if(n!=o)return!1}return!0},Sao.common.contains=function(e,t){for(var i=0;i<e.length;i++)if(Sao.common.compare(e[i],t))return!0;return!1},Sao.common.intersect=function(e,t){for(var i=0,n=0,o=[];i<e.length&&n<t.length;)e[i]<t[n]?i++:(e[i]>t[n]||(o.push(e[i]),i++),n++);return o},Sao.common.scrollIntoViewIfNeeded=function(e){var t;(e=e[0])&&((t=e.getBoundingClientRect()).bottom>window.innerHeight&&e.scrollIntoView(!1),t.top<0)&&e.scrollIntoView()},Sao.common.click_press=function(i,n){return function e(t){if("keypress"!=t.type||t.which==Sao.common.RETURN_KEYCODE)return n&&jQuery(this).off("click keypress",null,e),i(t)}},Sao.common.product=function(e,t){t=t||1;for(var i=[],n=0;n<t;)i=i.concat(e),n++;var o=[[]];for(const a of i){var s=[];for(const r of o)for(const l of a)s.push(r.concat([l]));o=s}return o},Sao.common.selection=function(e,t,i=!1){var n,o,s=jQuery.Deferred();return jQuery.isEmptyObject(t)?s.reject():1!=(n=Object.keys(t).sort()).length||i?(o=new Sao.Dialog(e||Sao.i18n.gettext("Your selection:"),"selection-dialog"),n.forEach(function(e,t){jQuery("<div/>",{class:"radio"}).append(jQuery("<label/>").text(" "+e).prepend(jQuery("<input/>",{type:"radio",name:"selection",value:t}))).appendTo(o.body)}),o.body.find("input").first().prop("checked",!0),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(function(){o.modal.modal("hide"),s.reject()}).appendTo(o.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(function(){var e=o.body.find("input:checked").attr("value");o.modal.modal("hide"),s.resolve(t[n[e]])}).appendTo(o.footer),o.modal.on("hidden.bs.modal",function(e){jQuery(this).remove()}),o.modal.modal("show")):(i=n[0],s.resolve(t[i])),s},Sao.common.moment_format=function(e){return e.replace("%a","ddd").replace("%A","dddd").replace("%w","d").replace("%d","DD").replace("%b","MMM").replace("%B","MMMM").replace("%m","MM").replace("%y","YY").replace("%Y","YYYY").replace("%H","HH").replace("%I","hh").replace("%p","A").replace("%M","mm").replace("%S","ss").replace("%f","SSS").replace("%z","ZZ").replace("%Z","zz").replace("%j","DDDD").replace("%U","ww").replace("%W","WW").replace("%c","llll").replace("%x","L").replace("%X","LTS").replace("%","%%")},Sao.common.DATE_OPERATORS=[["S",moment.duration(-1,"seconds")],["s",moment.duration(1,"seconds")],["I",moment.duration(-1,"minutes")],["i",moment.duration(1,"minutes")],["H",moment.duration(-1,"hours")],["h",moment.duration(1,"hours")],["D",moment.duration(-1,"days")],["d",moment.duration(1,"days")],["W",moment.duration(-1,"weeks")],["w",moment.duration(1,"weeks")],["M",moment.duration(-1,"months")],["m",moment.duration(1,"months")],["Y",moment.duration(-1,"years")],["y",moment.duration(1,"years")]],Sao.common.date_format=function(e){var t;return jQuery.isEmptyObject(e)&&(e="%x",Sao.Session.current_session)&&(t=Sao.Session.current_session.context).locale&&t.locale.date&&(e=t.locale.date),Sao.common.moment_format(e)},Sao.common.format_time=function(e,t){return t?t.format(Sao.common.moment_format(e)):""},Sao.common.parse_time=function(e,t){t=moment(t,Sao.common.moment_format(e));return t=t.isValid()?Sao.Time(t.hour(),t.minute(),t.second(),t.millisecond()):null},Sao.common.format_date=function(e,t){return t?t.format(Sao.common.moment_format(e)):""},Sao.common.parse_date=function(e,t){t=moment(t,Sao.common.moment_format(e));return t=t.isValid()?Sao.Date(t.year(),t.month(),t.date()):null},Sao.common.format_datetime=function(e,t){return t?t.format(Sao.common.moment_format(e)):""},Sao.common.parse_datetime=function(e,t){t=moment(t,Sao.common.moment_format(e));return t=t.isValid()?Sao.DateTime(t.year(),t.month(),t.date(),t.hour(),t.minute(),t.second(),t.millisecond()):null},Sao.common.timedelta={},Sao.common.timedelta.DEFAULT_CONVERTER={s:1},Sao.common.timedelta.DEFAULT_CONVERTER.m=60*Sao.common.timedelta.DEFAULT_CONVERTER.s,Sao.common.timedelta.DEFAULT_CONVERTER.h=60*Sao.common.timedelta.DEFAULT_CONVERTER.m,Sao.common.timedelta.DEFAULT_CONVERTER.d=24*Sao.common.timedelta.DEFAULT_CONVERTER.h,Sao.common.timedelta.DEFAULT_CONVERTER.w=7*Sao.common.timedelta.DEFAULT_CONVERTER.d,Sao.common.timedelta.DEFAULT_CONVERTER.M=30*Sao.common.timedelta.DEFAULT_CONVERTER.d,Sao.common.timedelta.DEFAULT_CONVERTER.Y=365*Sao.common.timedelta.DEFAULT_CONVERTER.d,Sao.common.timedelta._get_separator=function(){return{Y:Sao.i18n.gettext("Y"),M:Sao.i18n.gettext("M"),w:Sao.i18n.gettext("w"),d:Sao.i18n.gettext("d"),h:Sao.i18n.gettext("h"),m:Sao.i18n.gettext("m"),s:Sao.i18n.gettext("s")}},Sao.common.timedelta.format=function(e,t){if(!e)return"";t=t||Sao.common.timedelta.DEFAULT_CONVERTER;for(var i,n,o=[],s="",a=((e=e.asSeconds())<0&&(s="-"),e=Math.abs(e),t=Object.keys(Sao.common.timedelta._get_separator()).map(function(e){return[e,t[e]]}),[]),r=0;r<t.length;r++){var l,c,d=t[r][0];(c=t[r][1])?(e-=(l=Math.floor(e/c))*c,a.push(l)):a.push(0)}for(r=0;r<t.length-3;r++)d=t[r][0],(c=a[r])&&o.push(c+Sao.common.timedelta._get_separator()[d]);return(jQuery(a.slice(-3)).is(function(e,t){return t})||jQuery.isEmptyObject(o))&&(n=(i=a.slice(-3))[0].toString().padStart(2,"0"),n+=":"+i[1].toString().padStart(2,"0"),(i[2]||e)&&(n+=":"+i[2].toString().padStart(2,"0")),o.push(n)),o=s+o.reduce(function(e,t){return e?e+" "+t:t}),e&&(jQuery(a.slice(-3)).is(function(e,t){return t})||(o+=" "),o+=(""+e.toFixed(6)).slice(1)),o},Sao.common.timedelta.parse=function(e,t){if(!e)return null;t=t||Sao.common.timedelta.DEFAULT_CONVERTER;var i,n,o=Sao.common.timedelta._get_separator();for(n in o)i=o[n],e=e.replace(i,i+" ");for(var s=0,a=e.split(" "),r=0;r<a.length;r++){var l=a[r];if(l.contains(":"))for(var c=l.split(":"),d=[t.h,t.m,t.s],h=0;h<Math.min(c.length,d.length);h++){var u=c[h],_=d[h],m=Math.abs(parseFloat(u))*_;isNaN(m)||(s+=m)}else{var p,f=!1;for(p in o)if(i=o[p],l.endsWith(i)){l=l.slice(0,-i.length),m=Math.abs(parseFloat(l))*t[p],isNaN(m)||(s+=m),f=!0;break}f||(m=Math.abs(parseFloat(l)),isNaN(m))||(s+=m)}}return e.contains("-")&&(s*=-1),Sao.TimeDelta(null,s)},Sao.common.btoa=function(e){for(var t=[],i=0;65535*i<e.length;i++)t.push(String.fromCharCode.apply(null,e.subarray(65535*i,65535*(i+1))));return btoa(t.join(""))},Sao.common.atob=function(e){for(var t=atob(e.base64.replace(/\s/g,"")),e=new ArrayBuffer(t.length),i=new Uint8Array(e),n=0;n<t.length;n++)i[n]=t.charCodeAt(n);return i},Sao.common.ModelAccess=Sao.class_(Object,{init:function(){this.batchnum=100,this._models=[],this._access={}},load_models:function(e){e||(this._access={});try{this._models=Sao.rpc({method:"model.ir.model.list_models",params:[{}]},Sao.Session.current_session,!1)}catch(e){Sao.Logger.error("Unable to get model list.")}},get:function(t){if(void 0===this._access[t]){var i,e=this._models.indexOf(t),e=(e<0&&(this.load_models(!1),e=this._models.indexOf(t)),this._models.slice(Math.max(0,e-Math.floor(this.batchnum/2)),e+Math.floor(this.batchnum/2)));try{i=Sao.rpc({method:"model.ir.model.access.get_access",params:[e,{}]},Sao.Session.current_session,!1)}catch(e){Sao.Logger.error(`Unable to get access for ${t}.`),i={model:{read:!0,write:!1,create:!1,delete:!1}}}this._access=jQuery.extend(this._access,i)}return this._access[t]}}),Sao.common.MODELACCESS=new Sao.common.ModelAccess,Sao.common.ModelHistory=Sao.class_(Object,{init:function(){this._models=[]},load_history:function(){return this._models=[],Sao.rpc({method:"model.ir.model.list_history",params:[{}]},Sao.Session.current_session).then(e=>{this._models=e})},contains:function(e){return~this._models.indexOf(e)}}),Sao.common.MODELHISTORY=new Sao.common.ModelHistory,Sao.common.ModelName=Sao.class_(Object,{init:function(){this._names={}},load_names:function(){this._names=Sao.rpc({method:"model.ir.model.get_names",params:[{}]},Sao.Session.current_session,!1)},get:function(e){return jQuery.isEmptyObject(this._names)&&this.load_names(),this._names[e]||""},clear:function(){this._names={}}}),Sao.common.MODELNAME=new Sao.common.ModelName,Sao.common.ModelNotification=Sao.class_(Object,{init:function(){this._depends=null},load_names:function(){this._depends=Sao.rpc({method:"model.ir.model.get_notification",params:[{}]},Sao.Session.current_session,!1)},get:function(e){return this._depends||this.load_names(),this._depends[e]||[]}}),Sao.common.MODELNOTIFICATION=new Sao.common.ModelNotification,Sao.common.ViewSearch=Sao.class_(Object,{init:function(){this.encoder=new Sao.PYSON.Encoder},load_searches:function(){return this.searches={},Sao.rpc({method:"model.ir.ui.view_search.get",params:[{}]},Sao.Session.current_session).then(e=>{this.searches=e})},get:function(e){return this.searches[e]||[]},add:function(t,i,n){return Sao.rpc({method:"model.ir.ui.view_search.set",params:[i,t,this.encoder.encode(n),{}]},Sao.Session.current_session).then(e=>{void 0===this.searches[t]&&(this.searches[t]=[]),this.searches[t].push([e,i,n,!0])})},remove:function(t,i){return Sao.rpc({method:"model.ir.ui.view_search.unset",params:[i,{}]},Sao.Session.current_session).then(()=>{for(var e=0;e<this.searches[t].length;e++)if(this.searches[t][e][0]===i){this.searches[t].splice(e,1);break}})}}),Sao.common.VIEW_SEARCH=new Sao.common.ViewSearch,Sao.common.humanize=function(i,e){var n,o;if(e=e||"",0<Math.abs(i)&&Math.abs(i)<1)for(let e=0,t=(n=["","m","µ","n","p","f","a","z","y","r","q"]).length;e<t&&(o=n[e],!(.01<=Math.abs(i)));e++)e+1<t&&(i*=1e3);else for(let e=0,t=(n=["","k","M","G","T","P","E","Z","Y","R","Q"]).length;e<t&&(o=n[e],!(Math.abs(i)<=1e3));e++)e+1<t&&(i/=1e3);return(i=i.toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),{minimumFractionDigits:0,maximumFractionDigits:Math.abs(i)<.01?15:2}))+o+e},Sao.common.EvalEnvironment=function(e,t="eval"){var i;if("eval"==t)i=e.get_eval();else for(var n in i={},e.model.fields){var o=e.model.fields[n];i[n]=o.get_on_change_value(e)}return i.id=e.id,e.group.parent&&Object.defineProperty(i,"_parent_"+e.group.parent_name,{enumerable:!0,get:function(){return Sao.common.EvalEnvironment(e.group.parent,t)}}),i.get=function(e,t){return this.hasOwnProperty(e)?this[e]:t},i},Sao.common.selection_mixin={},Sao.common.selection_mixin.init=function(){this.selection=null,this.help=null,this.inactive_selection=[],this._last_domain=null,this._values2selection={},this._domain_cache={},void 0===this.nullable_widget&&(this.nullable_widget=!0)},Sao.common.selection_mixin.init_selection=function(e,t){if(!e){e={};for(const a of this.attributes.selection_change_with||[])e[a]=null}var i=JSON.stringify(e),n=this.attributes.selection||[],o=(this.attributes.help_selection,e=>{e=jQuery.extend([],e),void 0!==this.attributes.sort&&!this.attributes.sort||e.sort(function(e,t){return e[1].localeCompare(t[1])}),this.selection=jQuery.extend([],e),this.help=this.attributes.help_selection||{},t&&t(this.selection,this.help)}),s=n instanceof Array||i in this._values2selection?(o(n=i in this._values2selection?this._values2selection[i]:n),jQuery.when()):(s=(s=jQuery.isEmptyObject(this.attributes.selection_change_with)?this.model.execute(n,[]):this.model.execute(n,[e])).then(e=>this._values2selection[i]=e)).then(o);this.inactive_selection=[],this._selection_prm=s},Sao.common.selection_mixin.update_selection=function(t,i,c){this._selection_prm.done(()=>{var s,a,r,l,e;i?(s=i.get_domain(t),"relation"in this.attributes?(a=i.get_context(t),(r=JSON.stringify([s,a]))in this._domain_cache&&(this.selection=this._domain_cache[r],this._last_domain=[s,a]),null!==this._last_domain&&Sao.common.compare(s,this._last_domain[0])&&JSON.stringify(a)==JSON.stringify(this._last_domain[1])?c&&c(this.selection,this.help):(e=["rec_name"],(l=this.attributes.help_field)&&e.push(l),(e=Sao.rpc({method:"model."+this.attributes.relation+".search_read",params:[s,0,null,null,e,a]},t.model.session,!0,!1)).done(e=>{var t=[];for(const n of e)t.push([n.id,n.rec_name]);this.nullable_widget&&t.push([null,""]);var i={};if(l)for(const o of e)i[o.id]=o[l];this._last_domain=[s,a],this._domain_cache[r]=t,this.selection=jQuery.extend([],t),this.help=i,c&&c(this.selection,this.help)}),e.fail(()=>{var e=[];this.nullable_widget&&e.push([null,""]),this._last_domain=null,this.selection=e,c&&c(this.selection,this.help)}))):(e=this.attributes.selection_change_with||[],delete(e=t._get_on_change_args(e)).id,Sao.common.selection_mixin.init_selection.call(this,e,()=>{Sao.common.selection_mixin.filter_selection.call(this,s,t,i),c&&c(this.selection,this.help)}))):c&&c(this.selection,this.help)})},Sao.common.selection_mixin.filter_selection=function(i,e,t){if(!jQuery.isEmptyObject(i)){var n,o,s=new Sao.common.DomainInversion,a=e=>{var t={};return t[this.field_name]=e[0],s.eval_domain(i,t)},r=t.description.type;if("reference"==r){t=t.get_models(e);o=t,n=function(e){return~o.indexOf(e[0])||jQuery.isEmptyObject(o)}}else{if("multiselection"==r)return;n=a}this.selection=this.selection.filter(n)}},Sao.common.selection_mixin.get_inactive_selection=function(e){if(!this.attributes.relation)return jQuery.when([]);if(null===e)return jQuery.when([null,""]);for(var t=0,i=this.inactive_selection.length;t<i;t++)if(e==this.inactive_selection[t][0])return jQuery.when(this.inactive_selection[t]);return Sao.rpc({method:"model."+this.attributes.relation+".read",params:[[e],["rec_name"],{}]},Sao.Session.current_session).then(e=>(this.inactive_selection.push([e[0].id,e[0].rec_name]),[e[0].id,e[0].rec_name]))},Sao.common.Button=Sao.class_(Object,{init:function(e,t,i,n){this.attributes=e,t?this.el=t:(this.el=jQuery("<button/>",{title:e.string||"",name:e.name||""}),this.el.text(e.string||""),this.attributes.rule&&this.el.append(" ").append(jQuery("<span/>",{class:"badge"})),this.el.attr("accesskey",Sao.common.accesskey(e.string||""))),this.icon=this.el.children("img"),this.icon.length||(this.icon=jQuery("<img/>",{class:"icon"}).prependTo(this.el),this.icon.hide()),this.el.addClass(["btn","btn-horizontal",n||"btn-default",i||""].join(" ")),this.el.attr("type","button"),this.icon.attr("aria-hidden",!0),this.set_icon(e.icon)},set_icon:function(e){e?Sao.common.ICONFACTORY.get_icon_url(e).done(e=>{this.icon.attr("src",e),this.icon.show()}):(this.icon.attr("src",""),this.icon.hide())},set_state:function(e){var t=e?e.expr_eval(this.attributes.states||{}):{};if(t.invisible?this.el.hide():this.el.show(),this.el.prop("disabled",Boolean(t.readonly)),this.set_icon(t.icon||this.attributes.icon),this.attributes.rule&&(e?e.get_button_clicks(this.attributes.name):jQuery.when()).then(e=>{var t=this.el.children(".badge"),i=[],n="";if(!jQuery.isEmptyObject(e)){for(var o in e)i.push(e[o]);n=Sao.i18n.gettext("By: ")+i.join(Sao.i18n.gettext(", "))}t.text(i.length||""),t.attr("title",n)}),(void 0===this.attributes.type||"class"===this.attributes.type)&&e)for(var i=e.group.parent;i;){if(i.modified){this.el.prop("disabled",!0);break}i=i.group.parent}}}),Sao.common.udlex=Sao.class_(Object,{init:function(e){var t=Sao.class_(Object,{init:function(e){this.stream=e.split(""),this.i=0},read:function(e=1){var t;return this.i>=this.stream.length?null:(t=this.stream.slice(this.i,this.i+e).join(),this.i+=e,t)}});this.instream=new t(e),this.eof=null,this.commenters="",this.nowordchars=[":",">","<","=","!",'"',";","(",")"],this.whitespace=" \t\r\n",this.whitespace_split=!1,this.quotes='"',this.escape="\\",this.escapedquotes='"',this.state=" ",this.pushback=[],this.token=""},get_token:function(){return 0<this.pushback.length?this.pushback.shift():this.read_token()},read_token:function(){for(var e=!1,t=" ";;){var i=this.instream.read(1);if(null===this.state){this.token="";break}if(" "==this.state){if(!i){this.state=null;break}if(this.whitespace.contains(i)){if(this.token||e)break}else if(!this.commenters.contains(i))if(this.escape.contains(i))t="a",this.state=i;else if(~this.nowordchars.indexOf(i)){if(this.quotes.contains(i))this.state=i;else if(this.whitespace_split)this.token=i,this.state="a";else if(this.token=i,this.token||e)break}else this.token=i,this.state="a"}else if(this.quotes.contains(this.state)){if(e=!0,!i)throw"no closing quotation";i==this.state?this.state="a":this.escape.contains(i)&&this.escapedquotes.contains(this.state)?(t=this.state,this.state=i):this.token=this.token+i}else if(this.escape.contains(this.state)){if(!i)throw"no escaped character";this.quotes.contains(t)&&i!=this.state&&i!=t&&(this.token=this.token+this.state),this.token=this.token+i,this.state=t}else if("a"==this.state){if(!i){this.state=null;break}if(this.whitespace.contains(i)){if(this.state=" ",this.token||e)break}else if(!this.commenters.contains(i))if(this.quotes.contains(i))this.state=i;else if(this.escape.contains(i))t="a",this.state=i;else if(!~this.nowordchars.indexOf(i)||this.quotes.contains(i)||this.whitespace_split)this.token=this.token+i;else if(this.pushback.unshift(i),this.state=" ",this.token)break}}var n=this.token;return this.token="",n=e||""!==n?n:null},next:function(){var e=this.get_token();return e==this.eof?null:e}}),Sao.common.DomainParser=Sao.class_(Object,{OPERATORS:["!=","<=",">=","=","!","<",">"],init:function(e,t){this.fields={},this.strings={},this.context=t,this.update_fields(e)},update_fields:function(e,t,i){for(var n in t=t||"",i=i||"",e){var o,s=e[n];(s.searchable||void 0===s.searchable)&&"rec_name"!==n&&(s=jQuery.extend({},s),n=t?t+"."+n:n,o=i?i+"."+s.string:s.string,s.string=o,s.name=n,this.fields[n]=s,s=(this.strings[s.string.toLowerCase()]=s).relation_fields)&&this.update_fields(s,n,o)}},parse:function(t){try{for(var e=new Sao.common.udlex(t),i=[];;){var n=e.next();if(null===n)break;i.push(n)}return i=this.group_operator(i),i=this.parenthesize(i),i=this.group(i),i=this.operatorize(i,"or"),i=this.operatorize(i,"and"),i=this.parse_clause(i),this.simplify(i)}catch(e){if("no closing quotation"==e)return this.parse(t+'"');throw e}},stringable:function(e){return!e||(e=~["AND","OR"].indexOf(e[0])?e.slice(1):e).every(e=>{var t,i,n;return!(e&&!jQuery.isEmptyObject(e))||(t=function(e){return e instanceof Array},(~["AND","OR"].indexOf(e[0])||t(e[0]))&&e.slice(1).every(t)?this.stringable(e):(t=e[0],e=e[2],(t=t.endsWith(".rec_name")?t.slice(0,-9):t)in this.fields?(i=this.fields[t],~["many2one","one2one","one2many","many2many"].indexOf(i.type)?(n=function(e){return"string"==typeof e||null===e},e instanceof Array?e.every(n):n(e)):"multiselection"!=i.type||!e||jQuery.isEmptyObject(e)||e instanceof Array):"rec_name"==t))})},string:function(e){var t;return jQuery.isEmptyObject(e)?"":(t=" ","AND"!=e[0]&&"OR"!=e[0]||("OR"==e[0]&&(t=" | "),e=e.slice(1)),e.map(e=>{var t,i,n,o;return jQuery.isEmptyObject(e)?"":"string"!=typeof e[0]||~["AND","OR"].indexOf(e[0])?"("+this.string(e)+")":(n=e[0],t=e[1],i=e[2],(n=n.endsWith(".rec_name")?n.slice(0,-9):n)in this.fields?(n=this.fields[n],o=null,3<e.length&&(o=e[3]),t.contains("ilike")&&(this.is_full_text(i)?i=i.slice(1,-1):this.is_like(i)||(t="ilike"==t?"=":"!",i=this.unescape(i))),(e=this.default_operator(n))==t.trim()?(t="",~this.OPERATORS.indexOf(i)&&(t='"" ')):t.contains(e)&&(t.contains("not")||t.contains("!"))&&(t=t.replace(e,"").replace("not","!").trim()),t.endsWith("in")&&(t=i instanceof Array&&1==i.length?"not in"==t?"!=":"=":"not in"==t?"!":""),e=this.format_value(n,i,o),~this.OPERATORS.indexOf(t)&&~["char","text","selection"].indexOf(n.type)&&""===i&&(e='""'),this.quote(n.string)+": "+t+e):(this.is_full_text(i)&&(i=i.slice(1,-1)),this.quote(i)))}).join(t))},completion:function(e){var t=[],i=this.parse(e),n=0;for(u=e.length;0<u&&(")"!=e[u]&&" "!=e[u]);u--)")"==e[u]&&(n+=1);function o(e,t){return 0<t?e.substring(0,e.length-t):e}var s,a,r,l=this.ending_clause(i),c=l[0],d=l[1]-n,l=this.string(i);(l=0<d?l.substring(0,l.length-d):l)!=e&&t.push(l);if(null!==c&&0===n)for(var h=this.complete(c),u=0,_=h.length;u<_;u++)s=h[u],s=this.string(this.replace_ending_clause(i,s)),t.push(o(s,d));if(0<e.length){if(" "!=e.substr(e.length-1,1))return t;if(2<=e.length||":"==e.substr(e.length-2,1))return t}for(r in this.strings){m=this.strings[r],a="","ilike"!=(p=this.default_operator(m))&&"not ilike"!=p||(a=this.likify(a));var m=this.append_ending_clause(i,[m.name,p,a],d),p=this.string(m);t.push(o(p,d))}return t},complete:function(e){var t,i,n,o,s=[];if(1==e.length?t=e[0]:3==e.length?(t=e[0],i=e[1],n=e[2]):(t=e[0],i=e[1],n=e[2],e[3],t.endsWith(".rec_name")&&(t=t.substring(0,t.length-9))),"rec_name"==t&&("ilike"==i&&((e=n.replace(/%%/g,"__")).startsWith("%")||e.endsWith("%")?n=e.substring(1,e.length-1):~e.indexOf("%")&&(n=n.replace(/%%/g,"%")),i=null),t=n,n=""),(t=null==t?"":t).toLowerCase()in this.strings||t in this.fields)if(o=t in this.fields?this.fields[t]:this.strings[t.toLowerCase()],i)for(var a=this.complete_value(o,n),r=0,l=a.length;r<l;r++)s.push([o.name,i,a[r]]);else n="","ilike"!=(i=this.default_operator(o))&&"not ilike"!=i||(n=this.likify(n)),s.push([o.name,i,n]);else for(var c in this.strings)(o=this.strings[c]).string.toLowerCase().startsWith(t.toLowerCase())&&(n="","ilike"==(i=this.default_operator(o))&&(n=this.likify(n)),s.push([o.name,i,n]));return s},is_subdomain:function(e){return e instanceof Array&&!e.clause},ending_clause:function(e,t=0){return 0===e.length?[null,t]:(e=e[e.length-1],this.is_subdomain(e)?this.ending_clause(e,t+1):[e,t])},replace_ending_clause:function(e,t){for(var i=[],n=0,o=e.length-1;n<o;n++)i.push(e[n]);return this.is_subdomain(e[n])?i.push(this.replace_ending_clause(e[n],t)):i.push(t),i},append_ending_clause:function(e,t,i){var n;return 0===e.length?[t]:(n=e.slice(0,-1),e=e[e.length-1],this.is_subdomain(e)?n.push(this.append_ending_clause(e,t,i-1)):(n.push(e),0===i&&n.push(t)),n)},complete_value:function(s,a){function e(){for(var e,t=[],i=null!==a?a:"",i=(i=a instanceof Array?a[a.length-1]||"":i).replace(/^%*|%*$/g,""),n=0,o=s.selection.length;n<o;n++)e=s.selection[n][0],s.selection[n][1].toLowerCase().startsWith(i.toLowerCase())&&(a instanceof Array?t.push(a.slice(0,-1).concat([e])):t.push(e));return t}function t(){return[Sao.Date(),Sao.DateTime().utc()]}var i={boolean:function(){return null==a?[!0,!1]:a?[!1]:[!0]},selection:e,multiselection:e,reference:()=>{for(var e,t=[],i=null!==a?a:"",i=(i=a instanceof Array?a[a.length-1]:i).replace(/^%*|%*$/g,""),n=0,o=s.selection.length;n<o;n++)e=s.selection[n][0],s.selection[n][1].toLowerCase().startsWith(i.toLowerCase())&&(a instanceof Array?t.push(a.slice(0,-1).concat([e])):t.push(this.likify(e)));return t},datetime:t,timestamp:t,date:function(){return[Sao.Date()]},time:function(){return[Sao.Time()]}};return s.type in i?i[s.type]():[]},group_operator:function(e){var t=e[0],i=null,n=[];for(const i of e.slice(1))t="="==i&&t&&~this.OPERATORS.indexOf(t+i)?(n.push(t+i),null):(null!==t&&n.push(t),i);return null!==t&&n.push(t),n},parenthesize:function(e){var t=[],i=t,n=[];for(const o of e)void 0!==i&&("("==o?(n.push(i),i=i[i.push([])-1]):")"==o?i=n.pop():i.push(o));return t},group:function(e){var t=[];const c=e=>{function t(e){(e=[e]).clause=!0,o.push(e)}var o=[],i=e.indexOf(":");if(~i){for(var n=0;n<i;n++)if((a=e.slice(n,i).join(" ")).toLowerCase()in this.strings){jQuery.isEmptyObject(e.slice(0,n))?t(null):e.slice(0,n).forEach(t);for(var s,a=[a],r=[""].concat(this.OPERATORS),l=(i+1<e.length&&~r.indexOf(e[i+1])?(a=a.concat([e[i+1]]),i+=1):a=a.concat([null]),[]);i+2<e.length&&";"==e[i+2];)l.push(e[i+1]),i+=2;c(e.slice(i+1)).forEach(function(i,n){return function(e){var t;jQuery.isEmptyObject(i)?o.push(e):(jQuery.isEmptyObject(n)?(t=i.concat(e)).clause=!0:(null!==e[0]&&n.push(e[0]),(t=i.concat([n])).clause=!0),o.push(t),i.splice(0,i.length))}}(a,l)),jQuery.isEmptyObject(a)||(jQuery.isEmptyObject(l)?(s=a.concat([null])).clause=!0:(s=a.concat([l])).clause=!0,o.push(s));break}}else e.forEach(t);return o};var i=[];for(const n of e)if(this.is_generator(n)){for(const o of c(i))Sao.common.compare(o,[null])||t.push(o);i=[],t.push(this.group(n))}else i.push(n);for(const s of c(i))Sao.common.compare(s,[null])||t.push(s);return t},is_generator:function(e){return e instanceof Array&&void 0===e.clause},operatorize:function(e,t){for(var i=[],n=(t=t||"or",e=jQuery.extend([],e),{or:"|",and:"&"}[t]),o=function(e){return e instanceof Array?Sao.common.compare(e,[n]):e==n},s=e.shift();o(s);)s=e.shift();if(void 0!==s){this.is_generator(s)&&(s=this.operatorize(s,t));for(var a=null;!jQuery.isEmptyObject(e);)if(a=e.shift(),o(a=this.is_generator(a)&&!o(a)?this.operatorize(a,t):a)){for(a=e.shift();o(a);)a=e.shift();void 0!==(a=this.is_generator(a)?this.operatorize(a,t):a)?s=[t.toUpperCase(),s,a]:o(s)||(i.push([t.toUpperCase(),s]),s=null),a=null}else o(s)||i.push(s),s=a;jQuery.isEmptyObject(e)&&(null===a||o(a)?null===s||o(s)||i.push(s):i.push(a))}return i},_clausify:function(e){return e.clause=!0,e},parse_clause:function(e){var l=[];return e.forEach(e=>{if(this.is_generator(e))l.push(this.parse_clause(e));else if("OR"===e||"AND"===e)l.push(e);else if(1!=e.length||e[0]instanceof Array){if(3==e.length&&e[0].toLowerCase()in this.strings){e[0];var t,i,n=e[1],o=e[2],s=this.strings[e[0].toLowerCase()],a=s.name,r=null;if("reference"==s.type?(r=(i=this.split_target_value(s,o))[0],o=i[1],r&&(a+=".rec_name")):"multiselection"!=s.type||null===o||o instanceof Array||(o=[o]),n=n||this.default_operator(s),"!"==(n=o instanceof Array&&"multiselection"!=s.type?"!"==n?"not in":"in":n)&&(n=this.negate_operator(this.default_operator(s))),null===o&&n.endsWith("in")&&(n=n.startsWith("not")?"!=":"="),~["integer","float","numeric","datetime","timestamp","date","time"].indexOf(s.type))if("string"==typeof o&&o.contains(".."))return i=o.split("..",2),t=this.convert_value(s,i[0],this.context),i=this.convert_value(s,i[1],this.context),void l.push([this._clausify([a,">=",t]),this._clausify([a,"<=",i])]);o instanceof Array?(o=o.map(e=>this.convert_value(s,e,this.context)),~["many2one","one2many","many2many","one2one","many2many","one2one"].indexOf(s.type)&&(a+=".rec_name")):o=this.convert_value(s,o,this.context),n.contains("like")&&(o=this.likify(o)),l.push(r?this._clausify([a,n,o,r]):this._clausify([a,n,o]))}}else l.push(this._clausify(["rec_name","ilike",this.likify(e[0])]))}),l},likify:function(e,t){return t=t||"\\",e?(t=e.replace(t+"%","").replace(t+"_","")).contains("%")||t.contains("_")?e:"%"+e+"%":"%"},is_full_text:function(e,t){t=t||"\\";var i=e;return!(i=(i="%"==i.charAt(0)&&"%"==i.charAt(i.length-1)?i.slice(1,-1):i).replace(t+"%","").replace(t+"_","")).contains("%")&&!i.contains("_")&&e.startsWith("%")&&e.endsWith("%")},is_like:function(e,t){e=e.replace((t=t||"\\")+"%","").replace(t+"_","");return e.contains("%")||e.contains("_")},unescape:function(e,t){return e.replace((t=t||"\\")+"%","%").replace(t+"_","_")},quote:function(e,t=!1){if("string"==typeof e){if(t&&""===e)return'""';(e=e.contains("\\")?e.replace(new RegExp("\\\\","g"),"\\\\"):e).contains('"')&&(e=e.replace(new RegExp('"',"g"),'\\"'));for(var i=[":"," ","(",")"].concat(this.OPERATORS),n=0;n<i.length;n++){var o=i[n];if(e.contains(o))return'"'+e+'"'}}return e},default_operator:function(e){return~["char","text","many2one","many2many","one2many","reference","one2one"].indexOf(e.type)?"ilike":"multiselection"==e.type?"in":"="},negate_operator:function(e){switch(e){case"ilike":return"not ilike";case"=":return"!=";case"in":return"not in"}},time_format:function(e){return new Sao.PYSON.Decoder({}).decode(e.format)},split_target_value:function(e,t){var i=null;if("string"==typeof t)for(var n=0;n<e.selection.length;n++){var o=e.selection[n],s=o[0],o=o[1];if(t.toLowerCase().startsWith(o.toLowerCase()+",")){i=s,t=t.slice(o.length+1);break}}return[i,t]},convert_value:function(n,o,e){e=e||{};function t(){if("string"==typeof o)for(var e=0;e<n.selection.length;e++){var t=n.selection[e],i=t[0],t=t[1];if(o.toLowerCase()==t.toLowerCase())return i}return o}var i={boolean:function(){return"string"==typeof o?[Sao.i18n.gettext("y"),Sao.i18n.gettext("Yes"),Sao.i18n.gettext("True"),Sao.i18n.gettext("t"),"1"].some(function(e){return e.toLowerCase().startsWith(o.toLowerCase())}):null},float:function(){var e=Number(n.factor||1),t=Number(o);return isNaN(t)||""===o||null===o?null:t/e},integer:function(){var e=Number(n.factor||1,10),t=parseInt(o,10);return isNaN(t)?null:t/e},numeric:function(){var e=Number(n.factor||1),t=Number(o);return isNaN(t.valueOf())||""===o||null===o?null:new Sao.Decimal(t/e)},selection:t,multiselection:t,reference:t,datetime:()=>Sao.common.parse_datetime(Sao.common.date_format(e.date_format)+" "+this.time_format(n),o),date:function(){return Sao.common.parse_date(Sao.common.date_format(e.date_format),o)},time:()=>{try{return Sao.common.parse_time(this.time_format(n),o)}catch(e){return null}},timedelta:()=>{var e=null;return n.converter&&(e=this.context[n.converter]),Sao.common.timedelta.parse(o,e)},many2one:function(){return""===o?null:o}},i=(i.timestamp=i.datetime,i[n.type]);return i?i():o},format_value:function(o,s,t=null,i={},e=!1){function n(){var e,t,i,n;return s||0===s||s===new Sao.Decimal(0)?(e=0,t=Number(o.factor||1),(n=String(s*t)).contains("e")&&(i=n.split("e")[1],n=n.split("e")[0],e-=parseInt(i)),n.contains(".")&&(e+=n.replace(/0+$/,"").split(".")[1].length),(s*t).toFixed(e)):""}function a(){if(o.selection instanceof Array)for(var e=0;e<o.selection.length;e++)if(o.selection[e][0]==s)return o.selection[e][1];return s||""}var r={boolean:function(){return!1===s?Sao.i18n.gettext("False"):s?Sao.i18n.gettext("True"):""},integer:function(){var e=Number(o.factor||1);return s||0===s?""+parseInt(parseInt(s,10)*e,10):""},float:n,numeric:n,selection:a,multiselection:a,reference:function(){if(!t)return a();for(var e=0;e<o.selection.length;e++)if(o.selection[e][0]==t){t=o.selection[e][1];break}return t+","+s},datetime:()=>s?s.isDate||!(s.hour()||s.minute()||s.second())?Sao.common.format_date(Sao.common.date_format(i.date_format),s):Sao.common.format_datetime(Sao.common.date_format(i.date_format)+" "+this.time_format(o),s):"",date:()=>Sao.common.format_date(Sao.common.date_format(i.date_format),s),time:()=>s?Sao.common.format_time(this.time_format(o),s):"",timedelta:()=>{var e;return s&&s.valueOf()?(e=null,o.converter&&(e=this.context[o.converter]),Sao.common.timedelta.format(s,e)):""},many2one:function(){return null===s?"":s}};return r.timestamp=r.datetime,s instanceof Array?s.map(e=>this.format_value(o,e,null,i,!0)).join(";"):(r=r[o.type])?this.quote(r(s)):null===s?"":this.quote(s,e)},simplify:function(e){return this.is_subdomain(e)?1==e.length&&this.is_subdomain(e[0])?this.simplify(e[0]):2!=e.length||"AND"!=e[0]&&"OR"!=e[0]||!this.is_subdomain(e[1])?(e=3!=e.length||"AND"!=e[0]&&"OR"!=e[0]||!this.is_subdomain(e[1])||e[0]!=e[1][0]?e:this.simplify(e[1]).concat([e[2]])).map(e=>this.simplify(e)):this.simplify(e[1]):e}}),Sao.common.DomainInversion=Sao.class_(Object,{and:function(e,t){return e&&t},or:function(e,t){return e||t},OPERATORS:{"=":function(e,t){return Sao.common.DomainInversion.equals(e,t)},">":function(e,t){return t<e},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">=":function(e,t){return t<=e},"!=":function(e,t){return!Sao.common.DomainInversion.equals(e,t)},in:function(e,t){return Sao.common.DomainInversion.in_(e,t)},"not in":function(e,t){return!Sao.common.DomainInversion.in_(e,t)},like:function(e,t){return Sao.common.DomainInversion.sql_like(e,t,!1)},ilike:function(e,t){return Sao.common.DomainInversion.sql_like(e,t,!0)},"not like":function(e,t){return!Sao.common.DomainInversion.sql_like(e,t,!1)},"not ilike":function(e,t){return!Sao.common.DomainInversion.sql_like(e,t,!0)},child_of:function(){return!0},"not child_of":function(){return!0}},locale_part:function(e,t,i="id"){return e===t?i:e.contains(".")?e.split(".").slice(1).join("."):e},is_leaf:function(e){return e instanceof Array&&2<e.length&&"string"==typeof e[1]},constrained_leaf:function(e,t){void 0===t&&(t=this.and);e[0];var i=e[1];e[2];return!!("="===i&t===this.and)},eval_leaf:function(e,t,i){void 0===i&&(i=this.and);var i=e[0],n=e[1],e=e[2];return i.contains(".")?Boolean(t[i.split(".")[0]]):(t=t[i],~["=","!="].indexOf(n)||null!=t&&null!=e||~["in","not in"].indexOf(n)&&null==t&&e instanceof Array&&~e.indexOf(null)?(moment.isMoment(t)&&!e&&(e=(t.isDateTime?Sao.DateTime:Sao.Date).min),(t=moment.isMoment(e)&&!t?(e.isDateTime?Sao.DateTime:Sao.Date).min:t)instanceof Array&null===e&&(e=[]),"string"==typeof t&&e instanceof Array&&2==e.length?e=e.join(","):t instanceof Array&&"string"==typeof e&&2==t.length&&(t=t.join(",")),!((n=~["=","!="].indexOf(n)&&t instanceof Array&&"number"==typeof e?{"=":"in","!=":"not in"}[n]:n)in this.OPERATORS)||this.OPERATORS[n](t,e)):void 0)},inverse_leaf:function(e){return~["AND","OR"].indexOf(e)?e:this.is_leaf(e)?!e[1].contains("child_of")||e[0].contains(".")||3==e.length?e:[e[3]].concat(e.slice(1)):e.map(e=>this.inverse_leaf(e))},filter_leaf:function(e,t,i){return~["AND","OR"].indexOf(e)?e:this.is_leaf(e)?e[0].startsWith(t)&&3<e.length&&e[3]!==i?["id","=",null]:e:e.map(e=>this.filter_leaf(e,t,i))},eval_domain:function(e,t,i){return void 0===i&&(i=this.and),this.is_leaf(e)?this.eval_leaf(e,t,i):!(!jQuery.isEmptyObject(e)||i!=this.and)||(!jQuery.isEmptyObject(e)||i!=this.or)&&("AND"==e[0]?this.eval_domain(e.slice(1),t):"OR"==e[0]?this.eval_domain(e.slice(1),t,this.or):i(Boolean(this.eval_domain(e[0],t)),Boolean(this.eval_domain(e.slice(1),t,i))))},localize_domain:function(e,t,i){var n,o;return~["AND","OR",!0,!1].indexOf(e)?e:this.is_leaf(e)?e[1].contains("child_of")?1<e[0].split(".").length?[e[0].split(".").slice(1).join(".")].concat(e.slice(1)):3==e.length?e:[e[3]].concat(e.slice(1,-1)):(n="id","string"==typeof e[2]&&(n="rec_name"),o=i?3:4,[this.locale_part(e[0],t,n)].concat(e.slice(1,o)).concat(e.slice(4))):e.map(e=>this.localize_domain(e,t,i))},_sort_key:function(e){var t;return e.length?this.is_leaf(e)?[1,e]:~["AND","OR"].indexOf(e)?[0,e]:(t=e.map(this._sort_key.bind(this)),[Math.max(...t.map(e=>e[0]))+1,t]):[0,e]},_domain_compare:function(e,t){if(e instanceof Array&&t instanceof Array){for(var i,n=Math.min(e.length,t.length),o=0;o<n;o++)if(0!=(i=this._domain_compare(e[o],t[o])))return i;return e.length==t.length?0:e.length<t.length?-1:1}return e==t?0:e<t?-1:1},sort:function(e){return e.length?this.is_leaf(e)||~["AND","OR"].indexOf(e)?e:((e=e.map(this.sort.bind(this))).sort((e,t)=>this._domain_compare(this._sort_key(e),this._sort_key(t))),e):[]},prepare_reference_domain:function(e,t){function i(e){var t,i,n=null,o=null;return"string"==typeof e&&e.contains(",")?((i=(t=e.split(",")).splice(0,1)).push(t.join(",")),n=i[0],"%"!=(o=i[1])&&(o=parseInt(o,10),isNaN(o))&&(n=null,o=e)):o=e instanceof Array&&2==e.length&&"string"==typeof e[0]&&("number"==typeof e[1]||"%"==e[1])?(n=e[0],e[1]):e,[n,o]}var n,o,s;if(~["AND","OR"].indexOf(e))return e;if(this.is_leaf(e)){if(e[0]!=t)return e;if("="==e[1]||"!="==e[1]){if(n=(s=i(e[2]))[0],o=s[1],n)return"%"==o?"="==e[1]?[t+".id","!=",null,n]:[t,"not like",e[2]]:[t+".id",e[1],o,n]}else if("in"==e[1]||"not in"==e[1]){for(var a={},r=!1,l=0;l<e[2].length;l++){if(n=(s=i(e[2][l]))[0],o=s[1],!n){r=!0;break}n in a||(a[n]=[]),a[n].push(o)}if(!r){var c,d="in"==e[1]?["OR"]:["AND"];for(n in a)~(c=a[n]).indexOf("%")?"in"==e[1]?d.push([t+".id","!=",null,n]):d.push([t,"not like",n+",%"]):d.push([t+".id",e[1],c.map(Number),n]);return d}}return[]}return e.map(e=>this.prepare_reference_domain(e,t))},extract_reference_models:function(e,s){var a;return~["AND","OR"].indexOf(e)?[]:this.is_leaf(e)?e[0].split(".",1)[0]==s&&3<e.length?[e[3]]:[]:(a=[],e.map(e=>{for(var t=this.extract_reference_models(e,s),i=0,n=t.length;i<n;i++){var o=t[i];~a.indexOf(o)||a.push(o)}}),a)},_bool_operator:function(e){var t="AND";return t=0<e.length&&("AND"==e[0]||"OR"==e[0])?e[0]:t},simplify_nested:function(e){if(e.length){if(this.is_leaf(e))return[e];if("AND"==e||"OR"==e)return[e];if(e instanceof Array&&1==e.length)return this.simplify_nested(e[0]);var t,i=[];for(t of e){var n=this.simplify_nested(t);this._bool_operator(n)==this._bool_operator(i)||1==n.length?0<i.length&&0<n.length&&("AND"==n[0]||"OR"==n[0])?i.push(...n.slice(1)):i.push(...n):i.push(n)}return i}return[]},simplify_duplicate:function(e){var t,i=[],n=null;~["AND","OR"].indexOf(e[0])&&(n=e[0],e=e.slice(1));for(t of e){var o=this.simplify(t);if(0==o.length){if("OR"===n)return[]}else{var s,a=!1;for(s of i)if(Sao.common.compare(o,s)){a=!0;break}a||i.push(o)}}return n&&1<i.length&&i.unshift(n),i},simplify:function(e){return this.is_leaf(e)?[e]:e.length?this.simplify_nested(this.simplify_duplicate(e)):[]},simplify_AND:function(e){if(this.is_leaf(e))return e;if("OR"==e)return e;var t=[];for(const i of e)"AND"!=i&&t.push(this.simplify_AND(i));return t},canonicalize:function(e){return this.simplify_AND(this.sort(this.simplify(e)))},merge:function(e,t){var i;return jQuery.isEmptyObject(e)||~["AND","OR"].indexOf(e)?[]:(i="OR"==e[0]?"OR":"AND",this.is_leaf(e)?[e]:void 0===t?[i].concat([].concat.apply([],e.map(e=>this.merge(e,i)))):i==t?[].concat.apply([],e.map(e=>this.merge(e,i))):[this.merge(e)])},concat:function(e,t){var i=[];t&&i.push(t);for(const n of e)jQuery.isEmptyObject(n)||i.push(n);return this.simplify(this.merge(i))},unique_value:function(o,s=!0){if(o instanceof Array&&1==o.length){let[e,t,i,...n]=o[0];o=e.split(".").length-1;if(("="==t||s&&"in"==t&&1==i.length)&&(!o||1==o&&n.length&&e.endsWith(".id")))return"in"==t&&s&&(i=i[0]),n.length&&e.endsWith(".id")&&(n=n[0],i=[n,i]),[!0,e,i]}return[!1,null,null]},parse:function(e){var t=Sao.common.DomainInversion.And,i=Sao.common.DomainInversion.Or;return this.is_leaf(e)?e:jQuery.isEmptyObject(e)?new t([]):"OR"===e[0]?new i(e.slice(1)):("AND"===e[i=0]&&(i=1),new t(e.slice(i)))},domain_inversion:function(e,t,i={}){e=this.parse(e);return!~e.variables.indexOf(t)||e.inverse(t,i)}}),Sao.common.DomainInversion.equals=function(e,t){return e instanceof Array&&t instanceof Array?Sao.common.compare(e,t):moment.isMoment(e)&&moment.isMoment(t)?e.isDate==t.isDate&&e.isDateTime==t.isDateTime&&e.valueOf()==t.valueOf():e instanceof Number||t instanceof Number?Number(e)===Number(t):e===t},Sao.common.DomainInversion.in_=function(e,t){if(e instanceof Array){if(t instanceof Array){for(var i=0,n=e.length;i<n;i++)if(~t.indexOf(e[i]))return!0;return!1}return Boolean(~e.indexOf(t))}return Boolean(~t.indexOf(e))},Sao.common.DomainInversion.sql_like=function(e,t,i){for(var n,o=!1,s=[],a=t.split(/(.|\\)/),r=1,l=a.length;r<l;r+=2)n=a[r],o?("%"==n||"_"==n?s.push(n):s.push("\\",n),o=!1):"\\"==n?o=!0:s.push("_"==n?".":"%"==n?".*":n);t.startsWith("%")||s.splice(0,0,"^"),t.endsWith("%")||s.push("$");t=i?"i":"";return new RegExp(s.join(""),t).test(e)},Sao.common.DomainInversion.And=Sao.class_(Object,{init:function(e){this.domain_inversion=new Sao.common.DomainInversion,this.branches=e.map(this.domain_inversion.parse.bind(this.domain_inversion)),this.variables=[];for(var t=0,i=this.branches.length;t<i;t++){var n=this.branches[t];this.domain_inversion.is_leaf(n)?this.variables.push(this.base(n[0])):n instanceof Sao.common.DomainInversion.And&&(this.variables=this.variables.concat(n.variables))}},base:function(e){return e.contains(".")?e.split(".")[0]:e},inverse:function(e,t){for(var i=Sao.common.DomainInversion,n=[],o=0,s=this.branches.length;o<s;o++){var a=this.branches[o];if(a instanceof i.And){var r=a.inverse(e,t),l="boolean"==typeof r;if(~a.variables.indexOf(e))if(l){if(!r)return!1}else n.push(r)}else if(this.domain_inversion.is_leaf(a)&&this.base(a[0])===e)n.push(a);else{l=a[0];if(l in t&&!(l in t&&(this.domain_inversion.eval_leaf(a,t,this.domain_inversion.and)||this.domain_inversion.constrained_leaf(a,this.domain_inversion.and))))return!1;n.push(!0)}}return n=n.filter(function(e){return!0!==e}),!!jQuery.isEmptyObject(n)||this.domain_inversion.simplify(n)}}),Sao.common.DomainInversion.Or=Sao.class_(Sao.common.DomainInversion.And,{inverse:function(t,i){var e=Sao.common.DomainInversion,n=[];if(!jQuery.isEmptyObject(this.variables.filter(function(e){return!(e in i)&&e!=t})))return!0;for(var o=0,s=this.branches.length;o<s;o++){var a=this.branches[o];if(a instanceof e.And){var r=a.inverse(t,i),l="boolean"==typeof r;if(~a.variables.indexOf(t))if(l){if(r)return!0}else n.push(r);else if(l&&r)return!0}else if(this.domain_inversion.is_leaf(a)&&this.base(a[0])==t)n.push(a);else{l=a[0];if((l=this.base(l))in i&&this.domain_inversion.eval_leaf(a,i,this.domain_inversion.or)||this.domain_inversion.constrained_leaf(a,this.domain_inversion.or))return!0;l in i&&!this.domain_inversion.eval_leaf(a,i,this.domain_inversion.or)&&n.push(!1)}}return n=n.filter(function(e){return!1!==e}),!jQuery.isEmptyObject(n)&&this.domain_inversion.simplify(["OR"].concat(n))}}),Sao.common.mimetypes={csv:"text/csv",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",gif:"image/gif",html:"text/html",jpeg:"image/jpeg",jpg:"image/jpeg",mpeg:"video/mpeg",mpg:"video/mpeg",ods:"application/vnd.oasis.opendocument.spreadsheet",odt:"application/vnd.oasis.opendocument.text",ogg:"audio/ogg",pdf:"application/pdf",png:"image/png",svg:"image/svg+xml",text:"text/plain",tif:"image/tif",tiff:"image/tif",txt:"text/plain",webp:"image/webp",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml:"application/xml",xpm:"image/x-xpixmap"},Sao.common.guess_mimetype=function(e){for(var t in Sao.common.mimetypes)if(new RegExp(".*."+t+"$","i").test(e))return Sao.common.mimetypes[t];return"application/octet-binary"},Sao.common.LOCAL_ICONS=["tryton-add","tryton-archive","tryton-attach","tryton-back","tryton-bookmark-border","tryton-bookmark","tryton-bookmarks","tryton-cancel","tryton-clear","tryton-close","tryton-copy","tryton-create","tryton-date","tryton-delete","tryton-download","tryton-email","tryton-error","tryton-exit","tryton-export","tryton-filter","tryton-format-align-center","tryton-format-align-justify","tryton-format-align-left","tryton-format-align-right","tryton-format-bold","tryton-format-color-text","tryton-format-italic","tryton-format-underline","tryton-forward","tryton-history","tryton-import","tryton-info","tryton-launch","tryton-link","tryton-log","tryton-menu","tryton-note","tryton-ok","tryton-open","tryton-print","tryton-public","tryton-question","tryton-refresh","tryton-remove","tryton-save","tryton-search","tryton-send","tryton-star-border","tryton-star","tryton-switch","tryton-translate","tryton-unarchive","tryton-undo","tryton-warning"],Sao.common.IconFactory=Sao.class_(Object,{batchnum:10,name2id:{},loaded_icons:{},tryton_icons:[],register_prm:jQuery.when(),load_icons:function(s){if(!(s=s||!1))for(var e in this.loaded_icons)window.URL.revokeObjectURL(this.loaded_icons[e]);return new Sao.Model("ir.ui.icon").execute("list_icons",[],{}).then(e=>{var t,i;s||(this.name2id={},this.loaded_icons={}),this.tryton_icons=[];for(var n=0,o=e.length;n<o;n++)t=e[n][0],i=e[n][1],s&&i in this.loaded_icons||(this.tryton_icons.push([t,i]),this.name2id[i]=t)})},register_icon:function(s){var e,a;return!s||s in this.loaded_icons||~Sao.common.LOCAL_ICONS.indexOf(s)?jQuery.when():"pending"==this.register_prm.state()?this.register_prm.then(()=>this.register_icon(s)):(e=s in this.name2id?jQuery.when():this.load_icons(!0),a=new Sao.Model("ir.ui.icon"),this.register_prm=e.then(()=>{const n=e=>{for(var t=0,i=this.tryton_icons.length;t<i;t++){var n=this.tryton_icons[t];if(Sao.common.compare(n,e))break}return t};var e=n([this.name2id[s],s]),t=(t=Math.round(e-this.batchnum/2))<0?0:t,e=Math.round(e+this.batchnum/2),i=[];for(const o of this.tryton_icons.slice(t,e))i.push(o[0]);return a.execute("read",[i,["name","icon"]],{}).then(e=>{for(const i of e){var t=this._convert(i.icon);this.loaded_icons[i.name]=t,delete this.name2id[i.name],this.tryton_icons.splice(n([i.id,i.name]),1)}})}),this.register_prm)},_convert:function(e){var t=jQuery.parseXML(e),t=(jQuery(t).find("svg").attr("fill",Sao.config.icon_colors[0]),e=(new XMLSerializer).serializeToString(t),new Blob([e],{type:"image/svg+xml"}));return window.URL.createObjectURL(t)},get_icon_url:function(t){return t?this.register_icon(t).then(()=>t in this.loaded_icons?this.loaded_icons[t]:jQuery.get("images/"+t+".svg",null,null,"text").then(e=>{e=this._convert(e);return this.loaded_icons[t]=e}).fail(()=>{Sao.Logger.error("Unknown icon %s",t)})):jQuery.when("")},get_icon_img:function(e,t){(t=t||{}).class||(t.class="icon");var i=jQuery("<img/>",t);return e&&this.get_icon_url(e).then(function(e){i.attr("src",e)}),i}}),Sao.common.ICONFACTORY=new Sao.common.IconFactory,Sao.common.UniqueDialog=Sao.class_(Object,{init:function(){this.running=!1},build_dialog:function(){return new Sao.Dialog("",this.class_,void 0,!1)},run:function(){var e,t,i;return this.running?jQuery.when():(e=Array.prototype.slice.call(arguments),t=jQuery.Deferred(),e.push(t),(i=this.build_dialog.apply(this,e)).content.submit(e=>{e.preventDefault(),i.footer.find("button.btn-primary").first().click()}),this.running=!0,i.modal.modal("show"),i.modal.on("shown.bs.modal",function(){i.modal.find("input,select").filter(":visible").first().focus()}),i.modal.on("keydown",e=>{e.which==Sao.common.ESC_KEYCODE&&(this.close(i),t.reject())}),t)},close:function(e){e.modal.on("hidden.bs.modal",function(e){jQuery(this).remove()}),e.modal.modal("hide"),this.running=!1}}),Sao.common.MessageDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"message-dialog",build_dialog:function(e,t,i){var n=Sao.common.MessageDialog._super.build_dialog.call(this);return n.header.remove(),n.body.append(jQuery("<div/>",{class:"alert alert-info",role:"alert"}).append(Sao.common.ICONFACTORY.get_icon_img(t,{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Message: "))).append(jQuery("<span/>").text(e).css("white-space","pre-wrap"))),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(()=>{this.close(n),i.resolve("ok")}).appendTo(n.footer),n},run:function(e,t){return Sao.common.MessageDialog._super.run.call(this,e,t||"tryton-info")}}),Sao.common.message=new Sao.common.MessageDialog,Sao.common.WarningDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"warning-dialog",build_dialog:function(e,t,i){var n=Sao.common.WarningDialog._super.build_dialog.call(this),t=jQuery("<div/>",{class:"alert alert-warning",role:"alert"}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-warning",{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Warning: "))).append(jQuery("<h4/>").text(t).css("white-space","pre-wrap"));return e&&t.append(jQuery("<span/>").text(e).css("white-space","pre-wrap")),n.body.append(t),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(()=>{this.close(n),i.resolve("ok")}).appendTo(n.footer),n}}),Sao.common.warning=new Sao.common.WarningDialog,Sao.common.UserWarningDialog=Sao.class_(Sao.common.WarningDialog,{class_:"user-warning-dialog",build_dialog:function(e,t,i){var n=Sao.common.UserWarningDialog._super.build_dialog.call(this,e,t,i),o=jQuery("<input/>",{type:"checkbox"});return n.body.append(jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>").text(Sao.i18n.gettext("Always ignore this warning.")).prepend(o))),n.body.append(jQuery("<p/>").text(Sao.i18n.gettext("Do you want to proceed?"))),n.footer.empty(),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("No")}).text(Sao.i18n.gettext("No")).click(()=>{this.close(n),i.reject()}).appendTo(n.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("Yes")}).text(Sao.i18n.gettext("Yes")).click(()=>{this.close(n),o.prop("checked")&&i.resolve("always"),i.resolve("ok")}).appendTo(n.footer),n}}),Sao.common.userwarning=new Sao.common.UserWarningDialog,Sao.common.ConfirmationDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"confirmation-dialog",build_dialog:function(e){var t=Sao.common.ConfirmationDialog._super.build_dialog.call(this);return t.header.remove(),t.body.append(jQuery("<div/>",{class:"alert alert-info",role:"alert"}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-info",{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Confirmation: "))).append(jQuery("<span/>").text(e).css("white-space","pre-wrap"))),t}}),Sao.common.SurDialog=Sao.class_(Sao.common.ConfirmationDialog,{build_dialog:function(e,t){var i=Sao.common.SurDialog._super.build_dialog.call(this,e);return jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(i),t.reject()}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(()=>{this.close(i),t.resolve()}).appendTo(i.footer),i}}),Sao.common.sur=new Sao.common.SurDialog,Sao.common.Sur3BDialog=Sao.class_(Sao.common.ConfirmationDialog,{build_dialog:function(e,t){var i=Sao.common.SurDialog._super.build_dialog.call(this,e);return jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(i),t.resolve("cancel")}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("No")}).text(Sao.i18n.gettext("No")).click(()=>{this.close(i),t.resolve("ko")}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("Yes")}).text(Sao.i18n.gettext("Yes")).click(()=>{this.close(i),t.resolve("ok")}).appendTo(i.footer),i}}),Sao.common.sur_3b=new Sao.common.Sur3BDialog,Sao.common.AskDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"ask-dialog",run:function(){var e=Array.prototype.slice.call(arguments);return 2==e.length&&e.push(!0),Sao.common.AskDialog._super.run.apply(this,e)},build_dialog:function(e,t,i,n){var o=Sao.common.AskDialog._super.build_dialog.call(this),s=(o.header.remove(),jQuery("<input/>",{class:"form-control",type:i?"input":"password",id:"ask-dialog-entry",name:t}));return o.body.append(jQuery("<div/>",{class:"form-group"}).append(jQuery("<label/>",{for:"ask-dialog-entry"}).text(e)).append(s)),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(o),n.reject()}).appendTo(o.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(()=>{this.close(o),n.resolve(s.val())}).appendTo(o.footer),o}}),Sao.common.ask=new Sao.common.AskDialog,Sao.common.ConcurrencyDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"ask-dialog",build_dialog:function(t,i,n,o){var e=Sao.common.ConcurrencyDialog._super.build_dialog.call(this);return e.modal.find(".modal-dialog").removeClass("modal-sm").addClass("modal-lg"),e.add_title(Sao.i18n.gettext("Concurrency Exception")),e.body.append(jQuery("<div/>",{class:"alert alert-info",role:"alert"}).append(jQuery("<p/>").append(Sao.common.ICONFACTORY.get_icon_img("tryton-info",{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Write Concurrency Warning: "))).text(Sao.i18n.gettext("This record has been modified while you were editing it."))).append(jQuery("<p/>").text(Sao.i18n.gettext("Choose:"))).append(jQuery("<ul/>").append(jQuery("<li/>").text(Sao.i18n.gettext('"Cancel" to cancel saving;'))).append(jQuery("<li/>").text(Sao.i18n.gettext('"Compare" to see the modified version;'))).append(jQuery("<li/>").text(Sao.i18n.gettext('"Write Anyway" to save your current version.'))))),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(e),o.reject()}).appendTo(e.footer),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("Compare")}).text(Sao.i18n.gettext("Compare")).click(()=>{this.close(e),Sao.rpc({method:"model."+t+".read",params:[[i],["rec_name"],n]},Sao.Session.current_session).then(function(e){e=e[0].rec_name;Sao.Tab.create({model:t,res_id:i,name:Sao.i18n.gettext("Compare: %1",e),domain:[["id","=",i]],context:n,mode:["form"]}),o.reject()})}).appendTo(e.footer),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("Write Anyway")}).text(Sao.i18n.gettext("Write Anyway")).click(()=>{this.close(e),o.resolve()}).appendTo(e.footer),e}}),Sao.common.concurrency=new Sao.common.ConcurrencyDialog,Sao.common.ErrorDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"error-dialog",build_dialog:function(e,t,i){var n=Sao.common.ConcurrencyDialog._super.build_dialog.call(this);return n.modal.find(".modal-dialog").removeClass("modal-sm").addClass("modal-lg"),n.add_title(Sao.i18n.gettext("Application Error")),n.body.append(jQuery("<div/>",{class:"alert alert-danger",role:"alert"}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-error",{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Warning: "))).append(jQuery("<p/>").append(jQuery("<pre/>").text(t))).append(jQuery("<p/>").append(jQuery("<a/>",{class:"btn btn-link",href:Sao.config.bug_url,target:"_blank",rel:"noreferrer noopener"}).text(Sao.i18n.gettext("Report Bug"))))),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("Close")}).text(Sao.i18n.gettext("Close")).click(()=>{this.close(n),i.resolve()}).appendTo(n.footer),n}}),Sao.common.error=new Sao.common.ErrorDialog,Sao.common.Processing=Sao.class_(Object,{queries:0,timeout:3e3,init:function(){this.el=jQuery("<div/>",{id:"processing",class:"text-center"});for(var e=jQuery("<span/>",{class:"label label-info",text:Sao.i18n.gettext("Processing")}).appendTo(this.el),t=0;t<3;t++)e.append(jQuery("<span/>",{class:"dot",text:"."}));this.el.hide(),jQuery(()=>{this.el.appendTo("body")})},show:function(){return window.setTimeout(()=>{this.queries+=1,this.el.show()},this.timeout)},hide:function(e){window.clearTimeout(e),0<this.queries&&--this.queries,this.queries<=0&&(this.queries=0,this.el.hide())}}),Sao.common.processing=new Sao.common.Processing,Sao.common.set_overflow=function(e,t){var i,t="hide"==t?i="":(i="visible","none");e.closest(".treeview").css("overflow",i).css("max-height",t),e.closest(".modal-body").css("overflow",i),e.closest(".navbar-collapse.in").css("overflow-y",i),e.closest(".content-box").css("overflow-y",i),e.parents("fieldset.form-group_").css("overflow",i),Sao.common.scrollIntoViewIfNeeded(e)},Sao.common.InputCompletion=Sao.class_(Object,{init:function(e,t,i,n){e.is("input")?(e.wrap('<div class="dropdown"/>'),this.dropdown=e.parent()):(e.addClass("dropdown"),this.dropdown=e),this.input=e.find("input").add(e.filter("input")).first(),this.input.attr("autocomplete","off"),jQuery("<span/>",{"data-toggle":"dropdown"}).appendTo(this.dropdown),this.menu=jQuery("<ul/>",{class:"dropdown-menu",role:"listbox"}).appendTo(this.dropdown),this.separator=jQuery("<li/>",{role:"separator",class:"divider"}).appendTo(this.menu),this.separator.hide(),this.source=t,this.match_selected=i,this.format=n,this.action_activated=null,this._search_text=null,this.input.on("input",()=>{window.setTimeout(this._input.bind(this),300,this.input.val())}),this.input.keydown(e=>{e.which==Sao.common.ESC_KEYCODE?this.dropdown.hasClass("open")&&(e.preventDefault(),e.stopPropagation(),this.menu.dropdown("toggle")):e.which==Sao.common.DOWN_KEYCODE&&this.dropdown.hasClass("open")&&(e.preventDefault(),e.stopPropagation(),this.menu.find("li > a").first().focus())}),this.menu.keydown(e=>{e.which==Sao.common.ESC_KEYCODE&&(e.preventDefault(),e.stopPropagation(),this.menu.dropdown("toggle"))}),this.dropdown.on("hide.bs.dropdown",()=>{this.input.focus(),Sao.common.set_overflow(this.input,"hide")}),this.dropdown.on("show.bs.dropdown",()=>{Sao.common.set_overflow(this.input,"show")})},set_actions:function(e,t=!0,i=!0){void 0!==e&&(this.action_activated=e);e=[];t&&e.push(["search",Sao.i18n.gettext("Search...")]),i&&e.push(["create",Sao.i18n.gettext("Create...")]),this.menu.find("li.action").remove(),jQuery.isEmptyObject(e)?this.separator.hide():(this.separator.show(),e.forEach(function(e){var t=e[0],e=e[1];jQuery("<li/>",{class:"action action-"+t}).append(jQuery("<a/>",{href:"#"}).text(this._format_action(e))).click(e=>{e.preventDefault(),this.action_activated&&this.action_activated(t),this.input.val("")}).appendTo(this.menu)},this))},_format:function(e){return this.format?this.format(e):jQuery("<span/>").text(e)},_format_action:function(e){return this.format_action?this.format_action(e):e},_input:function(t){t==this.input.val()&&(this.source instanceof Array?jQuery.when(this.source.filter(function(e){return e.toLowerCase().startsWith(t.toLowerCase())})):this.source(t)).then(e=>{t==this.input.val()&&this._set_selection(e)})},_set_selection:function(e){void 0===e&&(e=[]),this.menu.find("li.completion").remove(),e.reverse().forEach(function(t){jQuery("<li/>",{class:"completion"}).append(jQuery("<a/>",{href:"#"}).append(this._format(t))).click(e=>{e.preventDefault(),this.match_selected&&this.match_selected(t),this.input.focus()}).prependTo(this.menu)},this),this.input.val()&&(this.menu.find("li.completion").length||this.menu.find("li.action").length)?this.dropdown.hasClass("open")||this.menu.dropdown("toggle"):this.dropdown.hasClass("open")&&this.menu.dropdown("toggle")}}),Sao.common.get_completion=function(e,t,i,n,o=!0,s=!0){e=new Sao.common.InputCompletion(e,t,i,function(e){return e.name});return n&&e.set_actions(n,o,s),e._allow_create=s,e},Sao.common.update_completion=function(t,e,i,n,o){var s=t.val();if(!s||!n)return jQuery.when();void 0===o&&(o=i.get_domain(e));var a=i.get_search_context(e),i=i.get_search_order(e);return new Sao.Model(n).execute("autocomplete",[s,o,Sao.config.limit,i],a).then(function(e){return e.filter(e=>e.id||t.completion._allow_create).map(e=>(null===e.id&&(e.name=Sao.i18n.gettext('Create "%1"...',e.name)),e))},function(){Sao.Logger.warn("Unable to search for completion of %s",n)})},Sao.common.Paned=Sao.class_(Object,{init:function(e){var t;this._orientation=e,this.el=jQuery("<div/>"),"horizontal"==e?(t=jQuery("<div/>",{class:"row"}).appendTo(this.el),this.child1=jQuery("<div/>",{class:"col-md-6"}).appendTo(t),this.child2=jQuery("<div/>",{class:"col-md-6"}).appendTo(t)):"vertical"==e&&(this.child1=jQuery("<div/>",{class:"row"}).appendTo(this.el),this.child2=jQuery("<div/>",{class:"row"}).appendTo(this.el))},get_child1:function(){return this.child1},get_child2:function(){return this.child2}}),Sao.common.get_focus_chain=function(e){e=e.find("input,select,textarea");return e.sort(function(e,t){return"tabindex"in e.attributes&&"tabindex"in t.attributes?parseInt(e.attributes.tabindex.value)-parseInt(t.attributes.tabindex.value):"tabindex"in e.attributes?-1:"tabindex"in t.attributes?1:0}),e},Sao.common.find_focusable_child=function(e){var t,i,n,o;if(!e.is(":visible"))return null;if(~["input","select","textarea"].indexOf(e[0].tagName.toLowerCase())&&!e.prop("readonly"))return e;for(t=0,i=(n=Sao.common.get_focus_chain(e)).length;t<i;t++)if(o=Sao.common.find_focusable_child(jQuery(n[t])))return o},Sao.common.find_first_focus_widget=function(e,t){var i,n,o,s;if(1==t.length)return jQuery(t[0]);for(o=Sao.common.get_focus_chain(e),i=0;i<o.length;i++){for(s=[],n=0;n<t.length;n++)0<jQuery(t[n]).closest(o[i]).length&&s.push(t[n]);if(0<s.length)return Sao.common.find_first_focus_widget(jQuery(o[i]),s)}},Sao.common.apply_label_attributes=function(e,t,i){t?e.removeClass("editable required"):(e.addClass("editable"),i?e.addClass("required"):e.removeClass("required"))},Sao.common.download_file=function(e,t,i){void 0===i&&(i={type:Sao.common.guess_mimetype(t)});var n,o,e=new Blob([e],i);window.navigator&&window.navigator.msSaveOrOpenBlob?window.navigator.msSaveOrOpenBlob(e,t):(i=window.URL.createObjectURL(e),n=new Sao.Dialog(Sao.i18n.gettext("Download")),e=function(){n.modal.modal("hide")},o=jQuery("<a/>",{href:i,download:t,text:t,target:"_blank"}).appendTo(n.body).click(e),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("Close")}).text(Sao.i18n.gettext("Close")).click(e).appendTo(n.footer),n.modal.on("shown.bs.modal",function(){o[0].click()}),n.modal.modal("show"),n.modal.on("hidden.bs.modal",function(){jQuery(this).remove(),window.URL.revokeObjectURL(this.blob_url)}))},Sao.common.get_input_data=function(e,t,i){for(var n=0;n<e[0].files.length;n++)Sao.common.get_file_data(e[0].files[n],t,i)},Sao.common.get_file_data=function(t,i,n){var o=new FileReader;o.onload=function(){var e=new Uint8Array(o.result);n&&(e=String.fromCharCode.apply(null,e)),i(e,t.name)},o.readAsArrayBuffer(t)},Sao.common.ellipsize=function(e,t){var i;return e.length<=t?e:(i=Sao.i18n.gettext("..."),e.slice(0,t-i.length)+i)},Sao.common.accesskey=function(e){for(var t=0;t<e.length;t++){var i=e.charAt(t).toLowerCase();if(!~["d","e","f","i","n","t","w"].indexOf(i))return i}},Sao.common.debounce=function(t,i){return(...e)=>{clearTimeout(t._debounceTimeout),t._debounceTimeout=setTimeout(()=>{t.apply(this,e)},i)}},Sao.common.uuid4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})},Sao.common.COLOR_SCHEMES={red:"#cf1d1d",green:"#3fb41b",blue:"#224565",grey:"#444444",black:"#000000",darkcyan:"#305755"},Sao.common.hex2rgb=function(e,t){t=t||2;var i=parseInt("f".repeat(t),16);return[parseInt(e.substring(1,t+1),16)/i,parseInt(e.substring(t+1,2*t+1),16)/i,parseInt(e.substring(2*t+1,3*t+1),16)/i]},Sao.common.rgb2hex=function(e,t){t=t||2;var i=parseInt("f".repeat(t),16);return"#"+e.map(function(e){return Math.round(e*i).toString(16)}).join("")},Sao.common.rgb2hsv=function(e){var t,i,n=e[0],o=e[1],s=e[2],a=Math.max.apply(null,e),e=Math.min.apply(null,e);return e==a?[0,0,a]:(t=(a-n)/(a-e),i=(a-o)/(a-e),s=(a-s)/(a-e),[(n==a?s-i:o==a?2+t-s:4+i-t)/6%1,(a-e)/a,a])},Sao.common.hsv2rgb=function(e){var t,i,n,o=e[0],s=e[1],e=e[2];return 0==s?[e,e,e]:(i=e*(1-s),n=e*(1-s*(t=6*o-(o=Math.trunc(6*o)))),s=e*(1-s*(1-t)),0==(o%=6)?[e,s,i]:1==o?[n,e,i]:2==o?[i,e,s]:3==o?[i,n,e]:4==o?[s,i,e]:5==o?[e,i,n]:void 0)},Sao.common.generateColorscheme=function(e,t,i=.1){for(var e=Sao.common.hex2rgb(Sao.common.COLOR_SCHEMES[e]||e),e=Sao.common.rgb2hsv(e),n=e[0],o=e[1],s=e[2],a=(t.length&&(i=Math.min(i,(1-s)/t.length)),{}),r=0;r<t.length;r++)a[t[r]]=Sao.common.rgb2hex(Sao.common.hsv2rgb([(n+.618033988749895*r)%1,o,(s+i*r)%1]));return a},Sao.common.richtext_toolbar=function(){function n(e){document.execCommand(e.data)}function e(e){var t=jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(o);for(const i of e)jQuery("<button/>",{class:"btn btn-default",type:"button",title:i.label}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-format-"+i.icon)).appendTo(t).click(i.command,n)}var o=jQuery("<div/>",{class:"btn-toolbar",role:"toolbar"});e([{icon:"bold",command:"bold",label:Sao.i18n.gettext("Bold")},{icon:"italic",command:"italic",label:Sao.i18n.gettext("Italic")},{icon:"underline",command:"underline",label:Sao.i18n.gettext("Underline")}]);var t;for(t of[{heading:Sao.i18n.gettext("Font"),options:["Normal","Serif","Sans","Monospace"],command:"fontname"},{heading:Sao.i18n.gettext("Size"),options:[1,2,3,4,5,6,7],command:"fontsize"}]){var i=jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(o),i=(jQuery("<button/>",{class:"btn btn-default dropdown-toggle",type:"button","data-toggle":"dropdown","aria-expanded":!1,"aria-haspopup":!0}).append(t.heading).append(jQuery("<span/>",{class:"caret"})).appendTo(i),jQuery("<ul/>",{class:"dropdown-menu"}).appendTo(i));t.options.forEach(function(e,i){return function(t){e.append(jQuery("<li/>").append(jQuery("<a/>",{href:"#"}).text(t).click(function(e){e.preventDefault(),document.execCommand(i.command,!1,t)})))}}(i,t))}return e([{icon:"align-left",command:Sao.i18n.rtl?"justifyRight":"justifyLeft",label:Sao.i18n.rtl?Sao.i18n.gettext("Justify Right"):Sao.i18n.gettext("Justify Left")},{icon:"align-center",command:"justifyCenter",label:Sao.i18n.gettext("Justify Center")},{icon:"align-right",command:Sao.i18n.rtl?"justifyLeft":"justifyRight",label:Sao.i18n.rtl?Sao.i18n.gettext("Justify Left"):Sao.i18n.gettext("Justify Right")},{icon:"align-justify",command:"justifyFull",label:Sao.i18n.gettext("Justify Full")}]),[["foreColor","#000000"]].forEach(function(e){var t=e[0],e=e[1];jQuery("<input/>",{class:"btn btn-default",type:"color"}).appendTo(o).change(function(){document.execCommand(t,!1,jQuery(this).val())}).focusin(function(){document.execCommand(t,!1,jQuery(this).val())}).val(e)}),o},Sao.common.richtext_normalize=function(e){e=jQuery("<div/>").html(e);return e.find("div").each(function(e,t){var i;(t=jQuery(t)).css("text-align")&&(i=t.css("text-align").split("-").pop(),t.attr("align",i),t.css("text-align","")),"start"==t.attr("align")&&(Sao.i18n.rtl?t.attr("align","right"):t.attr("align","left"))}),e.html()},Sao.common.image_url=function(e){if(!e)return null;var t="";try{var i=e;i instanceof Uint8Array&&(i=(new TextDecoder).decode(e)),jQuery.parseXML(i)&&(t="image/svg+xml")}catch(e){}i=new Blob([e],{type:t});return window.URL.createObjectURL(i)},Sao.common.play_sound=function(e="success"){e=new Audio("sounds/"+e+".wav");e.volume=localStorage.getItem("sao_sound_volume")||.5,e.play()}}(),!function(){"use strict";Sao.Model=Sao.class_(Object,{init:function(e,t){this.name=e,this.session=Sao.Session.current_session,this.fields={}},add_fields:function(e){var t,i=[];for(t in e){var n,o=e[t];t in this.fields?jQuery.extend(this.fields[t].description,o):(n=Sao.field.get(o.type),this.fields[t]=new n(o),i.push(t))}return i},execute:function(e,t,i={},n=!0,o=!0){e={method:"model."+this.name+"."+e,params:t.concat(i)};return Sao.rpc(e,this.session,n,o)},copy:function(e,t){return jQuery.isEmptyObject(e)?jQuery.when():(e=e.map(function(e){return e.id}),this.execute("copy",[e,{}],t))}}),Sao.Group=function(e,t,i){return i.prm=jQuery.when(),i.model=e,i._context=t,i.on_write=[],i.parent=void 0,i.screens=[],i.parent_name="",i.children=[],i.child_name="",i.parent_datetime_field=void 0,i.record_removed=[],i.record_deleted=[],i.__readonly=!1,i.exclude_field=null,i.skip_model_access=!1,i.forEach(function(e,t,i){e.group=i}),Object.defineProperty(i,"readonly",{get:function(){var e=Sao.common.MODELACCESS.get(this.model.name);return!(!this.context._datetime&&(e.write||e.create||this.skip_model_access))||this.__readonly},set:function(e){this.__readonly=e}}),i.load=function(e,t=!1,i=-1){-1==i&&(i=this.length);var n=[];for(const a of e){let e=this.get(a);e||(((e=new Sao.Record(this.model,a)).group=this).splice(i,0,e),i+=1),n.push(e)}var o=[];for(const r of this.record_removed)~e.indexOf(r.id)||o.push(r);this.record_removed=o;var s=[];for(const l of this.record_deleted)~e.indexOf(l.id)||s.push(l);if(this.record_deleted=s,n.length&&t){for(const c of n)c.modified_fields.id=!0;this.record_modified()}},i.get=function(e){for(const t of this)if(t.id==e)return t},i.new_=function(e,t,i=null){t=new Sao.Record(this.model,t);return t.group=this,e&&t.default_get(i),t},i.add=function(e,t=-1,i=!0){-1==t&&(t=this.length),t=Math.min(t,this.length),e.group!=this&&(e.group=this),this.indexOf(e)<0&&this.splice(t,0,e);for(var n of this.record_removed)n.id==e.id&&this.record_removed.splice(this.record_removed.indexOf(n),1);for(var o of this.record_deleted)o.id==e.id&&this.record_deleted.splice(this.record_deleted.indexOf(o),1);return e.modified_fields.id=!0,i&&this.parent&&this.model.fields[this.parent_name]&&((t=this.model.fields[this.parent_name])instanceof Sao.field.Many2One||t instanceof Sao.field.Reference)&&(i=[this.parent.id,""],t instanceof Sao.field.Reference&&(i=[this.parent.model.name,i]),t.set_client(e,i)),e},i.remove=function(e,t,i=!1,n=!0){this.indexOf(e);0<=e.id&&(t?(~this.record_deleted.indexOf(e)&&this.record_deleted.splice(this.record_deleted.indexOf(e),1),~this.record_removed.indexOf(e)||this.record_removed.push(e)):(~this.record_removed.indexOf(e)&&this.record_removed.splice(this.record_removed.indexOf(e),1),~this.record_deleted.indexOf(e)||this.record_deleted.push(e))),e.modified_fields.id=!0,(e.id<0||i)&&this._remove(e),n&&this.record_modified()},i._remove=function(e){e=this.indexOf(e);this.splice(e,1)},i.unremove=function(e){this.record_removed.splice(this.record_removed.indexOf(e),1),this.record_deleted.splice(this.record_deleted.indexOf(e),1),e.group.record_modified()},i.clear=function(){this.splice(0,this.length),this.record_removed=[],this.record_deleted=[]},i.record_modified=function(){if(this.parent)this.parent.modified_fields[this.child_name]=!0,this.parent.model.fields[this.child_name].changed(this.parent),this.parent.validate(null,!0,!1,!0),this.parent.group.record_modified();else for(const e of this.screens)e.record_modified()},i.record_notify=function(e){for(const t of this.screens)t.record_notify(e)},i.delete_=function(i){if(jQuery.isEmptyObject(i))return jQuery.when();var n=this.root_group,o=(Sao.Logger.assert(i.every(e=>e.model.name==this.model.name),"records not from the same model"),Sao.Logger.assert(i.every(e=>e.group.root_group==n),"records not from the same root group"),i=i.filter(e=>0<=e.id),this.context);o._timestamp={};for(const e of i)jQuery.extend(o._timestamp,e.get_timestamp());var s=i.map(function(e){return e.id});return n.on_write_ids(s).then(e=>{for(const t of i)t.destroy();return e=e.filter(e=>!~s.indexOf(e)),this.model.execute("delete",[s],o).then(()=>{n.reload(e)})})},Object.defineProperty(i,"root_group",{get:function(){for(var e=this,t=this.parent;t;)e=t.group,t=t.parent;return e}}),i.save=function(){var t=[];if(this.forEach(e=>{t.push(e.save())}),!jQuery.isEmptyObject(this.record_deleted)){for(const e of this.record_deleted)this._remove(e);t.push(this.delete_(this.record_deleted)),this.record_deleted.splice(0,this.record_deleted.length)}return jQuery.when.apply(jQuery,t)},i.written=function(t){return"number"==typeof t&&(t=[t]),this.on_write_ids(t).then(e=>{e=e.filter(e=>!~t.indexOf(e)),this.root_group.reload(e)})},i.reload=function(e){for(const i of this.children)i.reload(e);for(const n of e){var t=this.get(n);t&&jQuery.isEmptyObject(t.modified_fields)&&t.cancel()}},i.on_write_ids=function(t){var i=[],n=[];return this.on_write.forEach(e=>{e=this.model.execute(e,[t],this._context).then(e=>{jQuery.extend(n,e)});i.push(e)}),jQuery.when.apply(jQuery,i).then(()=>n.filter((e,t,i)=>t==i.indexOf(e)))},i.set_parent=function(e){(this.parent=e)&&e.model.name==this.model.name&&this.parent.group.children.push(this)},i.add_fields=function(e){e=this.model.add_fields(e);if(!jQuery.isEmptyObject(this)){var i=[];for(const t of this)t.id<0&&i.push(t);i.length&&e.length&&this.model.execute("default_get",[e,this.context]).then(e=>{for(const t of i)t.set_default(e,!0,!1);this.record_modified()})}},i.destroy=function(){var e;this.parent&&~(e=this.parent.group.children.indexOf(this))&&this.parent.group.children.splice(e,1),this.parent=null},Object.defineProperty(i,"domain",{get:function(){var e=[];for(const t of this.screens)t.attributes.domain&&e.push(t.attributes.domain);return this.parent&&this.child_name?[e,this.parent.model.fields[this.child_name].get_domain(this.parent)]:e}}),Object.defineProperty(i,"context",{get:function(){return this._get_context()},set:function(e){this._context=jQuery.extend({},e)}}),Object.defineProperty(i,"local_context",{get:function(){return this._get_context(!0)}}),i._get_context=function(e){var t,i,n=e?{}:jQuery.extend({},this.model.session.context);return this.parent&&(t=this.parent.get_context(e),jQuery.extend(n,t),this.child_name in this.parent.model.fields)&&(i=this.parent.model.fields[this.child_name],jQuery.extend(n,i.get_context(this.parent,t,e))),jQuery.extend(n,this._context),this.parent_datetime_field&&(n._datetime=this.parent.get_eval()[this.parent_datetime_field]),n},i.clean4inversion=function(e){var t,i;return jQuery.isEmptyObject(e)?[]:(i=new Sao.common.DomainInversion,t=e[0],e=e.slice(1),~["AND","OR"].indexOf(t)||(i.is_leaf(t)?(i=t[0])in this.model.fields&&this.model.fields[i].description.readonly&&(t=[]):t=this.clean4inversion(t)),[t].concat(this.clean4inversion(e)))},i.domain4inversion=function(){var e=this.domain;return this.__domain4inversion&&Sao.common.compare(this.__domain4inversion[0],e)||(this.__domain4inversion=[e,this.clean4inversion(e)]),this.__domain4inversion[1]},i.get_by_path=function(i){i=jQuery.extend([],i);var n=null,o=this,s=function(){var e,t;return jQuery.isEmptyObject(i)?n:(e=i[0][0],t=i[0][1],i.splice(0,1),(n=o.get(t))?e?n.load(e).then(function(){return(o=n._values[e])?s():null}):s():null)};return jQuery.when().then(s)},i.set_sequence=function(e,t){var i,n,o,s,a=!1,r=null,l=0===t?function(e,t){return t<e}:function(e,t){return e<t};for(const i of this)(i.get_loaded([e])||a||i.id<0)&&(n=r?(r.load(e,!1),r.field_get(e)):null,o=!1,null===(s=i.field_get(e))?n?o=!0:r&&(0<=i.id?o=l(i.id,r.id):0===t&&(o=!0)):s===n?r&&(0<=i.id?o=l(i.id,r.id):0===t&&(o=!0)):s<=(n||0)&&(o=!0),o)&&(null===n&&(n=0),n+=1,i.field_set_client(e,n),a=i),r=i},i},Sao.Record=Sao.class_(Object,{id_counter:-1,init:function(e,t=null){this.model=e,this.group=Sao.Group(e,{},[]),this.id=null===t?Sao.Record.prototype.id_counter:t,this.id<0&&Sao.Record.prototype.id_counter--,this._values={},this.modified_fields={},this._loaded={},this.fields={},this._timestamp=null,this._write=!0,this._delete=!0,this.resources=null,this.button_clicks={},this.links_counts={},this.state_attrs={},this.autocompletion={},this.exception=!1,this.destroyed=!1},get modified(){return!jQuery.isEmptyObject(this.modified_fields)&&(Sao.Logger.info("Modified fields of %s@%s",this.id,this.model.name,Object.keys(this.modified_fields)),!0)},save:function(t=!1){var e=this.get_context(),i=jQuery.when();if(this.id<0||this.modified){var n=this.get();if(this.id<0)try{this.id=this.model.execute("create",[[n]],e,!1)[0]}catch(e){return e.promise?e.then(()=>this.save(t)):jQuery.Deferred().reject()}else jQuery.isEmptyObject(n)||(e._timestamp=this.get_timestamp(),i=this.model.execute("write",[[this.id],n],e));i=i.done(()=>{if(this.cancel(),t)return this.reload()}),this.group&&(i=i.done(()=>this.group.written(this.id)))}return this.group.parent&&(delete this.group.parent.modified_fields[this.group.child_name],i=i.done(()=>this.group.parent.save(t))),i},reload:function(e,t=!0){if(this.id<0)return t?jQuery.when():null;if(!e)return this.load("*",t);var i,n;if(t)return i=e.map(e=>this.load(e)),jQuery.when.apply(jQuery,i);for(n of e)this.load(n,t)},is_loaded:function(e){return this.id<0||e in this._loaded},load:function(t,e=!0,i=!0){if(this.destroyed||this.is_loaded(t))return e?jQuery.when():"*"!==t?this.model.fields[t]:void 0;if(e&&"pending"==this.group.prm.state())return this.group.prm.then(()=>this.load(t));var n,o,s,l={};if(l[this.id]=this,"*"==t)for(var a in n="eager",o=new Set,this.model.fields){"lazy"==((s=this.model.fields[a]).description.loading||"eager")&&(n="lazy");for(const j of s.views)o.add(j)}else n=this.model.fields[t].description.loading||"eager",o=this.model.fields[t].views;var r={};if("eager"==n)for(a in this.model.fields)"eager"==((s=this.model.fields[a]).description.loading||"eager")&&(r[a]=s);else r=this.model.fields;var c=[];for(a in r)s=r[a],a in this._loaded||o.size&&!Sao.common.intersect(Array.from(o).sort(),Array.from(s.views).sort())||c.push(a);var d=c.slice(),h=["many2one","one2one","reference"],u=["selection","multiselection"];for(const a of c){var _=this.model.fields[a].description;~h.indexOf(_.type)?d.push(a+".rec_name"):~u.indexOf(_.type)&&"eager"==(_.loading||"lazy")&&d.push(a+":string")}~c.indexOf("rec_name")||d.push("rec_name"),d.push("_timestamp"),d.push("_write"),d.push("_delete");var m=jQuery.extend({},this.get_context());if("eager"==n){var p=Math.trunc(Sao.config.limit/Math.min(d.length,10));const O=e=>!e.destroyed&&0<=e.id&&!(t in e._loaded);var f,g=e=>O(e)&&void 0===l[e.id]&&(e.group===this.group||JSON.stringify(e.get_context())===JSON.stringify(m)),v=this.group.parent&&this.group.parent.model.name==this.model.name?(f=(f=[]).concat.apply(f,this.group.parent.group.children),g):(f=this.group,O),S=f.indexOf(this);if(~S)for(var y,b=f.length,w=1;Object.keys(l).length<p&&(0<=S-w||S+w<b)&&w<2*p;)0<=S-w&&v(y=f[S-w])&&(l[y.id]=y),S+w<b&&v(y=f[S+w])&&(l[y.id]=y),w++}for(a in this.model.fields)this.model.fields.hasOwnProperty(a)&&"binary"==this.model.fields[a].description.type&&~d.indexOf(a,d)&&(m[this.model.name+"."+a]="size");g=this.model.execute("read",[Object.keys(l).map(e=>parseInt(e,10)),d],m,e,i);const x=(e,t=!1)=>{var i,n={};for(const r of e)n[r.id]=r;for(i in l)if(l.hasOwnProperty(i)){var o=l[i],s=(o.exception||(o.exception=t),n[i]);if(o&&s){for(var a in this.modified_fields)this.modified_fields.hasOwnProperty(a)&&delete s[a];o.set(s,!1)}}};i=()=>{var e,t,i=[];for(t in l){e={id:t};for(const n of d)"id"!=n&&(e[n]=null);i.push(e)}return x(i,!0)};return e?(this.group.prm=g.then(x,i),this.group.prm):(g?x(g):i(),"*"!==t?this.model.fields[t]:void 0)},set:function(e,t=!0,i=!0){var n,o,s,a,r={},l=[];for(n in e)e.hasOwnProperty(n)&&(a=e[n],"_timestamp"==n?this._timestamp||(this._timestamp=a):"_write"==n||"_delete"==n?this[n]=a:n in this.model.fields?this.model.fields[n]instanceof Sao.field.One2Many?r[n]=a:((o=this.model.fields[n])instanceof Sao.field.Many2One||o instanceof Sao.field.Reference?this._values[s=n+"."]=e[s]||{}:(o instanceof Sao.field.Selection||o instanceof Sao.field.MultiSelection)&&((s=n+":string")in e?this._values[s]=e[s]:delete this._values[s]),this.model.fields[n].set(this,a),this._loaded[n]=!0,l.push(n)):"rec_name"==n&&(this._values[n]=a));for(n in r)this.model.fields[n].set(this,a=r[n]),this._loaded[n]=!0,l.push(n);i&&this.validate(l,!0,!1,!1),t&&this.set_modified()},get:function(){var e,t,i={};for(e in this.model.fields)this.model.fields.hasOwnProperty(e)&&((t=this.model.fields[e]).description.readonly&&(!(t instanceof Sao.field.One2Many)||t instanceof Sao.field.Many2Many)||void 0===this.modified_fields[e]&&0<=this.id||(i[e]=t.get(this),t instanceof Sao.field.One2Many&&0===i[e].length&&delete i[e]));return i},invalid_fields:function(){var e,t={};for(e in this.model.fields){var i=this.model.fields[e].get_state_attrs(this).invalid;i&&(t[e]=i)}return t},get_context:function(e){return e?this.group.local_context:this.group.context},field_get:function(e){return this.model.fields[e].get(this)},field_set:function(e,t){this.model.fields[e].set(this,t)},field_get_client:function(e){return this.model.fields[e].get_client(this)},field_set_client:function(e,t,i){this.model.fields[e].set_client(this,t,i)},default_get:function(e=null){if(jQuery.isEmptyObject(this.model.fields))return jQuery.when();var t=this.get_context();if(e)for(const i in e)Sao.setdefault(t,"default_"+i,e[i]);return this.model.execute("default_get",[Object.keys(this.model.fields)],t).then(e=>{var t;return this.group.parent&&this.group.parent_name in this.group.model.fields&&((t=this.group.model.fields[this.group.parent_name])instanceof Sao.field.Reference?e[this.group.parent_name]=[this.group.parent.model.name,this.group.parent.id]:t.description.relation==this.group.parent.model.name&&(e[this.group.parent_name]=this.group.parent.id)),this.set_default(e)})},set_default:function(e,t=!0,i=!0){var n,o,s,a=[],r=[];for(n in e)"_write"==n||"_delete"==n||"_timestamp"==n?this[n]=e[n]:e.hasOwnProperty(n)&&(o=e[n],n in this.model.fields)&&n!=this.group.exclude_field&&((this.model.fields[n]instanceof Sao.field.Many2One||this.model.fields[n]instanceof Sao.field.Reference)&&(this._values[s=n+"."]=e[s]||{}),a.push(this.model.fields[n].set_default(this,o)),this._loaded[n]=!0,r.push(n));return jQuery.when.apply(jQuery,a).then(()=>{this.on_change(r),this.on_change_with(r);var e=()=>{if(i)return this.set_modified(),jQuery.when.apply(jQuery,this.group.root_group.screens.map(e=>e.display()))};return t?this.validate(null,!0).then(e):e()})},get_timestamp:function(){var e,t={};for(e in t[this.model.name+","+this.id]=this._timestamp,this.model.fields)this.model.fields.hasOwnProperty(e)&&e in this._loaded&&jQuery.extend(t,this.model.fields[e].get_timestamp(this));return t},get_eval:function(){var e,t={};for(e in this.model.fields)!this._loaded.hasOwnProperty(e)&&0<=this.id||(t[e]=this.model.fields[e].get_eval(this));return t.id=this.id,t},get_on_change_value:function(e){var t,i={};for(t in this.model.fields)e&&~e.indexOf(t)||0<=this.id&&(!this._loaded[t]||!this.modified_fields[t])||(i[t]=this.model.fields[t].get_on_change_value(this));return i.id=this.id,i},_get_on_change_args:function(e){var t={},i=Sao.common.EvalEnvironment(this,"on_change");for(const o of e){var n=i;for(const s of o.split("."))void 0!==n&&(n=n[s]);t[o]=n}return t},on_change:function(e){var t,i={};for(const a of e){var n=this.model.fields[a].description.on_change;jQuery.isEmptyObject(n)||(i=jQuery.extend(i,this._get_on_change_args(n)))}if(!jQuery.isEmptyObject(i)){try{if(1==e.length||void 0===i.id){t=[];for(const r of e)t.push(this.model.execute("on_change_"+r,[i],this.get_context(),!1))}else t=[this.model.execute("on_change",[i,e],this.get_context(),!1)]}catch(e){return}t.forEach(this.set_on_change,this)}var o=Sao.common.MODELNOTIFICATION.get(this.model.name),s=new Set(o);e.some(e=>s.has(e))&&(i=this._get_on_change_args(o),this.model.execute("on_change_notify",[i],this.get_context()).then(this.group.record_notify.bind(this.group)))},on_change_with:function(e){var t,i,n,o={},s={},a={};for(t in this.model.fields)if(this.model.fields.hasOwnProperty(t)&&(i=this.model.fields[t].description.on_change_with,!jQuery.isEmptyObject(i))){for(var r=0;r<e.length&&!~i.indexOf(e[r]);r++);r>=e.length||(jQuery.isEmptyObject(Sao.common.intersect(Object.keys(o).sort(),i.sort()))?(o[t]=!0,s=jQuery.extend(s,this._get_on_change_args(i.concat([t]))),(this.model.fields[t]instanceof Sao.field.Many2One||this.model.fields[t]instanceof Sao.field.Reference)&&delete this._values[t+"."]):a[t]=!0)}if((o=Object.keys(o)).length){try{if(1==o.length||void 0===s.id){n={};for(const t of o)n=jQuery.extend(n,this.model.execute("on_change_with_"+t,[s],this.get_context(),!1))}else n=this.model.execute("on_change_with",[s,o],this.get_context(),!1)}catch(e){return}this.set_on_change(n)}if(!jQuery.isEmptyObject(a)){s={};for(const t in a)i=this.model.fields[t].description.on_change_with,s=jQuery.extend(s,this._get_on_change_args(i.concat([t])));o=Object.keys(a);try{if(1==o.length||void 0===s.id){n={};for(const t of o)n=jQuery.extend(n,this.model.execute("on_change_with_"+t,[s],this.get_context(),!1))}else n=this.model.execute("on_change_with",[s,o],this.get_context(),!1)}catch(e){return}this.set_on_change(n)}},set_on_change:function(e){for(var t in e){var i,n=e[t];t in this.model.fields&&((this.model.fields[t]instanceof Sao.field.Many2One||this.model.fields[t]instanceof Sao.field.Reference)&&(this._values[i=t+"."]=e[i]||{}),this.load(t,!1).set_on_change(this,n))}},autocomplete_with:function(e){for(var t in this.model.fields)~(this.model.fields[t].description.autocomplete||[]).indexOf(e)&&this.do_autocomplete(t)},do_autocomplete:function(e){this.autocompletion[e]=[];var t,i=this.model.fields[e].description.autocomplete,i=this._get_on_change_args(i);try{t=this.model.execute("autocomplete_"+e,[i],this.get_context(),!1)}catch(e){t=[]}this.autocompletion[e]=t},on_scan_code:function(e,t){t=this.expr_eval(t);t=this._get_on_change_args(t);return this.model.execute("on_scan_code",[t,e],this.get_context(),!0,!1).then(e=>(this.set_on_change(e),this.set_modified(),!jQuery.isEmptyObject(e)))},reset:function(e){this.cancel(),this.set(e,!0),this.group.parent&&(this.group.parent.on_change([this.group.child_name]),this.group.parent.on_change_with([this.group.child_name]))},expr_eval:function(e){var t,i;return"string"!=typeof e?e:e?"[]"==e?[]:"{}"==e?{}:((t=this.get_eval()).context=this.get_context(),t.active_model=this.model.name,t.active_id=this.id,this.group.parent&&this.group.parent_name&&(i=Sao.common.EvalEnvironment(this.group.parent),t["_parent_"+this.group.parent_name]=i),new Sao.PYSON.Decoder(t).decode(e)):void 0},rec_name:function(){return this.model.execute("read",[[this.id],["rec_name"]],this.get_context()).then(function(e){return e[0].rec_name})},validate:function(n,o,s,a){var e=()=>{var e,t,i=!0;for(e in this.model.fields)a&&0<=this.id&&!(e in this._loaded)||this.model.fields.hasOwnProperty(e)&&(t=this.model.fields[e],n&&!~n.indexOf(e)||t.description.readonly||e==this.group.exclude_field||t.validate(this,o,s)||(i=!1));return i};return a?(this._check_load(n,!1),e()):this._check_load(n).then(e)},pre_validate:function(){var e;return jQuery.isEmptyObject(this.modified_fields)?jQuery.Deferred().resolve(!0):(e=this._get_on_change_args(Object.keys(this.modified_fields).concat(["id"])),this.model.execute("pre_validate",[e],this.get_context()))},cancel:function(){this._loaded={},this._values={},this.modified_fields={},this._timestamp=null,this.button_clicks={},this.links_counts={},this.exception=!1},_check_load:function(e,t=!0){return this.get_loaded(e)?jQuery.when():this.reload(e,t)},get_loaded:function(e){if(jQuery.isEmptyObject(e))return Sao.common.compare(Object.keys(this.model.fields).sort(),Object.keys(this._loaded).sort());var t=!0;for(const i of e)i in this._loaded||i in this.modified_fields||(t=!1);return t},get root_parent(){for(var e=this;e.group.parent;)e=e.group.parent;return e},get_path:function(e){for(var t=[],i=this,n="";i&&(t.push([n,i.id]),i.group!==e);)n=i.group.child_name,i=i.group.parent;return t.reverse(),t},get_index_path:function(e){for(var t=[],i=this;i&&(t.push(i.group.indexOf(i)),i.group!==e);)i=i.group.parent;return t.reverse(),t},children_group:function(t){var i=jQuery.Deferred();return t?this._check_load([t]).done(()=>{var e=this._values[t];void 0===e?i.resolve(null):(e.model.fields!==this.group.model.fields&&(jQuery.extend(this.group.model.fields,e.model.fields),e.model.fields=this.group.model.fields),e.on_write=this.group.on_write,e.readonly=this.group.readonly,jQuery.extend(e._context,this.group._context),i.resolve(e))}):i.resolve([]),i},get deleted(){return Boolean(~this.group.record_deleted.indexOf(this))},get removed(){return Boolean(~this.group.record_removed.indexOf(this))},get readonly(){return this.deleted||this.removed||this.exception||this.group.readonly||!this._write},get deletable(){return this._delete},get identity(){return JSON.stringify(Object.keys(this._values).reduce((e,t)=>{var i=this.model.fields[t];return i&&(i instanceof Sao.field.Binary?e[t]=i.get_size(this):e[t]=i.get(this)),e},{}))},set_field_context:function(){for(var e in this.model.fields){var t,i;this.model.fields.hasOwnProperty(e)&&(t=this.model.fields[e],(e=this._values[e])instanceof Array)&&(i=Object.getOwnPropertyDescriptor(e,"context"))&&i.set&&(i=t.description.context)&&(e.context=this.expr_eval(i))}},get_resources:function(e){e=0<=this.id&&(!this.resources||e)?this.model.execute("resources",[this.id],this.get_context()).then(e=>this.resources=e):jQuery.when(this.resources);return e},get_button_clicks:function(t){var e;return this.id<0?jQuery.when():void 0!==(e=this.button_clicks[t])?jQuery.when(e):Sao.rpc({method:"model.ir.model.button.click.get_click",params:[this.model.name,t,this.id,{}]},this.model.session).then(e=>this.button_clicks[t]=e)},set_modified:function(e){e&&(this.modified_fields[e]=!0),this.group.record_modified()},destroy:function(){for(const e of Object.values(this._values))e&&e.hasOwnProperty("destroy")&&e.destroy();this.destroyed=!0}}),Sao.field={},Sao.field.get=function(e){switch(e){case"char":return Sao.field.Char;case"selection":return Sao.field.Selection;case"multiselection":return Sao.field.MultiSelection;case"datetime":case"timestamp":return Sao.field.DateTime;case"date":return Sao.field.Date;case"time":return Sao.field.Time;case"timedelta":return Sao.field.TimeDelta;case"float":return Sao.field.Float;case"numeric":return Sao.field.Numeric;case"integer":return Sao.field.Integer;case"boolean":return Sao.field.Boolean;case"many2one":return Sao.field.Many2One;case"one2one":return Sao.field.One2One;case"one2many":return Sao.field.One2Many;case"many2many":return Sao.field.Many2Many;case"reference":return Sao.field.Reference;case"binary":return Sao.field.Binary;case"dict":return Sao.field.Dict;default:return Sao.field.Char}},Sao.field.Field=Sao.class_(Object,{_default:null,_single_value:!0,init:function(e){this.description=e,this.name=e.name,this.views=new Set},set:function(e,t){e._values[this.name]=t},get:function(e){e=e._values[this.name];return e=void 0===e?this._default:e},_has_changed:function(e,t){return JSON.stringify(e)!=JSON.stringify(t)},set_client:function(e,t,i){var n=this.get(e);this.set(e,t),this._has_changed(n,this.get(e))?(this.changed(e),e.validate(null,!0,!1,!0),e.set_modified(this.name)):i&&(this.changed(e),e.validate(null,!0,!1,!0),e.set_modified())},get_client:function(e){return this.get(e)},set_default:function(e,t){this.set(e,t),e.modified_fields[this.name]=!0},set_on_change:function(e,t){this.set(e,t),e.modified_fields[this.name]=!0},changed:function(e){e.on_change([this.name]),e.on_change_with([this.name]),e.autocomplete_with(this.name),e.set_field_context()},get_timestamp:function(e){return{}},get_context:function(e,t,i){t=t?jQuery.extend({},t):e.get_context(i);return jQuery.extend(t,e.expr_eval(this.description.context||{})),t},get_search_context:function(e){var t=this.get_context(e);return jQuery.extend(t,e.expr_eval(this.description.search_context||{})),t},get_search_order:function(e){return e.expr_eval(this.description.search_order||null)},get_domains:function(e,t){t=(new Sao.common.DomainInversion).domain_inversion([e.group.domain4inversion(),t||[]],this.name,Sao.common.EvalEnvironment(e)),"boolean"!=typeof t||t?"boolean"==typeof t&&(t=t&&[]):t=[["id","=",null]],e=e.expr_eval(this.description.domain||[]);return[t,e]},get_domain:function(e){var e=this.get_domains(e),t=e[0],e=e[1],i=new Sao.common.DomainInversion;return i.concat([i.localize_domain(t),e])},validation_domains:function(e,t){return(new Sao.common.DomainInversion).concat(this.get_domains(e,t))},get_eval:function(e){return this.get(e)},get_on_change_value:function(e){return this.get_eval(e)},set_state:function(e,t=["readonly","required","invisible"]){var i=e.expr_eval(this.description.states||{});for(const n of t)"readonly"==n&&this.description.readonly||(void 0!==i[n]?this.get_state_attrs(e)[n]=i[n]:void 0!==this.description[n]&&(this.get_state_attrs(e)[n]=this.description[n]));(e.group.readonly||this.get_state_attrs(e).domain_readonly||e.parent_name==this.name)&&(this.get_state_attrs(e).readonly=!0)},get_state_attrs:function(e){return this.name in e.state_attrs||(e.state_attrs[this.name]=jQuery.extend({},this.description)),(e.group.readonly||e.readonly)&&(e.state_attrs[this.name].readonly=!0),e.state_attrs[this.name]},_is_empty:function(e){return!this.get_eval(e)},check_required:function(e){var t=this.get_state_attrs(e);return 1!=t.required||!this._is_empty(e)||1==t.readonly},validate:function(e,t,i){if(this.description.readonly)return!0;var n=!1,o=this.get_state_attrs(e),s=Boolean(parseInt(o.required,10)),a=Boolean(parseInt(o.invisible,10)),r=(o.domain_readonly=!1,new Sao.common.DomainInversion),l=r.simplify(this.validation_domains(e,i));if(t||this.check_required(e)||(n="required"),"boolean"==typeof l)l||(n="domain");else if(Sao.common.compare(l,[["id","=",null]]))n="domain";else{var[t,,]=this.get_domains(e,i),c=r.unique_value(l,this._single_value),d=c[0],h=c[1],c=c[2],t=r.unique_value(t,this._single_value)[0];if((!this._is_empty(e)||s||a||t)&&d){!1===c&&(c=null);s=!0,a=jQuery.isEmptyObject(e.group.domain)?r.merge(l):r.merge(e.group.domain),t="AND"==a[0];if(h.contains(".")){var d=h.split(".",1)[0],h=h.split(".",1)[1],u=[];if(t)for(const _ of r.localize_domain(a.slice(1)))u.push(_);"id"==h&&~u.indexOf(d)||(s=!1)}s&&jQuery.isEmptyObject(i)&&(this.set_client(e,c),o.domain_readonly=t)}r.eval_domain(l,Sao.common.EvalEnvironment(e))||(n=l)}return!(o.invalid=n)}}),Sao.field.Char=Sao.class_(Sao.field.Field,{_default:"",set:function(e,t){if(this.description.strip&&t)switch(this.description.strip){case"leading":t=t.trimStart();break;case"trailing":t=t.trimEnd();break;default:t=t.trim()}Sao.field.Char._super.set.call(this,e,t)},get:function(e){return Sao.field.Char._super.get.call(this,e)||this._default}}),Sao.field.Selection=Sao.class_(Sao.field.Field,{_default:null,set_client:function(e,t,i){delete e._values[this.name+":string"],Sao.field.Selection._super.set_client.call(this,e,t,i)}}),Sao.field.MultiSelection=Sao.class_(Sao.field.Selection,{_default:null,_single_value:!1,get:function(e){e=Sao.field.MultiSelection._super.get.call(this,e);return jQuery.isEmptyObject(e)?e=this._default:e.sort(),e},get_eval:function(e){e=Sao.field.MultiSelection._super.get_eval.call(this,e);return e=null===e?[]:e},set_client:function(e,t,i){t=(t="string"==typeof(t=null===t?[]:t)?[t]:t)&&t.slice().sort(),Sao.field.MultiSelection._super.set_client.call(this,e,t,i)}}),Sao.field.DateTime=Sao.class_(Sao.field.Field,{_default:null,time_format:function(e){return e.expr_eval(this.description.format)},set_client:function(e,t,i){var n;t&&(t.isTime?t=(n=this.get(e))?Sao.DateTime.combine(n,t):null:t.isDate&&(n=this.get(e)||Sao.Time(),t=Sao.DateTime.combine(t,n))),Sao.field.DateTime._super.set_client.call(this,e,t,i)},date_format:function(e){e=this.get_context(e);return Sao.common.date_format(e.date_format)}}),Sao.field.Date=Sao.class_(Sao.field.Field,{_default:null,set_client:function(e,t,i){t&&!t.isDate&&(t.isDate=!0,t.isDateTime=!1),Sao.field.Date._super.set_client.call(this,e,t,i)},date_format:function(e){e=this.get_context(e);return Sao.common.date_format(e.date_format)}}),Sao.field.Time=Sao.class_(Sao.field.Field,{_default:null,time_format:function(e){return e.expr_eval(this.description.format)},set_client:function(e,t,i){t&&(t.isDate||t.isDateTime)&&(t=Sao.Time(t.hour(),t.minute(),t.second(),t.millisecond())),Sao.field.Time._super.set_client.call(this,e,t,i)}}),Sao.field.TimeDelta=Sao.class_(Sao.field.Field,{_default:null,converter:function(e){return e.context[this.description.converter]},set_client:function(e,t,i){"string"==typeof t&&(t=Sao.common.timedelta.parse(t,this.converter(e.group))),Sao.field.TimeDelta._super.set_client.call(this,e,t,i)},get_client:function(e){var t=Sao.field.TimeDelta._super.get_client.call(this,e);return Sao.common.timedelta.format(t,this.converter(e.group))}}),Sao.field.Float=Sao.class_(Sao.field.Field,{_default:null,init:function(e){Sao.field.Float._super.init.call(this,e),this._digits={},this._symbol={}},digits:function(e,t=1){var i=e.expr_eval(this.description.digits);if("string"==typeof i){if(!(i in e.model.fields))return;var n=e.model.fields[i],o=n.description.relation,n=n.get(e);if(!(o&&null!==n&&0<=n))return;if(n in this._digits)i=this._digits[n];else{try{i=Sao.rpc({method:"model."+o+".get_digits",params:[n,{}]},e.model.session,!1)}catch(e){return void Sao.Logger.warn("Fail to fetch digits for %s,%s",o,n)}this._digits[n]=i}}if(i&&i.every(function(e){return null!==e}))return e=Math.round(Math.log(Math.abs(t))/Math.LN10),[i[0]+e,i[1]-e]},get_symbol:function(e,t){if(e&&t in e.model.fields){var i=this.get(e)||0,n=1,i=(i<0?n=-1:0===i&&(n=0),e.model.fields[t]),t=i.description.relation,i=i.get(e);if(t&&null!==i&&0<=i){if(i in this._symbol)return this._symbol[i];try{var o=Sao.rpc({method:"model."+t+".get_symbol",params:[i,n,e.get_context()]},e.model.session,!1)||["",1];return this._symbol[i]=o}catch(e){Sao.Logger.warn("Fail to fetch symbol for %s,%s",t,i)}}}return["",1]},check_required:function(e){var t=this.get_state_attrs(e);return 1!=t.required||null!==this.get(e)||1==t.readonly},convert:function(e){return e||0===e?(e=Number(e),isNaN(e)?this._default:e):null},apply_factor:function(e,t,i){return null!==t&&(t/=i,(i=this.digits(e))&&(t=t.toFixed(i[1])),t=this.convert(t)),t},set_client:function(e,t,i,n=1){t=this.apply_factor(e,this.convert(t),n),Sao.field.Float._super.set_client.call(this,e,t,i)},get_client:function(e,t=1,i=!0){var n=this.get(e);return null!==n?(i={useGrouping:i},(e=this.digits(e,t))&&(i.minimumFractionDigits=e[1],i.maximumFractionDigits=e[1]),(n*t).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),i)):""}}),Sao.field.Numeric=Sao.class_(Sao.field.Float,{convert:function(e){return e||0===e?(e=new Sao.Decimal(e),isNaN(e.valueOf())?this._default:e):null}}),Sao.field.Integer=Sao.class_(Sao.field.Float,{convert:function(e){return e||0===e?(e=parseInt(e,10),isNaN(e)?this._default:e):null}}),Sao.field.Boolean=Sao.class_(Sao.field.Field,{_default:!1,set_client:function(e,t,i){t=Boolean(t),Sao.field.Boolean._super.set_client.call(this,e,t,i)},get:function(e){return Boolean(e._values[this.name])},get_client:function(e){return Boolean(e._values[this.name])}}),Sao.field.Many2One=Sao.class_(Sao.field.Field,{_default:null,check_required:function(e){var t=this.get_state_attrs(e);return 1!=t.required||null!==this.get(e)||1==t.readonly},get_client:function(e){var t=(e._values[this.name+"."]||{}).rec_name;return void 0===t&&(this.set(e,this.get(e)),t=(e._values[this.name+"."]||{}).rec_name||""),t},set:function(e,t){var i,n=(e._values[this.name+"."]||{}).rec_name||"";!n&&0<=t&&null!==t&&(i=e.model.fields[this.name].description.relation,n=Sao.rpc({method:"model."+i+".read",params:[[t],["rec_name"],e.get_context()]},e.model.session,!1)[0].rec_name),Sao.setdefault(e._values,this.name+".",{}).rec_name=n,e._values[this.name]=t},set_client:function(e,t,i){var n;t instanceof Array?(n=t[1],t=t[0]):n=t==this.get(e)&&(e._values[this.name+"."]||{}).rec_name||"",t<0&&this.name!=e.group.parent_name&&(t=null,n=""),Sao.setdefault(e._values,this.name+".",{}).rec_name=n,Sao.field.Many2One._super.set_client.call(this,e,t,i)},get_context:function(e,t,i){t=Sao.field.Many2One._super.get_context.call(this,e,t,i);return this.description.datetime_field&&(t._datetime=e.get_eval()[this.description.datetime_field]),t},validation_domains:function(e,t){return this.get_domains(e,t)[0]},get_domain:function(e){var e=this.get_domains(e),t=e[0],e=e[1],i=new Sao.common.DomainInversion;return i.concat([i.localize_domain(t,this.name),e])},get_on_change_value:function(e){return e.group.parent_name==this.name&&e.group.parent?e.group.parent.get_on_change_value([e.group.child_name]):Sao.field.Many2One._super.get_on_change_value.call(this,e)}}),Sao.field.One2One=Sao.class_(Sao.field.Many2One,{}),Sao.field.One2Many=Sao.class_(Sao.field.Field,{init:function(e){Sao.field.One2Many._super.init.call(this,e)},_default:null,_single_value:!1,_set_value:function(e,t,i,n){this._set_default_value(e);var o,s=e._values[this.name];jQuery.when();if(jQuery.isEmptyObject(t)&&(t=[]),"list values"==(o=jQuery.isEmptyObject(t)||!isNaN(parseInt(t[0],10))?"list ids":"list values")){var a=this.get_context(e),r=new Set;for(const h of t)for(const u in h)u in s.model.fields||~u.indexOf(".")||r.add(u);if(r.size){var l,a={method:"model."+this.description.relation+".fields_get",params:[Array.from(r),a]};try{l=Sao.rpc(a,e.model.session,!1)}catch(e){return}s.add_fields(l)}}if("list ids"==o){var c=[];for(const _ of s)~t.indexOf(_.id)||c.push(_);for(const m of c)s.remove(m,!0,!1,!1);s.load(t,n||i)}else{for(const p of t){var d="id"in p?(d=s.get(p.id))||s.new_(!1,p.id):s.new_(!1);i?(d.set_default(p,!1,!1),s.add(d,-1,!1)):(d.set(p,!1),s.push(d))}s.record_modified()}},set:function(e,t,i=!1){var n,o=e._values[this.name];void 0!==o?(n=o.model,o.destroy()):n=e.model.name==this.description.relation?e.model:new Sao.Model(this.description.relation),e._values[this.name]=void 0,this._set_default_value(e,n),this._set_value(e,t,i)},get:function(e){e=e._values[this.name];if(void 0===e)return[];var t,i=e.record_removed,n=e.record_deleted,o=[],s=this.description.relation_field||"",a=[],r=[],l=[];for(const c of e)~i.indexOf(c)||~n.indexOf(c)||(0<=c.id?c.modified&&(delete(t=c.get())[s],jQuery.isEmptyObject(t)||(l.push([c.id]),l.push(t)),a.push(c.id)):(delete(t=c.get())[s],r.push(t)));return jQuery.isEmptyObject(a)||o.push(["add",a]),jQuery.isEmptyObject(r)||o.push(["create",r]),jQuery.isEmptyObject(l)||o.push(["write"].concat(l)),jQuery.isEmptyObject(i)||o.push(["remove",i.map(function(e){return e.id})]),jQuery.isEmptyObject(n)||o.push(["delete",n.map(function(e){return e.id})]),o},set_client:function(e,t,i){"number"==typeof(t=null===t?[]:t)&&(t=[t]);var n=this.get_eval(e),n=!Sao.common.compare(n.sort(),t.sort());this._set_value(e,t,!1,n),n?(this.changed(e),e.validate(null,!0,!1,!0),e.set_modified(this.name)):i&&(this.changed(e),e.validate(null,!0,!1,!0),e.set_modified())},get_client:function(e){return this._set_default_value(e),e._values[this.name]},set_default:function(e,t){return e.modified_fields[this.name]=!0,this.set(e,t,!0)},set_on_change:function(e,t){var i;if(e.modified_fields[this.name]=!0,this._set_default_value(e),t instanceof Array)return this._set_value(e,t,!1,!0);var n={};if(t&&(t.add||t.update)){var o=this.get_context(e),s=e._values[this.name].model.fields,a=[];if(t.add)for(const g of t.add)a.push(g[1]);for(const v of[a,t.update])if(!jQuery.isEmptyObject(v))for(const S of v)for(const y of Object.keys(S))y in s||"id"==y||~y.indexOf(".")||(n[y]=!0);if(jQuery.isEmptyObject(n))i={};else{o={method:"model."+this.description.relation+".fields_get",params:[Object.keys(n),o]};try{i=Sao.rpc(o,e.model.session,!1)}catch(e){return}}}var r,l=e._values[this.name];if(t&&t.delete)for(const b of t.delete){var c=l.get(b);c&&l.remove(c,!1,!1,!1)}if(t&&t.remove)for(const w of t.remove){var d=l.get(w);d&&l.remove(d,!0,!1,!1)}if(t&&(t.add||t.update)){if(t.update)for(const x of t.update)if(x.id){var h=l.get(x.id);if(h){var u,_={};for(u in x)u in n||(_[u]=x[u]);h.set_on_change(_)}}if(l.add_fields(i),t.add)for(const j of t.add){let e;var m=j[0],p=j[1],f=p.id;delete p.id,e=(e=f?l.get(f):e)||l.new_(!1,f),l.add(e,m,!1),e.set_on_change(p)}if(t.update)for(const O of t.update)O.id&&(r=l.get(O.id))&&r.set_on_change(O)}},_set_default_value:function(e,t){var i;void 0===e._values[this.name]&&(t=t||new Sao.Model(this.description.relation),e.model.name==this.description.relation&&(t=e.model),i=e.expr_eval(this.description.context||{}),(t=Sao.Group(t,i,[])).set_parent(e),t.parent_name=this.description.relation_field,t.child_name=this.name,t.parent_datetime_field=this.description.datetime_field,e._values[this.name]=t)},get_timestamp:function(e){var t={},i=e._values[this.name]||[],n=i.filter(function(e){return e.modified});for(const e of jQuery.extend(n,i.record_removed,i.record_deleted))jQuery.extend(t,e.get_timestamp());return t},get_eval:function(e){var t=[],e=e._values[this.name];if(void 0!==e){var i=e.record_removed,n=e.record_deleted;for(const o of e)~i.indexOf(o)||~n.indexOf(o)||t.push(o.id)}return t},get_on_change_value:function(e){var t=[],e=e._values[this.name];if(void 0!==e)for(const i of e)i.deleted||i.removed||t.push(i.get_on_change_value([this.description.relation_field||""]));return t},get_removed_ids:function(e){return e._values[this.name].record_removed.map(function(e){return e.id})},get_domain:function(e){return this.get_domains(e)[1]},validation_domains:function(e,t){return this.get_domains(e,t)[0]},validate:function(e,t,i){var n=!1,o=new Sao.common.DomainInversion,s=o.localize_domain(o.domain_inversion(e.group.clean4inversion(i||[]),this.name,Sao.common.EvalEnvironment(e)),this.name);"boolean"==typeof s&&(s=s?[]:[["id","=",null]]);for(const a of e._values[this.name]||[])!a.get_loaded()&&0<=a.id&&jQuery.isEmptyObject(i)||a.validate(null,t,s,!0)||(n="children");o=Sao.field.One2Many._super.validate.call(this,e,t,i);return o&&n?(this.get_state_attrs(e).invalid=n,!1):o},set_state:function(e,t){this._set_default_value(e),Sao.field.One2Many._super.set_state.call(this,e,t)},_is_empty:function(e){return jQuery.isEmptyObject(this.get_eval(e))}}),Sao.field.Many2Many=Sao.class_(Sao.field.One2Many,{get_on_change_value:function(e){return this.get_eval(e)}}),Sao.field.Reference=Sao.class_(Sao.field.Field,{_default:null,get_client:function(e){return e._values[this.name]?[e._values[this.name][0],(e._values[this.name+"."]||{}).rec_name||""]:null},get:function(e){return e._values[this.name]&&e._values[this.name][0]&&null!==e._values[this.name][1]&&-1<=e._values[this.name][1]?e._values[this.name].join(","):null},set_client:function(e,t,i){var n,o,s;t&&(n=(t="string"==typeof t?t.split(","):t)[0],(o=t[1])instanceof Array?(s=o[1],o=o[0]):s=[n,o=o&&!isNaN(parseInt(o,10))?parseInt(o,10):o].join(",")==this.get(e)&&(e._values[this.name+"."]||{}).rec_name||"",Sao.setdefault(e._values,this.name+".",{}).rec_name=s,t=[n,o]),Sao.field.Reference._super.set_client.call(this,e,t,i)},set:function(e,t){var i,n;t?("string"==typeof t?(i=t.split(",")[0],(n=t.split(",")[1])?isNaN(parseInt(n,10))||(n=parseInt(n,10)):n=null):(i=t[0],n=t[1]),t=(e._values[this.name+"."]||{}).rec_name||"",i&&null!==n&&0<=n?!t&&0<=n&&(t=Sao.rpc({method:"model."+i+".read",params:[[n],["rec_name"],e.get_context()]},e.model.session,!1)[0].rec_name):t=i?"":n,Sao.setdefault(e._values,this.name+".",{}).rec_name=t,e._values[this.name]=[i,n]):e._values[this.name]=this._default},get_on_change_value:function(e){return e.group.parent_name==this.name&&e.group.parent?[e.group.parent.model.name,e.group.parent.get_on_change_value([e.group.child_name])]:Sao.field.Reference._super.get_on_change_value.call(this,e)},get_context:function(e,t,i){t=Sao.field.Reference._super.get_context.call(this,e,t,i);return this.description.datetime_field&&(t._datetime=e.get_eval()[this.description.datetime_field]),t},validation_domains:function(e,t){return this.get_domains(e,t)[0]},get_domains:function(e,t){var i=null,e=(e._values[this.name]&&(i=e._values[this.name][0]),Sao.field.Reference._super.get_domains.call(this,e,t));return e[1]=e[1][i]||[],e},get_domain:function(e){var t=null,e=(e._values[this.name]&&(t=e._values[this.name][0]),this.get_domains(e)),i=e[0],e=e[1],n=new Sao.common.DomainInversion,i=n.filter_leaf(i,this.name,t);return i=n.prepare_reference_domain(i,this.name),n.concat([n.localize_domain(i,this.name,!0),e])},get_search_order:function(e){var t,i=Sao.field.Reference._super.get_search_order.call(this,e);return null!==i&&(t=null,i=i[t=e._values[this.name]?e._values[this.name][0]:t]||null),i},get_models:function(e){var e=this.get_domains(e),t=new Sao.common.DomainInversion,i=t.prepare_reference_domain(e[0],this.name);return t.extract_reference_models(t.concat([i,e[1]]),this.name)},_is_empty:function(e){var t=Sao.field.Reference._super._is_empty.call(this,e);return t=!t&&e._values[this.name][1]<0?!0:t}}),Sao.field.Binary=Sao.class_(Sao.field.Field,{_default:null,_has_changed:function(e,t){return e!=t},get_size:function(e){e=e._values[this.name]||0;return e instanceof Uint8Array||"string"==typeof e?e.length:e},get_data:function(t){var e=t._values[this.name],i=jQuery.when(e);if(!(e instanceof Uint8Array)&&"string"!=typeof e&&null!==e){if(t.id<0)return i;e=t.get_context(),i=t.model.execute("read",[[t.id],[this.name]],e).then(e=>(e=e[0][this.name],this.set(t,e),e))}return i}}),Sao.field.Dict=Sao.class_(Sao.field.Field,{_default:{},_single_value:!1,init:function(e){Sao.field.Dict._super.init.call(this,e),this.schema_model=new Sao.Model(e.schema_model),this.keys={}},set:function(e,t){if(t){var i,n=[];for(i in t)n.push(i);n.sort();var o,s={};for(o in n)s[i=n[o]]=t[i];t=s}Sao.field.Dict._super.set.call(this,e,t)},get:function(e){return jQuery.extend({},Sao.field.Dict._super.get.call(this,e))},get_client:function(e){return Sao.field.Dict._super.get_client.call(this,e)},validation_domains:function(e,t){return this.get_domains(e,t)[0]},get_domain:function(e){var t=new Sao.common.DomainInversion,e=this.get_domains(e),i=e[0],e=e[1];return t.concat([t.localize_domain(i),e])},date_format:function(e){e=this.get_context(e);return Sao.common.date_format(e.date_format)},time_format:function(e){return"%X"},add_keys:function(e,t){this.description.schema_model;for(var i=this.get_context(t),n=this.get_domain(t),o=Math.min(10,Sao.config.limit),s=(e=jQuery.extend([],e),e=>{for(const t of e)this.keys[t.name]=t}),a=[];0<e.length;){var r=e.splice(0,o);a.push(this.schema_model.execute("search_get_keys",[[["name","in",r],n],Sao.config.limit],i).then(s))}return jQuery.when.apply(jQuery,a)},add_new_keys:function(e,t){t=this.get_context(t);return this.schema_model.execute("get_keys",[e],t).then(e=>{var t=[];for(const i of e)this.keys[i.name]=i,t.push(i.name);return t})},validate:function(e,t,i){t=Sao.field.Dict._super.validate.call(this,e,t,i);if(this.description.readonly)return t;var n,o,s=new Sao.PYSON.Decoder,i=this.get_eval(e),a=[];for(n in i)n in this.keys&&(o=this.keys[n].domain)&&a.push(s.decode(o));i=(new Sao.common.DomainInversion).eval_domain(a,i);return i||(this.get_state_attrs(e).invalid="domain"),t&&i}})}(),!function(){"use strict";Sao.Tab=Sao.class_(Object,{init:function(e){Sao.Tab.tabs.push(this),this.attributes=jQuery.extend({},e),this.buttons={},this.menu_buttons={},this.id="tab-"+Sao.Tab.counter++,this.name="",this.name_el=jQuery("<span/>"),this.view_prm=jQuery.when()},menu_def:function(){return[{id:"switch_",icon:"tryton-switch",label:Sao.i18n.gettext("Switch"),tooltip:Sao.i18n.gettext("Switch view")},{id:"previous",icon:"tryton-back",label:Sao.i18n.gettext("Previous"),tooltip:Sao.i18n.gettext("Previous Record")},{id:"next",icon:"tryton-forward",label:Sao.i18n.gettext("Next"),tooltip:Sao.i18n.gettext("Next Record")},{id:"search",icon:"tryton-search",label:Sao.i18n.gettext("Search")},null,{id:"new_",icon:"tryton-create",label:Sao.i18n.gettext("New"),tooltip:Sao.i18n.gettext("Create a new record")},{id:"save",icon:"tryton-save",label:Sao.i18n.gettext("Save"),tooltip:Sao.i18n.gettext("Save this record")},{id:"reload",icon:"tryton-refresh",label:Sao.i18n.gettext("Reload/Undo"),tooltip:Sao.i18n.gettext("Reload")},{id:"copy",icon:"tryton-copy",label:Sao.i18n.gettext("Duplicate")},{id:"delete_",icon:"tryton-delete",label:Sao.i18n.gettext("Delete")},null,{id:"logs",icon:"tryton-log",label:Sao.i18n.gettext("View Logs...")},{id:this.screen&&Sao.common.MODELHISTORY.contains(this.screen.model_name)?"revision":null,icon:"tryton-history",label:Sao.i18n.gettext("Show revisions...")},null,{id:"attach",icon:"tryton-attach",label:Sao.i18n.gettext("Attachment"),tooltip:Sao.i18n.gettext("Add an attachment to the record"),dropdown:!0},{id:"note",icon:"tryton-note",label:Sao.i18n.gettext("Note"),tooltip:Sao.i18n.gettext("Add a note to the record")},{id:"action",icon:"tryton-launch",label:Sao.i18n.gettext("Action")},null,{id:"relate",icon:"tryton-link",label:Sao.i18n.gettext("Relate")},{id:"print",icon:"tryton-print",label:Sao.i18n.gettext("Print")},{id:"email",icon:"tryton-email",label:Sao.i18n.gettext("E-Mail..."),tooltip:Sao.i18n.gettext("Send an e-mail using the record")},null,{id:"export",icon:"tryton-export",label:Sao.i18n.gettext("Export")},{id:"import",icon:"tryton-import",label:Sao.i18n.gettext("Import")},null,{id:"close",icon:"tryton-close",label:Sao.i18n.gettext("Close Tab")}]},create_tabcontent:function(){this.el=jQuery("<div/>",{class:"panel panel-default "+this.class_});var e=this.create_toolbar().appendTo(this.el);this.title=e.find(".title"),this.main=jQuery("<div/>",{class:"panel-body row"}).appendTo(this.el),this.content=jQuery("<div/>",{class:"col-xs-12"}).appendTo(this.main),this.info_bar&&this.el.append(this.info_bar.el)},set_menu:function(n){var o;this.menu_def().forEach(t=>{if(t){if(!this[t.id])return;var i=jQuery("<li/>",{role:"presentation"}),e=jQuery("<a/>",{id:t.id,role:"menuitem",href:"#",tabindex:-1}).text(" "+t.label).prepend(Sao.common.ICONFACTORY.get_icon_img(t.icon,{"aria-hidden":"true"})).appendTo(i);this.menu_buttons[t.id]=i,e.click(e=>{e.preventDefault(),i.hasClass("disabled")||this[t.id]()})}else{if(!o)return;i=jQuery("<li/>",{role:"separator",class:"divider hidden-xs"})}(o=i).appendTo(n)})},create_toolbar:function(){var i,n=jQuery("<nav/>",{class:"toolbar panel-heading",role:"toolbar"}).append(jQuery("<div/>",{class:"container-fluid navbar-inverse"}).append(jQuery("<div/>",{class:"dropdown navbar-header navbar-left flip"}).append(jQuery("<a/>",{href:"#",class:"navbar-brand dropdown-toggle","data-toggle":"dropdown",role:"button","aria-expanded":!1,"aria-haspopup":!0}).append(jQuery("<span/>",{class:"title"})).append(jQuery("<span/>",{class:"caret"}))).append(jQuery("<ul/>",{class:"dropdown-menu",role:"menu"})).append(jQuery("<button/>",{type:"button",class:"close visible-xs","aria-label":Sao.i18n.gettext("Close"),title:Sao.i18n.gettext("Close")}).append(jQuery("<span/>",{"aria-hidden":!0}).append("×")).click(()=>{this.close()}))).append(jQuery("<div/>",{class:"btn-toolbar navbar-right flip",role:"toolbar"})));this.set_menu(n.find('ul[role*="menu"]'));return this.menu_def().forEach(e=>{var t;e&&e.tooltip?e.id&&this[e.id]&&(i=i||jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(n.find(".btn-toolbar")),t={type:"button",class:"btn btn-default navbar-btn",title:e.label,id:e.id},e.dropdown&&(t.class+=" dropdown-toggle",t["data-toggle"]="dropdown",t["aria-expanded"]=!1,t["aria-haspopup"]=!0),t=jQuery("<button/>",t).append(Sao.common.ICONFACTORY.get_icon_img(e.icon,{"aria-hidden":"true"})),this.buttons[e.id]=t,e.dropdown?jQuery("<div/>",{class:"btn-group dropdown",role:"group"}).append(t.append(jQuery("<span/>",{class:"caret"}))).append(jQuery("<ul/>",{class:"dropdown-menu",role:"menu","aria-labelledby":e.id})).appendTo(i):t.appendTo(i),this.buttons[e.id].click(e,e=>{var t=e.data,i=this.buttons[t.id];i.data("disabled")?e.preventDefault():(i.data("disabled",!0),(this[t.id](this)||jQuery.when()).always(function(){i.data("disabled",!1)}))})):i=null}),this.buttons.previous&&(this.status_label=jQuery("<span/>",{class:"badge"}).appendTo(jQuery("<div/>",{class:"navbar-text hidden-xs"}).insertAfter(this.buttons.previous)),this.buttons.previous.addClass("hidden-xs")),this.buttons.next&&this.buttons.next.addClass("hidden-xs"),n.find(".btn-toolbar > .btn-group").last().addClass("hidden-xs").find(".dropdown").on("show.bs.dropdown",function(){jQuery(this).parents(".btn-group").removeClass("hidden-xs")}).on("hide.bs.dropdown",function(){jQuery(this).parents(".btn-group").addClass("hidden-xs")}),n},show:function(){Sao.common.scrollIntoViewIfNeeded(jQuery("#tablist").find('a[href="#'+this.id+'"]').tab("show"))},close:function(){var i=jQuery("#tabs"),n=jQuery("#tablist").find("#nav-"+this.id),o=i.find("#"+this.id);return this.show(),this._close_allowed().then(()=>{var e=n.nextAll("li").first(),t=(e.length||(e=n.prevAll("li").first()),n.remove(),o.remove(),Sao.Tab.tabs.indexOf(this));0<=t&&Sao.Tab.tabs.splice(t,1),e.length?e.find("a").tab("show"):Sao.set_url(),i.trigger("ready")})},_close_allowed:function(){return jQuery.when()},set_name:function(e){this.name=e,this.name_el.text(e.split(" / ").pop()),this.name_el.attr("title",e)},get_url:function(){},compare:function(e){return!1}}),Sao.Tab.counter=0,Sao.Tab.tabs=[],Sao.Tab.tabs.close=function(e){var t;return e&&Sao.Tab.tabs.length?Sao.common.sur.run(Sao.i18n.gettext("The following action requires to close all tabs.\nDo you want to continue?")).then(function(){return Sao.Tab.tabs.close(!1)}):Sao.Tab.tabs.length?(t=Sao.Tab.tabs[0]).close().then(function(){return~Sao.Tab.tabs.indexOf(t)?jQuery.Deferred().reject():Sao.Tab.tabs.close()}):Sao.main_menu_screen?Sao.main_menu_screen.save_tree_state().then(function(){Sao.main_menu_screen=null}):jQuery.when()},Sao.Tab.tabs.get_current=function(){return jQuery("#tablist").find("li.active").data("tab")},Sao.Tab.tabs.close_current=function(){this.get_current().close()},Sao.Tab.create=function(e){var t,i=jQuery("#tablist");void 0===e.context&&(e.context={});for(const n of Sao.Tab.tabs)if(n.compare(e))return void Sao.common.scrollIntoViewIfNeeded(i.find('a[href="#'+n.id+'"]').tab("show"));(t=e.model?new Sao.Tab.Form(e.model,e):new Sao.Tab.Board(e)).view_prm.done(function(){Sao.Tab.add(t)})},Sao.Tab.add=function(t){var i=jQuery("#tabs"),e=jQuery("#tablist"),n=jQuery("#tabcontent"),o=jQuery("<a/>",{"aria-controls":t.id,role:"tab","data-toggle":"tab",href:"#"+t.id}).on("show.bs.tab",function(){Sao.set_url(t.get_url(),t.name.split(" / ").pop())}).append(jQuery("<button/>",{class:"close","aria-label":Sao.i18n.gettext("Close"),title:Sao.i18n.gettext("Close")}).append(jQuery("<span/>",{"aria-hidden":!0}).append("×")).click(function(e){e.preventDefault(),t.close()})).append(t.name_el);jQuery("<li/>",{role:"presentation","data-placement":"bottom",id:"nav-"+t.id}).append(o).appendTo(e).data("tab",t),jQuery("<div/>",{role:"tabpanel",class:"tab-pane",id:t.id}).append(t.el).appendTo(n),o.on("hide.bs.tab",function(e){jQuery(e.target).data("scrollTop",i.scrollTop())}),o.on("shown.bs.tab",function(e){i.scrollTop(jQuery(e.target).data("scrollTop")||0)}),Sao.common.scrollIntoViewIfNeeded(o.tab("show")),i.trigger("ready")},Sao.Tab.previous_tab=function(){Sao.Tab.move("prevAll")},Sao.Tab.next_tab=function(){Sao.Tab.move("nextAll")},Sao.Tab.move=function(e){var t=this.tabs.get_current(),i=jQuery("#tabs"),n=jQuery("#tablist"),t=n.find("#nav-"+t.id)[e]("li").first();(t=t.length?t:"prevAll"==e?n.find("li").last():n.find("li").first())&&(t.find("a").tab("show"),i.trigger("ready"))},Sao.Tab.Form=Sao.class_(Sao.Tab,{class_:"tab-form",init:function(e,t){Sao.Tab.Form._super.init.call(this,t);var i=(i=(t=jQuery.extend({},t)).name)||Sao.common.MODELNAME.get(e),n=(this.set_name(i),t.res_id&&t.hasOwnProperty("tab_domain")&&delete t.tab_domain,t.breadcrumb=[i],new Sao.Screen(e,t));n.windows.push(this),this.screen=n,this.info_bar=new Sao.Window.InfoBar,this.create_tabcontent(),this.attachment_screen=null,n.switch_callback=()=>{this===Sao.Tab.tabs.get_current()&&Sao.set_url(this.get_url(),this.name.split(" / ").pop())},this.view_prm=this.screen.switch_view().done(()=>{this.set_buttons_sensitive(),this.content.append(n.screen_container.el),t.res_id?(jQuery.isArray(t.res_id)||(t.res_id=[t.res_id]),n.load(t.res_id),t.res_id.length&&(n.current_record=n.group.get(t.res_id[0])),n.display()):("form"==n.current_view.view_type&&n.new_(),~["tree","graph","calendar"].indexOf(n.current_view.view_type)&&n.search_filter()),this.update_revision()})},create_toolbar:function(){var i=Sao.Tab.Form._super.create_toolbar.call(this),l=this.screen,n=l.model.execute("view_toolbar_get",[],l.context,!1);return[["action","tryton-launch",Sao.i18n.gettext("Launch action")],["relate","tryton-link",Sao.i18n.gettext("Open related records")],["print","tryton-print",Sao.i18n.gettext("Print report")]].forEach(a=>{var e=jQuery("<div/>",{class:"btn-group dropdown",role:"group"}).append(jQuery("<button/>",{type:"button",class:"btn btn-default navbar-btn dropdown-toggle","data-toggle":"dropdown","aria-expanded":!1,"aria-haspopup":!0,title:a[2],id:a[0]}).append(Sao.common.ICONFACTORY.get_icon_img(a[1],{"aria-hidden":"true"})).append(jQuery("<span/>",{class:"caret"}))).append(jQuery("<ul/>",{class:"dropdown-menu",role:"menu","aria-labelledby":a[0]})).insertBefore(i.find("button#email")),t=e.find("button"),r=(this.buttons[a[0]]=t,e.on("show.bs.dropdown",function(){jQuery(this).parents(".btn-group").removeClass("hidden-xs")}).on("hide.bs.dropdown",function(){jQuery(this).parents(".btn-group").addClass("hidden-xs")}),e.find(".dropdown-menu"));t.click(function(){r.find(["."+a[0]+"_button",".divider-button","."+a[0]+"_plugin",".divider-plugin"].join(",")).remove();var e=l.get_buttons().filter(function(e){return a[0]==(e.attributes.keyword||"action")}),t=(e.length&&r.append(jQuery("<li/>",{role:"separator",class:"divider divider-button"})),e.forEach(function(t){jQuery("<li/>",{role:"presentation",class:a[0]+"_button"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(t.attributes.string||"")).click(function(e){e.preventDefault(),l.button(t.attributes)}).appendTo(r)}),[]);for(const o of Sao.Plugins)for(const s of o.get_plugins(l.model.name)){var i=s[0],n=s[1];(s[2]||"action")==a[0]&&t.push([i,n])}t.length&&r.append(jQuery("<li/>",{role:"separator",class:"divider divider-plugin"})),t.forEach(function(e){var t=e[0],n=e[1];jQuery("<li/>",{role:"presentation",class:a[0]+"_plugin"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(t)).click(function(e){e.preventDefault();var e=l.current_view.selected_records.map(function(e){return e.id}),t=l.current_record?l.current_record.id:null,i=l.context_screen?l.context_screen.model_name:null;n({model:l.model.name,model_context:i,id:t,ids:e,paths:l.selected_paths})}).appendTo(r)})}),n[a[0]].forEach(s=>{jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(s.name)).click(e=>{e.preventDefault(),this.modified_save().then(function(){var e,t=jQuery.extend({},s),i=null,n=(l.current_record&&(i=l.current_record.id),e="listed"==s.records?(n=l.listed_records,l.listed_paths):(n=l.selected_records,l.selected_paths),n.map(function(e){return e.id})),o=l.context_screen?l.context_screen.model_name:null,o={model:l.model_name,model_context:o,id:i,ids:n,paths:e};Sao.Action.execute(t,o,jQuery.extend({},l.local_context))})}).appendTo(r)}),"action"!=a[0]&&(t._can_be_sensitive=Boolean(r.children().length)),"print"==a[0]&&n.exports.length&&(t._can_be_sensitive=!0,n.print.length&&r.append(jQuery("<li/>",{role:"separator",class:"divider"})),n.exports.forEach(t=>{jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(t.name)).click(e=>{e.preventDefault(),this.do_export(t)}).appendTo(r)}))}),this.buttons.attach.on("dragover",!1).on("drop",this.attach_drop.bind(this)),i},create_tabcontent:function(){Sao.Tab.Form._super.create_tabcontent.call(this),this.attachment_preview=jQuery("<div/>",{class:"col-xs-12 attachment-preview"}).prependTo(this.main)},compare:function(e){var t;return!!e&&(t=Sao.common.compare,this.screen.model_name===e.model)&&this.attributes.res_id===e.res_id&&t(this.attributes.domain||[],e.domain||[])&&t(this.attributes.view_ids||[],e.view_ids||[])&&(e.view_ids||t(this.attributes.mode||["tree","form"],e.mode||["tree","form"]))&&JSON.stringify(this.screen.local_context)===JSON.stringify(e.context)&&t(this.attributes.search_value||[],e.search_value||[])&&JSON.stringify(this.screen.attributes.tab_domain)===JSON.stringify(e.tab_domain)},_close_allowed:function(){return this.modified_save().then(null,function(e){return e?jQuery.Deferred().resolve():jQuery.Deferred().reject()})},modified_save:function(){return this.screen.save_tree_state(),this.screen.current_view.set_value(),this.screen.modified()?Sao.common.sur_3b.run(Sao.i18n.gettext("This record has been modified\ndo you want to save it?")).then(e=>{switch(e){case"ok":return this.save();case"ko":var t=this.screen.current_record.id;return this.reload(!1).then(()=>t<0?jQuery.Deferred().reject(!0):this.screen.current_record&&t!=this.screen.current_record.id?jQuery.Deferred().reject():void 0);default:return jQuery.Deferred().reject()}}):jQuery.when()},new_:function(){return Sao.common.MODELACCESS.get(this.screen.model_name).create?this.modified_save().then(()=>this.screen.new_().then(()=>{this.info_bar.clear(),this.set_buttons_sensitive()})):jQuery.when()},save:function(e){e&&this.screen.save_tree_state();e=Sao.common.MODELACCESS.get(this.screen.model_name);return e.write||e.create?this.screen.save_current().then(()=>{this.info_bar.add(Sao.i18n.gettext("Record saved."),"info"),this.screen.count_tab_domain(!0)},()=>(this.info_bar.add(this.screen.invalid_message(),"danger"),jQuery.Deferred().reject())):jQuery.Deferred().reject()},switch_:function(){return this.modified_save().then(()=>this.screen.switch_view())},reload:function(e=!0){var t=()=>this.screen.cancel_current().then(()=>{var t=!1,i=null;return this.screen.current_record&&(i=this.screen.current_record.id),"form"!=this.screen.current_view.view_type?this.screen.search_filter(this.screen.screen_container.search_entry.val()).then(()=>{for(const e of this.screen.group)e.id==i&&(this.screen.current_record=e,t=!0);return t}):t}).then(e=>this.screen.display(e).then(()=>{this.info_bar.clear(),this.set_buttons_sensitive(),this.screen.count_tab_domain()}));return e?this.modified_save().then(t):(this.screen.save_tree_state(!1),t())},copy:function(){return Sao.common.MODELACCESS.get(this.screen.model_name).create?this.modified_save().then(()=>this.screen.copy().then(()=>{this.info_bar.add(Sao.i18n.gettext("Working now on the duplicated record(s)."),"info"),this.screen.count_tab_domain(!0)})):jQuery.when()},delete_:function(){var e;return Sao.common.MODELACCESS.get(this.screen.model_name).delete?(e="form"==this.screen.current_view.view_type?Sao.i18n.gettext("Are you sure to remove this record?"):Sao.i18n.gettext("Are you sure to remove those records?"),Sao.common.sur.run(e).then(()=>this.screen.remove(!0,!1,!0).then(()=>{this.info_bar.add(Sao.i18n.gettext("Records removed."),"info"),this.screen.count_tab_domain(!0)},()=>{this.info_bar.add(Sao.i18n.gettext("Records not removed."),"danger")}))):jQuery.when()},previous:function(){return this.modified_save().then(()=>{var e=this.screen.display_previous();return this.info_bar.clear(),this.set_buttons_sensitive(),e})},next:function(){return this.modified_save().then(()=>{var e=this.screen.display_next();return this.info_bar.clear(),this.set_buttons_sensitive(),e})},search:function(){var e=this.screen.screen_container.search_entry;return e.is(":visible")&&window.setTimeout(function(){e.focus()},0),jQuery.when()},logs:function(){var e=this.screen.current_record;if(!e||e.id<0)return this.info_bar.add(Sao.i18n.gettext("You have to select one record."),"info"),jQuery.when();new Sao.Window.Log(e)},revision:function(){var i=null;this.screen.current_record&&(i=this.screen.current_record.id);const n=t=>e=>{e&&e.add(1,"milliseconds"),(e="form"==this.screen.current_view.view_type&&e&&e<t[t.length-1][0]?t[t.length-1][0]:e)!=this.screen.context._datetime&&(this.screen.clear(),this.screen.group._context._datetime=e,"form"!=this.screen.current_view.view_type?this.screen.search_filter(this.screen.screen_container.search_entry.val()):this.screen.group.load([i]),this.screen.display(!0),this.update_revision())};return this.modified_save().then(()=>{var e=this.screen.current_view.selected_records.map(e=>e.id);return this.screen.model.execute("history_revisions",[e],this.screen.context).then(e=>{var t=this.screen.context._datetime;t&&t.add(-1,"milliseconds"),new Sao.Window.Revision(e,t,n(e))})})},update_revision:function(){var e,t,i=this.screen.context._datetime;i=i?(e=Sao.common.date_format(this.screen.context.date_format),e=" @ "+Sao.common.format_datetime(e+" %H:%M:%S.%f",i),t=Sao.common.ellipsize(this.name,80-e.length)+e,this.name+e):(t=Sao.common.ellipsize(this.name,80),this.name),this.title.text(t),this.title.attr("title",i),this.set_buttons_sensitive()},set_buttons_sensitive:function(){if(this.screen.context._datetime)for(const i of["new_","save","delete_","copy","import"])this.buttons[i]&&this.buttons[i].prop("disabled",!0),this.menu_buttons[i]&&this.menu_buttons[i].addClass("disabled");else{var e=Sao.common.MODELACCESS.get(this.screen.model_name),t=this.screen.modified(),t=new Map([["new_",e.create&&!t],["save",(e.create||e.write)&&t&&!this.screen.readonly],["delete_",e.delete],["copy",e.create],["import",e.create]]);for(const[n,e]of t)this.buttons[n]&&this.buttons[n].prop("disabled",!e),this.menu_buttons[n]&&this.menu_buttons[n].toggleClass("disabled",!e)}},attach:function(e){const t=()=>new Sao.Window.Attachment(n,()=>{this.refresh_resources(!0)}),i=()=>{this.attachment_preview.children().length?(this.attachment_preview.empty(),this.attachment_screen=null,this.attachment_preview.removeClass("col-md-4 col-md-push-8"),this.content.removeClass("col-md-8 col-md-pull-4")):(this.attachment_preview.append(this._attachment_preview_el()),this.refresh_attachment_preview(),this.attachment_preview.addClass("col-md-4 col-md-push-8"),this.content.addClass("col-md-8 col-md-pull-4"))};var n,o,s=this.buttons.attach.parents(".dropdown");e?(n=this.screen.current_record,(o=s.find(".dropdown-menu")).empty(),Sao.Window.Attachment.get_attachments(n).then(function(e){e.forEach(function(e){var t=e[0],i=e[1],e=jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(t).appendTo(jQuery("<li/>",{role:"presentation"}).appendTo(o));"string"==typeof i?(e.attr("href",i),e.attr("target","_new")):e.click(function(e){e.preventDefault(),i()})})}).always(function(){o.append(jQuery("<li/>",{class:"divider"})),o.append(jQuery("<li/>",{role:"presentation",class:"input-file"}).append(jQuery("<input/>",{type:"file",role:"menuitem",multiple:!0,tabindex:-1}).change(function(){var i=t();Sao.common.get_input_data(jQuery(this),function(e,t){i.add_data(e,t)})})).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(Sao.i18n.gettext("Add...")))),o.append(jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(Sao.i18n.gettext("Preview")).click(function(e){e.preventDefault(),i()}))),o.append(jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(Sao.i18n.gettext("Manage...")).click(function(e){e.preventDefault(),t()})))})):window.setTimeout(()=>{this.buttons.attach.click()})},attach_drop:function(e){e.preventDefault(),e.stopPropagation(),e=e.originalEvent;var t=this.screen.current_record;if(t&&!(t.id<0)){var i,n,o=[],s=[],a=[];if(e.dataTransfer.items)for(Sao.Logger.debug("Attach drop items:",e.dataTransfer.items),i=0;i<e.dataTransfer.items.length;i++){var r,l=e.dataTransfer.items[i];if("string"==l.kind){if("text/uri-list"==l.type)r=s;else{if("text/plain"!=l.type)continue;r=a}l=jQuery.Deferred();e.dataTransfer.items[i].getAsString(l.resolve),r.push(l);break}(n=e.dataTransfer.items[i].getAsFile())&&o.push(n)}else for(i=0;i<e.dataTransfer.files.length;i++)(n=e.dataTransfer.files[i])&&o.push(n);var c=new Sao.Window.Attachment(t,()=>{this.refresh_resources(!0)});for(const n of o)Sao.common.get_file_data(n,c.add_data.bind(c));jQuery.when.apply(jQuery,s).then(function(){function e(e){return Boolean(e)}for(const t of arguments)t.split("\r\n").filter(e).forEach(c.add_uri,c)}),jQuery.when.apply(jQuery,a).then(function(){for(const e of arguments)c.add_text(e)}),e.dataTransfer.items?e.dataTransfer.items.clear():e.dataTransfer.clearData()}},_attachment_preview_el:function(){var e=jQuery("<div/>",{class:"text-center"}),t=jQuery("<div/>",{class:"btn-group"}).appendTo(e),i=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Previous"),title:Sao.i18n.gettext("Previous")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-back")).appendTo(t),n=jQuery("<span/>",{class:"badge"}).text("(0/0)").appendTo(jQuery("<span/>",{class:"btn btn-sm btn-link"}).appendTo(t)),o=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Next"),title:Sao.i18n.gettext("Next")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-forward")).appendTo(t),s=new Sao.Screen("ir.attachment",{readonly:!0,mode:["form"],context:{preview:!0}}),t=(this.attachment_screen=s,i.click(function(){return s.display_previous()}),o.click(function(){return s.display_next()}),{});return t.record_message=function(e,t){e=(e||"_")+"/"+t;n.text(e).attr("title",e),i.prop("disabled",!s.has_previous()),o.prop("disabled",!s.has_next())},s.windows.push(t),s.switch_view().done(function(){e.append(s.screen_container.el)}),e},refresh_attachment_preview:function(e){var t;this.attachment_screen&&(t=this.screen.current_record)&&(t=[["resource","=",t.model.name+","+t.id],["type","=","data"]],Sao.common.compare(this.attachment_screen.domain,t)&&!e||(this.attachment_screen.domain=t,this.attachment_screen.search_filter().then(()=>{var e=this.attachment_screen.group;e.length&&(this.attachment_screen.current_record=e[0],this.attachment_screen.display())})))},note:function(){var e=this.screen.current_record;!e||e.id<0||new Sao.Window.Note(e,()=>{this.refresh_resources(!0)})},email:function(){function a(e){return"ir.action.report"==e.type}this.buttons.email.prop("disabled")||this.modified_save().then(()=>{var o,s=this.screen.current_record;!s||s.id<0||(o=this.title.text(),this.screen.model.execute("view_toolbar_get",[],this.screen.context).then(function(e){var i=e.print.filter(a),n={};for(const t of e.emails)n[t.name]=t.id;s.rec_name().then(function(t){function e(e){new Sao.Window.Email(o+": "+t,s,i,e)}Sao.common.selection(Sao.i18n.gettext("Template"),n,!0).then(e,e)})}))})},refresh_resources:function(e){var t=this.screen.current_record;t?t.get_resources(e).always(this.update_resources.bind(this)):this.update_resources(),e&&this.refresh_attachment_preview(!0)},update_resources:function(e){e=e||{};var t=this.screen.get_id(),s=t<0||null==t,t=(e,t,i,n)=>{var e=this.buttons[e],o=e.find(".badge");o.length||(o=jQuery("<span/>",{class:"badge"}).appendTo(e)),n=n?Sao.config.icon_colors[n]:"",o.css("background-color",n),o.css("color","#fff"),o.text(i),e.attr("title",t),e.prop("disabled",s)},i=e.attachment_count||0,n=i||"";99<i&&(n="99+");t("attach",Sao.i18n.gettext("Attachment (%1)",i),n,1),i=e.note_count||0;var e=e.note_unread||0,n="",o=0<e?2:1;i&&(n=9<i?"+":i,n=9<e?"+/"+n:e+"/"+n),t("note",Sao.i18n.gettext("Note (%1/%2)",e,i),n,o)},record_message:function(t,e,i,n){var o,s=(e,t)=>{this.buttons[e]&&this.buttons[e].prop("disabled",!t),this.menu_buttons[e]&&this.menu_buttons[e].toggleClass("disabled",!t)},a="_",r=(t&&(a=""+t,1<(r=this.screen.selected_records.length))&&(a+="#"+r),this.screen.current_view.view_type),l=1<this.screen.number_of_views;for(const c of["print","relate","email","attach"]){let e=this.buttons[c]._can_be_sensitive;void 0===e&&(e=!0),"print"!=c&&"relate"!=c&&"email"!=c||(e|=this.screen.get_buttons().some(function(e){return(e.attributes.keyword||"action")==c})),s(c,t&&e)}s("switch_",(t||"form"==r)&&l),s("delete_",this.screen.deletable),s("previous",this.screen.has_previous()),s("next",this.screen.has_next()),e<i?(o=a+"@"+Sao.common.humanize(e)+"/"+Sao.common.humanize(i),i>=this.screen.count_limit&&(o+="+")):o=a+"/"+Sao.common.humanize(e),this.status_label.text(o).attr("title",o),this.info_bar.clear(),this.set_buttons_sensitive(),this.refresh_attachment_preview()},record_modified:function(){this.set_buttons_sensitive(),this.info_bar.refresh()},record_saved:function(){this.set_buttons_sensitive(),this.refresh_resources()},action:function(){window.setTimeout(()=>{this.buttons.action.click()})},relate:function(){window.setTimeout(()=>{this.buttons.relate.click()})},print:function(){window.setTimeout(()=>{this.buttons.print.click()})},export:function(){this.modified_save().then(()=>{new Sao.Window.Export(this.title.text(),this.screen,this.screen.current_view.get_fields())})},do_export:function(n){this.modified_save().then(()=>{var e,i="listed"==n.records?(e=this.screen.listed_records.map(e=>e.id),this.screen.listed_paths):(e=this.screen.selected_records.map(e=>e.id),this.screen.selected_paths),t=n["export_fields."].map(e=>e.name);this.screen.model.execute("export_data",[e,t,n.header],this.screen.context).then(function(e){var t={data:e},e=(t.data=e.map((e,t)=>{t=i&&i[t]?i[t].length-1:0;return Sao.Window.Export.format_row(e,t)}),","),t=(navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(e=";"),Papa.unparse(t,{quoteChar:'"',delimiter:e}));navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(t=Sao.BOM_UTF8+t),Sao.common.download_file(t,n.name+".csv",{type:"text/csv;charset=utf-8"})})})},import:function(){Sao.common.MODELACCESS.get(this.screen.model_name).create&&new Sao.Window.Import(this.title.text(),this.screen)},get_url:function(){return this.screen.get_url(this.name)}}),Sao.Tab.Board=Sao.class_(Sao.Tab,{class_:"tab-board",init:function(e){Sao.Tab.Board._super.init.call(this,e),this.model=e.model,this.view_id=0<e.view_ids.length?e.view_ids[0]:null,this.context=e.context;var e=(e=e.name)||Sao.common.MODELNAME.get(this.model);this.name=e,this.dialogs=[],this.board=null,this.create_tabcontent(),this.set_name(this.name),this.title.text(this.name_el.text()),e=new Sao.Model("ir.ui.view"),this.view_prm=e.execute("view_get",[this.view_id],this.context),this.view_prm.done(e=>{e=jQuery(jQuery.parseXML(e.arch)),this.board=new Sao.View.Board(e,this.context),this.board.actions_prms.done(()=>{for(var e=0,t=this.board.actions.length;e<t;e++)this.board.actions[e].screen.windows.push(this);this.board.reload()}),this.content.append(this.board.el)})},compare:function(e){var t;return!!e&&(t=Sao.common.compare,this.model===e.model)&&t(this.attributes.view_ids||[],e.view_ids||[])&&JSON.stringify(this.context)===JSON.stringify(e.context)},reload:function(){this.board.reload()},record_message:function(){for(var e=this.board.actions.length,t=0;t<e;t++)this.board.actions[t].update_domain(this.board.actions)},refresh_resources:function(){},update_resources:function(){}}),Sao.Tab.Wizard=Sao.class_(Sao.Tab,{class_:"tab-wizard",init:function(e){Sao.Tab.Wizard._super.init.call(this),this.wizard=e,this.set_name(e.name),(e.tab=this).create_tabcontent(),this.title.text(this.name_el.text()),this.content.remove(),this.content=e.form,this.main.css("padding-top",0).append(e.form)},create_toolbar:function(){return jQuery("<span/>")},_close_allowed:function(){var e=this.wizard,t=(e.state!==e.end_state&&e.end_state in e.states&&e.response(e.states[e.end_state].attributes),jQuery.Deferred());return e.state===e.end_state?t.resolve():t.reject(),t.promise()}})}(),!function(){"use strict";Sao.ScreenContainer=Sao.class_(Object,{init:function(e){this.alternate_viewport=jQuery("<div/>",{class:"screen-container"}),this.alternate_view=!1,this.search_modal=null,this.search_form=null,this.last_search_text="",this.tab_domain=e||[],this.tab_counter=[],this.el=jQuery("<div/>",{class:"screen-container"}),this.filter_box=jQuery("<form/>",{class:"filter-box"}).submit(e=>{e.preventDefault(),this.do_search()});var n,t,e=jQuery("<div/>",{class:"row"}).appendTo(this.filter_box),i=(this.el.append(this.filter_box),this.filter_button=jQuery("<button/>",{type:"button",class:"btn btn-link",title:Sao.i18n.gettext("Filters")}).text(Sao.i18n.gettext("Filters")),this.filter_button.click(this.search_box.bind(this)),this.search_entry=jQuery("<input/>",{class:"form-control mousetrap",placeholder:Sao.i18n.gettext("Search"),autocomplete:"off"}),this.search_list=jQuery("<datalist/>"),this.search_list.uniqueId(),this.search_entry.attr("list",this.search_list.attr("id")),this.search_entry.on("input",this.update.bind(this)),jQuery("<button/>",{type:"button",class:"btn btn-default hidden-md hidden-lg","aria-label":Sao.i18n.gettext("Clear Search"),title:Sao.i18n.gettext("Clear Search")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-clear"))),o=(i.hide(),i.click(()=>{this.search_entry.val("").change(),this.do_search()}),this.search_entry.on("keyup change",()=>{this.search_entry.val()?i.show():i.hide(),this.bookmark_match()}),jQuery("<button/>",{type:"submit",class:"btn btn-default","aria-label":Sao.i18n.gettext("Search"),title:Sao.i18n.gettext("Search")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-search"))),s=(this.but_active=jQuery("<button/>",{type:"button",class:"btn btn-default hidden-xs","aria-expanded":!1}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-archive",{"aria-hidden":!0})),this._set_active_tooltip(),this.but_active.click(this.search_active.bind(this)),this.but_bookmark=jQuery("<button/>",{type:"button",class:"btn btn-default dropdown-toggle","data-toggle":"dropdown","aria-expanded":!1,"aria-label":Sao.i18n.gettext("Bookmarks"),title:Sao.i18n.gettext("Bookmarks")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-bookmark",{"aria-hidden":!0})).uniqueId(),jQuery("<ul/>",{class:"dropdown-menu dropdown-menu-right",role:"menu","aria-labelledby":this.but_bookmark.attr("id")}));this.but_bookmark.click(()=>{s.empty();for(const i of this.bookmarks()){var e=i[1],t=i[2];jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(e).click(t,this.bookmark_activate.bind(this))).appendTo(s)}}),this.but_star=jQuery("<button/>",{class:"btn btn-default hidden-xs",type:"button"}).append(jQuery("<img/>",{class:"icon","aria-hidden":!0}).data("star",!1)).click(this.star_click.bind(this)),this.set_star(),jQuery("<div/>",{class:"input-group input-group-sm"}).append(jQuery("<span/>",{class:"input-group-btn"}).append(this.filter_button)).append(this.search_entry).append(this.search_list).append(jQuery("<span/>",{class:"input-group-btn"}).append(i).append(o).append(this.but_star).append(this.but_bookmark).append(s).append(this.but_active)).appendTo(jQuery("<div/>",{class:"col-sm-10 col-xs-12"}).appendTo(e)),this.but_prev=jQuery("<button/>",{type:"button",class:"btn btn-default btn-sm","aria-label":Sao.i18n.gettext("Previous"),title:Sao.i18n.gettext("Previous")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-back",{"aria-hidden":!0})),this.but_prev.click(this.search_prev.bind(this)),this.but_next=jQuery("<button/>",{type:"button",class:"btn btn-default btn-sm","aria-label":Sao.i18n.gettext("Next"),title:Sao.i18n.gettext("Next")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-forward",{"aria-hidden":!0})),this.but_next.click(this.search_next.bind(this)),jQuery("<div/>",{class:"btn-group",role:"group"}).append(this.but_prev).append(this.but_next).appendTo(jQuery("<div/>",{class:"col-sm-2 pull-right"}).appendTo(e)),this.content_box=jQuery("<div/>",{class:"content-box"}),jQuery.isEmptyObject(this.tab_domain)?this.tab=null:(this.tab=jQuery("<div/>",{class:"tab-domain"}).appendTo(this.el),n=jQuery("<ul/>",{class:"nav nav-tabs",role:"tablist"}).appendTo(this.tab),jQuery("<div/>",{class:"tab-content"}).appendTo(this.tab),this.tab_domain.forEach((e,t)=>{var e=e[0],i=jQuery("<span/>",{class:"badge badge-empty"}).html(" ");i.css("visibility","hidden"),jQuery("<li/>",{role:"presentation",id:"nav-"+t}).append(jQuery("<a/>",{"aria-controls":t,role:"tab","data-toggle":"tab",href:"#"+t}).text(e+" ").append(i)).appendTo(n);this.tab_counter.push(i)}),n.find("a:first").tab("show"),t=this,n.find("a").click(function(e){e.preventDefault(),jQuery(this).tab("show"),t.do_search(),t.screen.count_tab_domain(!0)})),this.el.append(this.content_box)},set_text:function(e){this.search_entry.val(e),this.bookmark_match()},update:function(){var e=this.screen.domain_parser.completion(this.get_text());this.search_list.empty();for(const t of e)jQuery("<option/>",{value:t.trim()}).appendTo(this.search_list)},set_star:function(e){var t,i=this.but_star.children("img"),n=e?(t="tryton-star",Sao.i18n.gettext("Remove this bookmark")):(t="tryton-star-border",Sao.i18n.gettext("Bookmark this filter"));this.but_star.data("star",Boolean(e)),this.but_star.attr("title",n),this.but_star.attr("aria-label",n),Sao.common.ICONFACTORY.get_icon_url(t).then(function(e){i.attr("src",e)})},get_star:function(){return this.but_star.data("star")},star_click:function(){var i,e=this.get_star(),n=this.screen.model_name;const o=()=>{this.bookmark_match(),this.but_bookmark.prop("disabled",jQuery.isEmptyObject(this.bookmarks()))};e?(e=this.bookmark_match(),Sao.common.VIEW_SEARCH.remove(n,e).then(function(){o()})):(i=this.get_text())&&Sao.common.ask.run(Sao.i18n.gettext("Bookmark Name:"),"bookmark").then(e=>{var t;e&&(t=this.screen.domain_parser.parse(i),Sao.common.VIEW_SEARCH.add(n,e,t).then(function(){o()}),this.set_text(this.screen.domain_parser.string(t)))})},bookmarks:function(){return Sao.common.VIEW_SEARCH.get(this.screen.model_name).filter(e=>this.screen.domain_parser.stringable(e[2]))},bookmark_activate:function(e){e.preventDefault();e=e.data;this.set_text(this.screen.domain_parser.string(e)),this.do_search()},bookmark_match:function(){var e=this.get_text();if(e){var t=this.screen.domain_parser.parse(e);this.get_star();for(const s of this.bookmarks()){var i=s[0],n=(s[1],s[2]),o=s[3];if(this.screen.domain_parser.string(n)===e||Sao.common.compare(n,t))return this.set_star(!0),this.but_star.prop("disabled",!o),i}this.but_star.prop("disabled",!e)}this.set_star(!1)},search_prev:function(){this.screen.search_prev(this.get_text())},search_next:function(){this.screen.search_next(this.get_text())},search_active:function(){this.but_active.toggleClass("active"),this._set_active_tooltip(),this.screen.search_filter(this.get_text())},_set_active_tooltip:function(){var e=this.but_active.hasClass("active")?Sao.i18n.gettext("Show active records"):Sao.i18n.gettext("Show inactive records");this.but_active.attr("aria-label",e),this.but_active.attr("title",e)},get_tab_index:function(){return this.tab?this.tab.find("li").index(this.tab.find("li.active")):-1},get_tab_domain:function(){var e;return!this.tab||(e=this.get_tab_index())<0?[]:this.tab_domain[e][1]},set_tab_counter:function(e,t=null){var i;jQuery.isEmptyObject(this.tab_counter)||!this.tab||(t=null===t?this.tab.find("li").index(this.tab.find("li.active")):t)<0||(t=this.tab_counter[t],null===e?(t.attr("title",""),t.html(" "),t.css("visibility","hidden")):(i=Sao.common.humanize(e),1e3<=e&&(i+="+"),t.attr("title",i),t.text(99<e?"99+":e),t.css("visibility","visible")))},do_search:function(){return this.screen.search_filter(this.get_text())},set_screen:function(e){this.screen=e,this.but_bookmark.prop("disabled",jQuery.isEmptyObject(this.bookmarks())),this.bookmark_match()},show_filter:function(){this.filter_box.show(),this.tab&&this.tab.show()},hide_filter:function(){this.filter_box.hide(),this.tab&&this.tab.hide()},set:function(e){(this.alternate_view?(this.alternate_viewport.children().detach(),this.alternate_viewport):(this.content_box.children().detach(),this.content_box)).append(e)},get_text:function(){return this.search_entry.val()},search_box:function(){var e=this.screen.domain_parser;const t=()=>{this.search_modal.modal("hide");var t="",i=e.quote.bind(e);for(const s of this.search_form.fields){var n=s[0],o=s[1];let e;(e=o instanceof Sao.ScreenContainer.Between||o instanceof Sao.ScreenContainer.Selection?o.get_value(i):i(o.val()))&&(t+=i(n)+": "+e+" ")}this.set_text(t),this.do_search().then(()=>{this.last_search_text=this.get_text()})};if(!this.search_modal){var i,n=new Sao.Dialog(Sao.i18n.gettext("Filters"),"","lg"),o=(this.search_modal=n.modal,this.search_form=n.content,this.search_form.addClass("form-horizontal"),this.search_form.submit(function(e){e.preventDefault(),t()}),[]);for(i in e.fields){var s=e.fields[i];!s.searchable&&void 0!==s.searchable||s.name.contains(".")||o.push(s)}var a="filter-"+this.screen.model_name+"-";this.search_form.fields=[];for(const p of o){var r,l,c,d,h,u=jQuery("<div/>",{class:"form-group form-group-sm"}).append(jQuery("<label/>",{class:"col-sm-4 control-label",for:a+p.name,text:p.string})).appendTo(n.body);switch(p.type){case"boolean":l=r=jQuery("<select/>",{class:"form-control input-sm",id:a+p.name});for(const f of["",Sao.i18n.gettext("True"),Sao.i18n.gettext("False")])jQuery("<option/>",{value:f,text:f}).appendTo(r);break;case"selection":case"multiselection":r=(l=new Sao.ScreenContainer.Selection(p.selection,a+p.name)).el;break;case"date":c=Sao.common.date_format(this.screen.context.date_format),r=(l=new Sao.ScreenContainer.Dates(c,a+p.name)).el;break;case"datetime":d=Sao.common.date_format(this.screen.context.date_format),h=new Sao.PYSON.Decoder({}).decode(p.format),h=Sao.common.moment_format(h),r=(l=new Sao.ScreenContainer.DateTimes(c=d+" "+h,a+p.name)).el;break;case"time":h=new Sao.PYSON.Decoder({}).decode(p.format),c=Sao.common.moment_format(h),r=(l=new Sao.ScreenContainer.Times(c,a+p.name)).el;break;case"integer":case"float":case"numeric":r=(l=new Sao.ScreenContainer.Numbers(a+p.name)).el;break;default:l=r=jQuery("<input/>",{class:"form-control input-sm",type:"text",placeholder:p.string,id:a+p.name})}jQuery("<div/>",{class:"col-sm-8"}).append(r).appendTo(u),this.search_form.fields.push([p.string,l,r])}jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("Find")}).text(Sao.i18n.gettext("Find")).click(t).appendTo(n.footer)}if(this.search_modal.modal("show"),this.last_search_text.trim()!==this.get_text().trim()){for(var _=0;_<this.search_form.fields.length;_++){var m=this.search_form.fields[_][1];m instanceof Sao.ScreenContainer.Selection?m.set_value([]):m instanceof Sao.ScreenContainer.Between?m.set_value(null,null):m.val("")}this.search_form.fields[0][2].focus()}}}),Sao.ScreenContainer.Between=Sao.class_(Object,{init:function(e){this.el=jQuery("<div/>",{class:"row",id:e}),this.from=this.build_entry(Sao.i18n.gettext("From"),jQuery("<div/>",{class:"col-md-5"}).appendTo(this.el)),jQuery("<p/>",{class:"text-center"}).append("..").appendTo(jQuery("<div/>",{class:"col-md-1"}).appendTo(this.el)),this.to=this.build_entry(Sao.i18n.gettext("To"),jQuery("<div/>",{class:"col-md-5"}).appendTo(this.el))},build_entry:function(e,t){},get_value:function(e){var t=this._get_value(this.from),i=this._get_value(this.to);return t&&i?t!==i?e(t)+".."+e(i):e(t):t?">="+e(t):i?"<="+e(i):void 0},_get_value:function(e){},set_value:function(e,t){this._set_value(this.from,e),this._set_value(this.to,t)},_set_value:function(e,t){},_from_changed:function(e){this._set_value(this.to,this._get_value(this.from))}}),Sao.ScreenContainer.BetweenDates=Sao.class_(Sao.ScreenContainer.Between,{init:function(e,t){this.format=e,Sao.ScreenContainer.BetweenDates._super.init.call(this,t),this.from.change(this._from_changed.bind(this))},_get_value:function(e,t){return e.find("input[type=text]").val()},_set_value:function(e,t){e.find("input[type=text]").val(t)}}),Sao.ScreenContainer.Dates=Sao.class_(Sao.ScreenContainer.BetweenDates,{_input:"date",_input_format:"%Y-%m-%d",_format:Sao.common.format_date,_parse:Sao.common.parse_date,build_entry:function(e,t){var i,t=jQuery("<div/>",{class:"input-group input-group-sm input-icon input-icon-secondary input-"+this._input}).appendTo(t),n=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap"}).appendTo(t),o=jQuery("<input/>",{type:this._input,role:"button",tabindex:-1}),s=(o.click(()=>{var e=this._parse(this.format,n.val()),e=this._format(this._input_format,e);o.val(e)}),o.change(()=>{var e=o.val();e&&(e=this._parse(this._input_format,e),e=this._format(this.format,e),n.val(e),n.focus())}),o[0].type==this._input&&(i=jQuery("<div/>",{class:"icon-input icon-secondary","aria-label":Sao.i18n.gettext("Open the calendar"),title:Sao.i18n.gettext("Open the calendar")}).appendTo(t),o.appendTo(i),Sao.common.ICONFACTORY.get_icon_img("tryton-date").appendTo(i)),new Mousetrap(n[0]));return s.bind("enter",(e,t)=>{var i=this._parse(this.format,n.val()),i=this._format(this.format,i);n.val(i)}),s.bind("=",(e,t)=>{e.preventDefault(),n.val(this._format(this.format,moment()))}),Sao.common.DATE_OPERATORS.forEach(i=>{s.bind(i[0],(e,t)=>{e.preventDefault();e=this._parse(this.format,n.val())||Sao.DateTime();e.add(i[1]),n.val(this._format(this.format,e))})}),t}}),Sao.ScreenContainer.DateTimes=Sao.class_(Sao.ScreenContainer.Dates,{_input:"datetime-local",_input_format:"%Y-%m-%dT%H:%M:%S",_format:Sao.common.format_datetime,_parse:Sao.common.parse_datetime}),Sao.ScreenContainer.Times=Sao.class_(Sao.ScreenContainer.Dates,{_input:"time",_input_format:"%H:%M:%S",_format:Sao.common.format_time,_parse:Sao.common.parse_time,build_entry:function(e,t){e=Sao.ScreenContainer.Times._super.build_entry.call(this,e,t);return~navigator.userAgent.indexOf("Firefox")&&e.find(".icon-input").hide(),e}}),Sao.ScreenContainer.Numbers=Sao.class_(Sao.ScreenContainer.Between,{init:function(e){Sao.ScreenContainer.Numbers._super.init.call(this,e),this.from.change(this._from_changed.bind(this))},build_entry:function(e,t){return jQuery("<input/>",{class:"form-control input-sm",type:"number",step:"any"}).appendTo(t)},_get_value:function(e,t){return e.val()},_set_value:function(e,t){return e.val(t)}}),Sao.ScreenContainer.Selection=Sao.class_(Object,{init:function(e,t){this.el=jQuery("<select/>",{class:"form-control input-sm",multiple:!0,id:t});for(const i of e)jQuery("<option/>",{value:i[1],text:i[1]}).appendTo(this.el)},get_value:function(e){var t=this.el.val();return t=jQuery.isEmptyObject(t)?null:jQuery.map(t,e).reduce(function(e,t){return e&&(e+=";"),e+t})},set_value:function(e){this.el.val(e)}}),Sao.Screen=Sao.class_(Object,{init:function(e,t){this.model_name=e,this.windows=[],this.model=new Sao.Model(e,t),this.attributes=jQuery.extend({},t),this.view_ids=jQuery.extend([],t.view_ids),this.view_to_load=jQuery.extend([],t.mode||["tree","form"]),this.views=[],this.views_preload=t.views_preload||{},this.exclude_field=t.exclude_field,this.current_view=null,this.domain=t.domain||[],this.context_domain=t.context_domain,this.size_limit=null,void 0===this.attributes.limit?this.limit=Sao.config.limit:this.limit=t.limit,this._current_domain=[],this.offset=0,this.order=this.default_order=t.order,this.readonly=this.attributes.readonly||!1;e=Sao.common.MODELACCESS.get(e);e.write||e.create||(this.readonly=!0),this.search_count=0,this.new_group(t.context||{}),this.current_record=null,this.screen_container=new Sao.ScreenContainer(t.tab_domain),this.breadcrumb=t.breadcrumb||[],this.context_screen=null,t.context_model&&(this.context_screen=new Sao.Screen(t.context_model,{mode:["form"],context:t.context}),this.context_screen_prm=this.context_screen.switch_view().then(()=>(jQuery("<div/>",{class:"row"}).append(jQuery("<div/>",{class:"col-md-12"}).append(this.context_screen.screen_container.el)).prependTo(this.screen_container.filter_box),this.context_screen.new_()))),t.row_activate?this.row_activate=t.row_activate:this.row_activate=this.default_row_activate,this.tree_states={},this.tree_states_done=[],this.fields_view_tree={},this._domain_parser={},this.pre_validate=!1,this.switch_callback=null},get readonly(){var e=this.selected_records.some(function(e){return e.readonly});return this.__readonly||e},set readonly(e){this.__readonly=e},get deletable(){return this.selected_records.every(function(e){return e.deletable})},get count_limit(){return 100*this.limit+this.offset},load_next_view:function(){var e,t;return jQuery.isEmptyObject(this.view_to_load)?jQuery.when():(jQuery.isEmptyObject(this.view_ids)||(e=this.view_ids.shift()),t=this.view_to_load.shift(),this.add_view_id(e,t))},add_view_id:function(e,t){var i;if(e&&this.views_preload[String(e)])i=this.views_preload[String(e)];else{if(e||!this.views_preload[t])return this.model.execute("fields_view_get",[e,t],this.context).pipe(this.add_view.bind(this));i=this.views_preload[t]}return this.add_view(i),jQuery.when()},add_view:function(e){var t,i=e.arch,n=e.fields,o=e.view_id,i=jQuery(jQuery.parseXML(i)),s=("tree"==i.children().prop("tagName")&&(this.fields_view_tree[o]=e),"eager");for(t in"form"==i.children().prop("tagName")&&(s="lazy"),n)t in this.model.fields&&"eager"!=s?n[t].loading=this.model.fields[t].description.loading:n[t].loading=s;for(t in this.group.add_fields(n),n)this.group.model.fields[t].views.add(o);i=Sao.View.parse(this,o,e.type,i,e.field_childs);return this.views.push(i),i},get number_of_views(){return this.views.length+this.view_to_load.length},switch_view:function(a=null,r=null,t=null,l=!0){if(null!==r&&(r=Number(r)),this.current_view){this.current_view.set_value(),this.current_record&&!~this.current_record.group.indexOf(this.current_record)&&(this.current_record=null);var e=this.current_view.get_fields();if(this.current_record&&this.current_view.editable&&!this.current_record.validate(e,!1,!1,!0))return this.screen_container.set(this.current_view.el),this.current_view.display().done(()=>{this.set_cursor()})}const c=()=>{var e;return!!this.current_view&&(e=!0,null!==a&&(e&=this.current_view.view_type==a),null!==r&&(e&=this.current_view.view_id==r),null!==t&&(e&=this.current_view.creatable==t),e)},d=()=>{const e=()=>{return this.screen_container.set(this.current_view.el),(l?this.display().done(()=>{this.set_cursor()}):jQuery.when()).done(()=>{this.switch_callback&&this.switch_callback()})},t=()=>{this.current_view=this.views[this.views.length-1]};for(var i=()=>(t(),(c()?e:d)()),n=e=>e.view_id==r,o=0;o<this.views.length+this.view_to_load.length;o++){if(this.view_to_load.length)return this.load_next_view().then(i);if(null!==r&&!this.views.find(n))return this.add_view_id(r,a).then(t);var s=this.views.indexOf(this.current_view);if(this.current_view=this.views[(s+1)%this.views.length],c())break}return e()};return d()},search_filter:function(e,i){if(i=i||!1,this.context_screen&&!i){if("pending"==this.context_screen_prm.state())return this.context_screen_prm.then(()=>this.search_filter(e));var t=this.context_screen.current_record;if(t&&!t.validate(null,!1,null,!0))return this.new_group(),this.context_screen.display(!0),jQuery.when();t=this.context_screen.get_on_change_value();delete t.id,this.new_group(jQuery.extend(this.local_context,t))}var t=new Sao.common.DomainInversion,n=this.search_domain(e,!0),t=t.canonicalize(n),o=(Sao.common.compare(t,this._current_domain)||(this._current_domain=t,this.offset=0),this.context);"none"!=this.screen_container.but_active.css("display")&&this.screen_container.but_active.hasClass("active")&&(o.active_test=!1);const s=()=>this.model.execute("search",[n,this.offset,this.limit,this.order],o).then(e=>e.length||this.offset<=0?e:(this.offset=Math.max(this.offset-this.limit,0),s()));return s().then(t=>{var e=jQuery.when(this.search_count);return i||(null!==this.limit&&t.length==this.limit?e=this.model.execute("search_count",[n,0,this.count_limit],o).then(e=>(this.search_count=e,this.search_count),()=>(this.search_count=0,this.search_count)):this.search_count=t.length),e.then(e=>(this.screen_container.but_next.prop("disabled",!(void 0!==this.limit&&t.length==this.limit&&e>this.limit+this.offset)),this.screen_container.but_prev.prop("disabled",this.offset<=0),i?t:(this.clear(),this.load(t).then(()=>{this.count_tab_domain()}))))})},search_domain:function(e=null,t=!1,i=!0){t=t||!1;var n,o=[];return!this.group.parent&&this.domain_parser?(n=this.domain_parser,null!==e?o=n.parse(e):(o=this.attributes.search_value,this.attributes.search_value=null),t&&this.screen_container.set_text(n.string(o))):o=[["id","in",this.group.map(function(e){return e.id})]],jQuery.isEmptyObject(o)?o=this.domain:jQuery.isEmptyObject(this.domain)||(o=["AND",o,this.domain]),"none"!=this.screen_container.but_active.css("display")&&this.screen_container.but_active.hasClass("active")&&(o=jQuery.isEmptyObject(o)?[["active","=",!1]]:[o,["active","=",!1]]),this.current_view&&"calendar"==this.current_view.view_type&&(o=jQuery.isEmptyObject(o)?this.current_view.current_domain():["AND",o,this.current_view.current_domain()]),this.context_domain&&(o=["AND",o,new Sao.PYSON.Decoder(this.context).decode(this.context_domain)]),i&&(e=this.screen_container.get_tab_domain(),jQuery.isEmptyObject(e)||(o=["AND",o,e])),o},count_tab_domain:function(i=!1){var n=this.search_domain(this.screen_container.get_text(),!1,!1),o=this.screen_container.get_tab_index();this.screen_container.tab_domain.forEach((e,t)=>{!e[2]||i&&t!=o||(e=["AND",e[1],n],this.screen_container.set_tab_counter(null,t),this.group.model.execute("search_count",[e,0,1e3],this.context).then(e=>{this.screen_container.set_tab_counter(e,t)}))})},get context(){var e=this.group.context;return this.context_screen&&(e.context_model=this.context_screen.model_name),e},get local_context(){var e=this.group.local_context;return this.context_screen&&(e.context_model=this.context_screen.model_name),e},set_group:function(e){var t,i={},n={};if(this.group){for(t in this.group.model.fields){var o=this.group.model.fields[t];i[t]=o.description,n[t]=o.views}this.group.screens.splice(this.group.screens.indexOf(this),1),jQuery.extend(e.on_write,this.group.on_write),e.on_write=e.on_write.filter(function(e,t,i){return t==i.indexOf(e)}),this.group.parent&&!e.parent&&(e.parent=this.group.parent)}for(t in e.screens.push(this),this.tree_states_done=[],this.views.map(function(e){e.reset()}),this.group=e,this.model=e.model,this.group.parent&&(this.order=null),this.current_record=null,this.group.add_fields(i),n)for(const s of n[t])this.group.model.fields[t].views.add(s);this.group.exclude_field=this.exclude_field},new_group:function(e){e=e||this.context;e=new Sao.Group(this.model,e,[]);e.readonly=this.__readonly,this.set_group(e)},record_modified:function(e=!0){for(const t of this.windows)t.record_modified&&t.record_modified();if(e)return this.display()},record_notify:function(e){for(const n of this.windows)if(n.info_bar){n.info_bar.refresh("notification");for(const o of e){var t=o[0],i=o[1];n.info_bar.add(i,t,"notification")}}},record_message:function(e,t,i,n){for(const o of this.windows)o.record_message&&o.record_message(e,t,i,n)},record_saved:function(){for(const e of this.windows)e.record_saved&&e.record_saved()},update_resources:function(e){for(const t of this.windows)t.update_resources&&t.update_resources(e)},has_update_resources:function(){return this.windows.some(function(e){return e.update_resources})},get current_record(){return this.__current_record},set current_record(e){var t,i,n;this.__current_record===e&&e||(n=i=null,(this.__current_record=e)&&(i=0<=(t=this.group.indexOf(e))?t+this.offset+1:e.get_index_path(),n=e.id),this.record_message(i||0,this.group.length+this.offset,this.search_count,n),this.switch_callback&&this.switch_callback(),this.has_update_resources()&&(e?e.get_resources().always(this.update_resources.bind(this)):this.update_resources()))},load:function(e,t=!0,i=!1,n=-1){return this.group.load(e,i,n),this.current_view&&this.current_view.reset(),this.current_record=null,this.display(t)},display:function(e){var t=[];if(this.views&&this.current_view){var i=this.search_active(~["tree","graph","calendar"].indexOf(this.current_view.view_type));t.push(i);for(const n of this.views)n&&(n==this.current_view||n.el.parent().length)&&t.push(n.display());"tree"==this.current_view.view_type&&"active"in(this.fields_view_tree[this.current_view.view_id]||{}).fields?this.screen_container.but_active.show():this.screen_container.but_active.hide()}return jQuery.when.apply(jQuery,t).then(()=>this.set_tree_state().then(()=>{this.current_record=this.current_record,e&&this.set_cursor(!1,!1)}))},_get_next_record:function(){var e=this.current_view;if(e&&~["tree","form","list-form"].indexOf(e.view_type)&&this.current_record&&this.current_record.group){for(var t=this.current_record.group,i=this.current_record;t;){var n=t.indexOf(i);if(n<t.length-1){i=t[n+1];break}if(!t.parent||i.group.model.name!=t.parent.group.model.name)break;i=t.parent,t=t.parent.group}return i}return this.group[0]},has_next:function(){var e=this._get_next_record();return e&&e!==this.current_record},display_next:function(){var e=this.current_view;return e&&e.set_value(),this.set_cursor(!1,!1),this.current_record=this._get_next_record(),this.set_cursor(!1,!1),e?e.display():jQuery.when()},_get_previous_record:function(){var e=this.current_view;if(e&&~["tree","form","list-form"].indexOf(e.view_type)&&this.current_record&&this.current_record.group){for(var t=this.current_record.group,i=this.current_record;t;){var n=t.indexOf(i);if(0<n){i=t[n-1];break}if(!t.parent||i.group.model.name!=t.parent.group.model.name)break;i=t.parent,t=t.parent.group}return i}return this.group[0]},has_previous:function(){var e=this._get_previous_record();return e&&e!==this.current_record},display_previous:function(){var e=this.current_view;return e&&e.set_value(),this.set_cursor(!1,!1),this.current_record=this._get_previous_record(),this.set_cursor(!1,!1),e?e.display():jQuery.when()},get selected_records(){return this.current_view?this.current_view.selected_records:[]},get selected_paths(){if(this.current_view&&"tree"==this.current_view.view_type)return this.current_view.get_selected_paths()},get listed_records(){return this.current_view&&~["tree","calendar","list-form"].indexOf(this.current_view.view_type)?this.current_view.listed_records:this.current_record?[this.current_record]:[]},get listed_paths(){if(this.current_view&&"tree"==this.current_view.view_type)return this.current_view.get_listed_paths()},clear:function(){this.current_record=null,this.group.clear(),this.tree_states_done=[],this.views.map(function(e){e.reset()})},default_row_activate:function(){this.current_view&&"tree"==this.current_view.view_type&&1==this.current_view.attributes.keyword_open?this.get_id()&&Sao.Action.exec_keyword("tree_open",{model:this.model_name,id:this.get_id(),ids:[this.get_id()]},this.local_context,!1):this.modified()||this.switch_view("form")},get_id:function(){if(this.current_record)return this.current_record.id},new_:function(i=!0,n=null){var o,s=this.current_view,e=jQuery.when();return this.current_view&&"calendar"==this.current_view.view_type&&(o=this.current_view.get_selected_date()),(e=this.current_view&&!this.current_view.creatable?this.switch_view("form",void 0,!0,!1):e).then(()=>{var e,t;if(this.current_view&&this.current_view.editable)return e=(this.current_record||this).group,t=e.new_(!1),(i?t.default_get(n):jQuery.when()).then(()=>(e.add(t,this.new_position),this.current_record=t,"calendar"==s.view_type&&s.set_default_date(t,o),this.display().then(()=>(this.set_cursor(!0,!0),t))))})},get new_position(){var e=null!==this.order?this.order:this.default_order;if(e)for(var t=0;t<e.length;t++){var i=e[t][0],n=e[t][1];if("id"==i&&n){if(n.startsWith("DESC"))return 0;if(n.startsWith("ASC"))return-1}}return this.group.parent?-1:0},set_on_write:function(e){!e||~this.group.on_write.indexOf(e)||this.group.on_write.push(e)},cancel_current:function(e){var t=[];return this.current_record&&(this.current_record.cancel(),this.current_record.id<0)&&(e?(this.current_record.reset(e),this.display()):t.push(this.remove(!1,!1,!1,[this.current_record]))),jQuery.when.apply(jQuery,t)},save_current:function(){var e=this.current_record;if(!e){if(!(this.current_view&&"tree"==this.current_view.view_type&&this.group&&this.group.length))return jQuery.when();this.current_record=this.group[0],e=this.current_record}this.current_view&&(this.current_view.set_value(),n=this.current_view.get_fields());var t=e.get_path(this.group),i=jQuery.Deferred();if(this.current_view&&"tree"==this.current_view.view_type)i=this.group.save().then(()=>this.current_record);else if(e.validate(n,null,null,!0))i=e.save().then(()=>e);else if(this.current_view)return this.current_view.display().then(()=>(this.set_cursor(),jQuery.Deferred().reject()));var n=()=>this.display().always(()=>this.record_saved()).then(()=>i,()=>i);return i.then(e=>(t&&e&&e.id&&t.splice(-1,1,[t[t.length-1][0],e.id]),this.group.get_by_path(t).then(e=>{this.current_record=e}))).then(n,n)},set_cursor:function(e,t){this.current_view&&~["tree","form","list-form"].indexOf(this.current_view.view_type)&&this.current_view.set_cursor(e,t)},modified:function(){function e(e){return e.modified||e.id<0}if(this.current_view&&"tree"!=this.current_view.view_type){if(this.current_record&&e(this.current_record))return!0}else if(this.group.some(e))return!0;return!(!this.current_view||!this.current_view.modified)},unremove:function(){if(this.current_view)for(const e of this.current_view.selected_records)e.group.unremove(e)},remove:function(n,o,s,a){var e=jQuery.when();return!a&&this.current_view&&(a=this.current_view.selected_records),jQuery.isEmptyObject(a)?e:(e=n?this.group.delete_(a):e).then(()=>{for(const t of a)t.group.remove(t,o,s,!1);a[0].group.record_modified();var e=[];if(n)for(const i of a)i.group.parent&&e.push(i.group.parent.save(!1)),~i.group.record_deleted.indexOf(i)&&i.group.record_deleted.splice(i.group.record_deleted.indexOf(i),1),~i.group.record_removed.indexOf(i)&&i.group.record_removed.splice(i.group.record_removed.indexOf(i),1);return this.current_record=null,jQuery.when.apply(jQuery,e).then(()=>this.display().done(()=>{this.set_cursor()}))})},copy:function(){var t=jQuery.Deferred(),e=this.current_view?this.current_view.selected_records:[];return this.model.copy(e,this.context).then(e=>{this.group.load(e,!1,this.new_position),jQuery.isEmptyObject(e)||(this.current_record=this.group.get(e[0])),this.display(!0).always(t.resolve)},t.reject),t.promise()},search_active:function(e){return e&&!this.group.parent?(this.screen_container.set_screen(this),this.screen_container.show_filter()):this.screen_container.hide_filter(),jQuery.when()},get domain_parser(){var e=this.current_view?this.current_view.view_id:null;if(e in this._domain_parser)return this._domain_parser[e];e in this.fields_view_tree?i=this.fields_view_tree[e]:(i=this.model.execute("fields_view_get",[!1,"tree"],this.context,!1),this.fields_view_tree[e]=i);var t,i,s,a=jQuery.extend({},i.fields);for(t in a){var n=a[t];"selection"!=n.type&&"multiselection"!=n.type&&"reference"!=n.type||n.selection instanceof Array||((n=jQuery.extend({},n)).selection=this.get_selection(n),a[t]=n)}"arch"in i&&(i=jQuery(jQuery.parseXML(i.arch)),s={},i.find("tree").children().each(function(e,t){if("field"==t.tagName){var i=t.getAttribute("name");if(!(i in s)){s[i]=a[i];for(const o of["string","factor"])t.getAttribute(o)&&(s[i][o]=t.getAttribute(o))}var n=t.getAttribute("symbol");!n||n in s||(s[n]=a[n])}}),a=s);for(const[t,o,r]of new Set([["id",Sao.i18n.gettext("ID"),"integer"],["create_uid",Sao.i18n.gettext("Created by"),"many2one"],["create_date",Sao.i18n.gettext("Created at"),"datetime"],["write_uid",Sao.i18n.gettext("Modified by"),"many2one"],["write_date",Sao.i18n.gettext("Modified at"),"datetime"]]))t in a||(a[t]={string:o,name:t,type:r},"datetime"==r&&(a[t].format='"%H:%M:%S"'));return i=new Sao.common.DomainParser(a,this.context),this._domain_parser[e]=i},get_selection:function(e){var t,i=e.selection_change_with;if(jQuery.isEmptyObject(i))t=this.model.execute(e.selection,[],void 0,!1);else{var n={};for(const o of i)n[o]=null;t=this.model.execute(e.selection,[n],void 0,!1)}return t.sort(function(e,t){return e[1].localeCompare(t[1])})},search_prev:function(e){this.limit&&(this.offset=Math.max(this.offset-this.limit,0)),this.search_filter(e)},search_next:function(e){this.limit&&(this.offset+=this.limit),this.search_filter(e)},invalid_message:function(e){var t,i={};for(t in(e=e||this.current_record).model.fields){var n=e.model.fields[t];i[t]=n.description}var o=new Sao.common.DomainParser(i),s=[],a=e.invalid_fields();for(const n of Object.keys(a).sort()){var r=a[n],l=e.model.fields[n].description.string;"required"==r||Sao.common.compare(r,[[n,"!=",null]])?s.push(Sao.i18n.gettext('"%1" is required.',l)):"domain"==r?s.push(Sao.i18n.gettext('"%1" is not valid according to its domain.',l)):"children"==r?s.push(Sao.i18n.gettext('The values of "%1" are not valid.',l)):o.stringable(r)?s.push(o.string(r)):s.push(Sao.i18n.gettext('"%1" is not valid according to its domain.'),l)}return 5<s.length&&(s.splice(5,s.length),s.push("...")),s.join("\n")},get:function(){return this.current_record?(this.current_view&&this.current_view.set_value(),this.current_record.get()):null},get_on_change_value:function(){return this.current_record?(this.current_view&&this.current_view.set_value(),this.current_record.get_on_change_value()):null},reload:function(e,t){this.group.reload(e);var i=[];return t&&i.push(this.group.written(e)),this.group.parent&&i.push(this.group.parent.root_parent.reload()),jQuery.when.apply(jQuery,i).then(()=>this.display())},get_buttons:function(){var e=this.current_view?this.current_view.selected_records:[];if(jQuery.isEmptyObject(e))return[];var t=this.current_view?this.current_view.get_buttons():[];for(const i of e)t=t.filter(function(e){return"instance"!==e.attributes.type&&!((e=i.expr_eval(e.attributes.states||{})).invisible||e.readonly)});return t},button:function(s){var a,r,t;const l=e=>this.reload(a,!0).then(()=>{"string"==typeof e?this.client_action(e):e&&Sao.Action.execute(e,{model:this.model_name,id:this.current_record.id,ids:a},null,this.context,!0),this.record_saved()});this.current_view&&(r=this.current_view.selected_records,this.current_view.set_value(),t=this.current_view.get_fields());var e=[];const c=e=>()=>{this.display(!0),e.validate(t)};for(const n of r){var i=n.expr_eval(s.states||{}).pre_validate||[];e.push(n.validate(t,!1,i))}return jQuery.when.apply(jQuery,e).then((...e)=>{for(var i=0;i<r.length;i++){var t=r[i],n=e[i];if(!n)return void Sao.common.warning.run(this.invalid_message(t),Sao.i18n.gettext("Pre-validation")).then(c(t))}var o=jQuery.when();return(o=s.confirm?Sao.common.sur.run(s.confirm):o).then(()=>{var e,t=this.current_record;return"instance"===s.type?(e=t.expr_eval(s.change||[]),e=t._get_on_change_args(e),t.model.execute(s.name,[e],this.context).then(function(e){t.set_on_change(e),t.set_modified()})):t.save(!1).then(()=>{var e=this.context;for(e._timestamp={},a=[],i=0;i<r.length;i++)t=r[i],jQuery.extend(e._timestamp,t.get_timestamp()),a.push(t.id);return t.model.execute(s.name,[a],e).then(l).fail(()=>this.reload(a,!0))})})})},client_action:function(e){var t=Sao.common.MODELACCESS.get(this.model_name);"new"==e?t.create&&this.new_():"delete"==e?!t.delete||this.current_record&&!this.current_record.deletable||this.remove(!this.group.parent,!1,!this.group.parent):"remove"==e?t.write&&t.read&&this.group.parent&&this.remove(!1,!0,!1):"copy"==e?t.create&&this.copy():"next"==e?this.display_next():"previous"==e?this.display_previous():"close"==e?Sao.Tab.tabs.close_current():e.startsWith("switch")?this.switch_view.apply(this,e.split(" ",3).slice(1)):"reload"==e?this.current_view&&~["tree","graph","calendar"].indexOf(this.current_view.view_type)&&!this.group.parent&&this.search_filter():"reload menu"==e?Sao.Session.current_session.reload_context().then(function(){Sao.menu()}):"reload context"==e&&Sao.Session.current_session.reload_context()},get_url:function(e){function t(e){return JSON.stringify(Sao.rpc.prepareObject(e))}var i,n=[],o=(jQuery.isEmptyObject(this.domain)||n.push(["domain",t(this.domain)]),this.local_context),o=(jQuery.isEmptyObject(o)||n.push(["context",t(o)]),this.context_screen&&n.push(["context_model",this.context_screen.model_name]),e&&n.push(["name",t(e)]),jQuery.isEmptyObject(this.attributes.tab_domain)||n.push(["tab_domain",t(this.attributes.tab_domain)]),["model",this.model_name]),e=this.views.map(function(e){return e.view_id}).concat(this.view_ids);return this.current_view&&"form"!=this.current_view.view_type?(i=this.attributes.search_value||(i=this.screen_container.get_text(),this.domain_parser.parse(i)),jQuery.isEmptyObject(i)||n.push(["search_value",t(i)])):this.current_record&&-1<this.current_record.id&&(o.push(this.current_record.id),this.current_view)&&(i=e.indexOf(this.current_view.view_id),e=e.slice(i).concat(e.slice(0,i))),jQuery.isEmptyObject(e)||n.push(["views",t(e)]),n=n.map(function(e){return e.map(encodeURIComponent).join("=")}).join("&"),o=o.join("/"),n&&(o+=";"+n),o},save_tree_state:function(e=!0){for(var t,i,n,o,s,a,r,l=[],c=this.group.parent?this.group.parent.id:null,d=function(){Sao.Session.current_session.cache.clear("model.ir.ui.view_tree_state.get")},h=()=>{Sao.Logger.warn("Unable to set view tree state for %s",this.model_name)},u=0,_=this.views.length;u<_;u++)if("form"==(t=this.views[u]).view_type){for(var m in t.widgets)if(t.widgets.hasOwnProperty(m))for(n=0,o=(i=t.widgets[m]).length;n<o;n++)i[n].screen&&(r=i[n].screen.save_tree_state(e),l.push(r));1==this.views.length&&this.current_record&&(c in this.tree_states||(this.tree_states[c]={}),this.tree_states[c][t.children_field||null]=[[],[[this.current_record.id]]])}else~["tree","list-form"].indexOf(t.view_type)&&(s="tree"==t.view_type?t.get_expanded_paths():[],a=t.get_selected_paths(),c in this.tree_states||(this.tree_states[c]={}),this.tree_states[c][t.children_field||null]=[s,a],e)&&parseInt(t.attributes.tree_state,10)&&(r=new Sao.Model("ir.ui.view_tree_state").execute("set",[this.model_name,this.get_tree_domain(c),t.children_field,JSON.stringify(s),JSON.stringify(a)],{}).then(d).fail(h),l.push(r));return jQuery.when.apply(jQuery,l)},get_tree_domain:function(e){e=e?(this.domain||[]).concat([[this.exclude_field,"=",e]]):this.domain;return JSON.stringify(Sao.rpc.prepareObject(e))},set_tree_state:function(){var t,e,a=this.current_view;return!a||!~["tree","form","list-form"].indexOf(a.view_type)||~this.tree_states_done.indexOf(a)||"form"==a.view_type&&!jQuery.isEmptyObject(this.tree_states_done)||(~["tree","list-form"].indexOf(a.view_type)&&!parseInt(a.attributes.tree_state,10)&&this.tree_states_done.push(a),(t=this.group.parent?this.group.parent.id:null)<0)?jQuery.when():(t in this.tree_states||(this.tree_states[t]={}),e=void 0===(e=this.tree_states[t][a.children_field||null])&&parseInt(a.attributes.tree_state,10)?new Sao.Model("ir.ui.view_tree_state").execute("get",[this.model_name,this.get_tree_domain(t),a.children_field],{}).then(e=>(e=[JSON.parse(e[0]),JSON.parse(e[1])],t in this.tree_states||(this.tree_states[t]={}),this.tree_states[t][a.children_field||null]=e)).fail(()=>{Sao.Logger.warn("Unable to get view tree state for %s",this.model_name)}):jQuery.when(e),this.tree_states_done.push(a),e.done(e=>{var t,i=[],n=[];if(e&&(i=e[0],n=e[1]),"tree"==a.view_type)return a.display(n,i);if("list-form"==a.view_type)return a.display(n);if(!jQuery.isEmptyObject(n)){for(const s of n[0]){var o=this.group.get(s);if(!o)break;t=o}t&&t!=this.current_record&&(this.current_record=t,a.display())}}))}}),Sao.Screen.tree_column_optional={}}(),!function(){"use strict";Sao.View=Sao.class_(Object,{view_type:null,el:null,mnemonic_widget:null,view_id:null,modified:null,editable:null,creatable:null,children_field:null,xml_parser:null,init:function(e,t,i){this.view_id=e,this.screen=t,this.widgets={},this.state_widgets=[];e=i.children()[0].attributes;this.attributes={};for(const s of e)this.attributes[s.name]=s.value;t.set_on_write(this.attributes.on_write);var n,o={};for(n in this.screen.model.fields)o[n]=this.screen.model.fields[n].description;this.xml_parser&&new this.xml_parser(this,this.screen.exclude_field,o).parse(i.children()[0]),this.reset()},set_value:function(){},get record(){return this.screen.current_record},set record(e){this.screen.current_record=e},get group(){return this.screen.group},get selected_records(){return[]},get_fields:function(){return[]},get_buttons:function(){return[]},reset:function(){}}),Sao.View.idpath2path=function(e,t){var i,n=[];if(!t)return[];for(var o=0,s=e.rows.length;o<s;o++)if(e.rows[o].record.id==t[0]){n.push(o),i=Sao.View.idpath2path(e.rows[o],t.slice(1,t.length)),n=n.concat(i);break}return n},Sao.View.parse=function(e,t,i,n,o){switch(i){case"tree":return new Sao.View.Tree(t,e,n,o);case"form":return new Sao.View.Form(t,e,n);case"graph":return new Sao.View.Graph(t,e,n);case"calendar":return new Sao.View.Calendar(t,e,n);case"list-form":return new Sao.View.ListForm(t,e,n)}},Sao.View.XMLViewParser=Sao.class_(Object,{init:function(e,t,i){this.view=e,this.exclude_field=t,this.field_attrs=i},_node_attributes:function(e){var t,i={};for(t of e.attributes)i[t.name]=t.value;var n={};i.name&&(n=this.field_attrs[i.name]||{});for(const o of["readonly","homogeneous"])i[o]&&(i[o]=1==i[o]);for(const s of["yexpand","yfill","xexpand","xfill","colspan","position","height","width"])i[s]&&(i[s]=Number(i[s]));for(const a of["xalign","yalign"])i[a]&&(i[a]=Number(i[a]));if(!jQuery.isEmptyObject(n)){i.widget||(i.widget=n.type),"label"==e.tagName&&void 0===i.string&&(i.string=n.string+Sao.i18n.gettext(":")),"field"!=e.tagName||i.help||(i.help=n.help);for(const r of["relation","domain","selection","string","states","relation_field","views","invisible","add_remove","sort","context","size","filename","autocomplete","translate","create","delete","selection_change_with","schema_model","required","help_selection","help_field","order","symbol","monetary"])r in n&&!(r in i)&&(i[r]=n[r])}return i},parse:function(e){var t;e.tagName&&(t=this._node_attributes(e),this["_parse_"+e.tagName](e,t))}})}(),!function(){"use strict";function s(e){return e.replace(/[\n\r]/gm,"")}Sao.View.FormXMLViewParser=Sao.class_(Sao.View.XMLViewParser,{init:function(e,t,i){Sao.View.FormXMLViewParser._super.init.call(this,e,t,i),this._containers=[],this._mnemonics={}},get container(){return 0<this._containers.length?this._containers[this._containers.length-1]:null},_parse_form:function(e,t){var i=new Sao.View.Form.Container(Number(e.getAttribute("col")||4));if(this.view.containers.push(i),this.parse_child(e,i),0<this._containers.length)throw"AssertionError";this.view.el.append(i.el)},parse_child:function(e,t){t&&this._containers.push(t);for(const i of e.childNodes)this.parse(i);t&&(t instanceof Sao.View.Form.Container&&t.setup_grid_template(),this._containers.pop())},_parse_field:function(e,t){var i,n=t.name;n&&n==this.exclude_field?this.container.add(null,t):(i=new Sao.View.FormXMLViewParser.WIDGETS[t.widget](this.view,t),this.view.widgets[n]||(this.view.widgets[n]=[]),this.view.widgets[n].push(i),i.position=this.view.widget_id+=1,i.expand&&(void 0===t.yexpand&&(t.yexpand=!0),void 0===t.yfill)&&(t.yfill=!0),void 0!==t.height&&(i.el.css("min-height",t.height+"px"),1==i.el.children().length)&&i.el.children().css("min-height","inherit"),void 0!==t.width&&i.el.css("min-width",t.width+"px"),void 0===t.xalign&&(t.xexpand?t.xalign=0:t.xalign=.5),void 0===t.yalign&&(t.yexpand?t.yalign=0:t.yalign=.5),this.container.add(i,t),this._mnemonics[n]&&i.labelled&&(t=this._mnemonics[n],n=Sao.common.accesskey(t.label_el.text()),t.label_el.uniqueId(),i.labelled.uniqueId(),i.labelled.attr("aria-labelledby",t.el.attr("id")),i.labelled.attr("accesskey",n),~["INPUT","SELECT"].indexOf(i.labelled.get(0).tagName)&&jQuery("<span/>",{"data-accesskey":n}).appendTo(i.labelled.parent()),t.label_el.attr("for",i.labelled.attr("id"))))},_parse_button:function(e,t){var i=new Sao.common.Button(t);i.el.click(i,this.view.button_clicked.bind(this.view)),this.view.state_widgets.push(i),this.container.add(i,t)},_parse_link:function(e,t){var i=new Sao.View.Form.Link(t);this.view.state_widgets.push(i),this.container.add(i,t)},_parse_image:function(e,t){var i=new Sao.View.Form.Image_(t);this.view.state_widgets.push(i),this.container.add(i,t)},_parse_separator:function(e,t){var i,n,o=t.name;o&&o==this.exclude_field?this.container.add(null,t):(n=t.string,i=new Sao.View.Form.Separator(n,t),n&&(n=t.xalign,i.label_el.css("text-align",n=.5==(n=void 0===n?0:n)?"center":n<=.5?"start":"end")),this.view.state_widgets.push(i),this.container.add(i,t),o&&(this._mnemonics[o]=i))},_parse_label:function(e,t){var i,n=t.name;n&&n==this.exclude_field?this.container.add(null,t):(void 0===t.xexpand&&(t.xexpand=0),void 0===t.xalign&&(t.xalign=1),void 0===t.yalign&&(t.yalign=.5),i=new Sao.View.Form.Label(t.string,t),this.view.state_widgets.push(i),this.container.add(i,t),n&&(this._mnemonics[n]=i))},_parse_newline:function(e,t){this.container.add_row()},_parse_notebook:function(e,t){void 0===t.colspan&&(t.colspan=4);var i=new Sao.View.Form.Notebook(t);void 0!==t.height&&i.el.css("min-height",t.height+"px"),void 0!==t.width&&i.el.css("min-width",t.width+"px"),this.view.state_widgets.push(i),this.view.notebooks.push(i),this.container.add(i,t),this.parse_child(e,i)},_parse_page:function(e,t){var i;t.name&&t.name==this.exclude_field||(i=new Sao.View.Form.Container(Number(e.getAttribute("col")||4)),this.view.containers.push(i),this.parse_child(e,i),e=new Sao.View.Form.Page(this.container.add(i.el,t.string,t.icon),t),this.view.state_widgets.push(e))},_parse_group:function(e,t){var i,n=new Sao.View.Form.Container(Number(e.getAttribute("col")||4));this.view.containers.push(n),this.parse_child(e,n),void 0===t.xalign&&(t.xalign=.5),void 0===t.yalign&&(t.yalign=.5),t.name&&t.name==this.exclude_field?this.container.add(null,t):(void 0!==t.expandable?((i=new Sao.View.Form.Expander(t)).set_expanded("1"===t.expandable),this.view.expandables.push(i)):i=new Sao.View.Form.Group(t),i.add(n),this.view.state_widgets.push(i),this.container.add(i,t))},_parse_hpaned:function(e,t){this._parse_paned(e,t,"horizontal")},_parse_vpaned:function(e,t){this._parse_paned(e,t,"vertical")},_parse_paned:function(e,t,i){i=new Sao.common.Paned(i);this.container.add(i,t),this.parse_child(e,i)},_parse_child:function(e,t){var i=this.container,n=new Sao.View.Form.Container(Number(e.getAttribute("col")||4));this.view.containers.push(n),this.parse_child(e,n),(i.get_child1().children().length?i.get_child2():i.get_child1()).append(n.el)}}),Sao.View.Form=Sao.class_(Sao.View,{editable:!0,creatable:!0,view_type:"form",xml_parser:Sao.View.FormXMLViewParser,init:function(e,t,i){this.el=jQuery("<div/>",{class:"form"}),this.notebooks=[],this.expandables=[],this.containers=[],this.widget_id=0,Sao.View.Form._super.init.call(this,e,t,i),this.attributes.creatable&&(this.creatable=Boolean(parseInt(this.attributes.creatable,10))),this.attributes.scan_code&&(this.scan_code_btn=new Sao.common.Button({string:Sao.i18n.gettext("Scan"),icon:"tryton-barcode-scanner",states:this.attributes.scan_code_states},null,"lg","btn-primary"),this.scan_code_btn.el.click(()=>{new Sao.Window.CodeScanner(this.on_scan_code.bind(this),"loop"==this.attributes.scan_code)}),this.el.append(jQuery("<div/>",{class:"btn-code-scanner"}).append(this.scan_code_btn.el)),this.state_widgets.push(this.scan_code_btn))},get_fields:function(){return Object.keys(this.widgets)},get_buttons:function(){var e,t=[];for(e in this.state_widgets){var i=this.state_widgets[e];i instanceof Sao.common.Button&&t.push(i)}return t},display:function(){var l,e=this.record,t=[];if(this.scan_code_btn&&this.scan_code_btn.el.toggle(Boolean(e)),e){var i=new Set(this.get_fields());for(const s in e.model.fields)~(l=e.model.fields[s]).views.has(this.view_id)&&i.add(s);var n=[];for(const a of i)l=e.model.fields[a],n.push([a,"eager"==(l.description.loading||"eager"),l.views.size]);n.sort(function(e,t){return!e[1]&&t[1]?-1:e[1]&&!t[1]?1:e[2]-t[2]});for(const r of n){var o=r[0];t.push(e.load(o))}}return jQuery.when.apply(jQuery,t).done(()=>{var e=this.record;for(const o in this.widgets){var t=this.widgets[o];l=null,(l=e?e.model.fields[o]:l)&&l.set_state(e);for(const s of t)s.display()}var i=[];for(const a in this.state_widgets){var n=this.state_widgets[a].set_state(e);n&&i.push(n)}for(const r of this.containers)r.set_grid_template();jQuery.when.apply(jQuery,i).done(()=>{for(const e of this.containers)e.set_grid_template()})})},set_value:function(){var e=this.record;if(e)for(var t in this.widgets)if(t in e.model.fields){var i=this.widgets[t],n=e.model.fields[t];for(const o of i)o.set_value(e,n)}},button_clicked:function(e){e=e.data;e.el.prop("disabled",!0),this.screen.button(e.attributes)},on_scan_code:function(e){var t=this.record;return t?t.on_scan_code(e,this.attributes.scan_code_depends||[]).done(()=>{"submit"==this.attributes.scan_code&&this.el.parents("form").submit()}):jQuery.when()},get selected_records(){return this.record?[this.record]:[]},get modified(){for(var e in this.widgets)for(const t of this.widgets[e])if(t.modified)return!0;return!1},set_cursor:function(e,t){var i,n,o,s,a,r,l,c,d,h,u=0<jQuery(document.activeElement).closest(this.el).length;if(t||!u){if(t)for(i=0;i<this.notebooks.length;i++)(a=this.notebooks[i]).set_current_page();this.attributes.cursor in this.widgets?s=Sao.common.find_focusable_child(this.widgets[this.attributes.cursor][0].el):(r=Sao.common.find_focusable_child(this.el))&&r.focus()}u=this.record;if(u){var _=[],m=this.el.find(".has-error");for(n in u.invalid_fields())for(c=this.widgets[n]||[],i=0;i<m.length;i++)for(d=jQuery(m[i]),o=0;o<c.length;o++)if(0<d.closest(c[o].el).length){_.push(d);break}0<_.length&&(s=Sao.common.find_first_focus_widget(this.el,_))}if(s){for(i=0;i<this.notebooks.length;i++)for(h=(a=this.notebooks[i]).get_n_pages(),o=0;o<h;o++)if(r=a.get_nth_page(o),0<jQuery(s).closest(r).length){a.set_current_page(o);break}for(i=0;i<this.expandables.length;i++)l=this.expandables[i],0<jQuery(s).closest(l.el).length&&l.set_expanded(!0);jQuery(s).find("input,select,textarea").addBack(s).focus()}}}),Sao.View.Form.Container=Sao.class_(Object,{init:function(e=4){this.col=e=e<0?0:e,this.el=jQuery("<div/>",{class:"form-container"}),this.col<=0?this.el.addClass("form-hcontainer"):1==this.col&&this.el.addClass("form-vcontainer"),this._col=1,this._row=1,this._xexpand=new Set,this._colspans=[],this._yexpand=new Set,this._grid_cols=[],this._grid_rows=[]},add_row:function(){this._col=1,this._row+=1},add:function(e,t){var i,n,o=t.colspan,s=(void 0===o&&(o=1),t.xfill),a=(void 0===s&&(s=1),t.xexpand),r=(void 0===a&&(a=1),0<this.col&&(o>this.col&&(o=this.col),this._col+o>this.col+1)&&(this._col=1,this._row+=1),e&&(i=e.el),jQuery("<div/>",{class:"form-item "+(e&&e.class_||"")}).append(i));if(r.css("grid-column",this._col+" / "+(this._col+o)),r.css("grid-row",this._row+" / "+(this._row+1)),this.el.append(r),e){if(a&&1==o)this._xexpand.add(this._col);else if(a){for(var l=[],c=this._col;c<this._col+o;c++)l.push(c);this._colspans.push(l)}t.yexpand&&this._yexpand.add(this._row),this._col+=o,void 0!==t.xalign?(n=.5==t.xalign?"center":t.xalign<=.5?"start":"end",r.addClass("xalign-"+n)):r.addClass("xalign-start"),a&&r.addClass("xexpand"),s&&(r.addClass("xfill"),a)&&i.addClass("xexpand"),void 0!==t.yalign&&(n=.5==t.yalign?"center":t.yalign<=.5?"start":"end",r.addClass("yalign-"+n)),t.yfill&&(r.addClass("yfill"),t.yexpand)&&i.addClass("yexpand"),t.help&&e.el.attr("title",t.help)}else this._col+=o},setup_grid_template:function(){for(const n of this._colspans){var e=!1;for(const i of n)if(this._xexpand.has(i)){e=!0;break}e||this._xexpand.add(Math.round((n[0]+n[n.length-1])/2))}var t,i=this.col<=0?this._col:this.col;if(this._xexpand.size)for(t=1;t<=i;t++)this._xexpand.has(t)?this._grid_cols.push(`minmax(min-content, ${i}fr)`):this._grid_cols.push("min-content");else for(t=1;t<=i;t++)this._grid_cols.push("min-content");if(this._yexpand.size)for(t=1;t<=this._row;t++)this._yexpand.has(t)?this._grid_rows.push(`minmax(min-content, ${this._row}fr)`):this._grid_rows.push("min-content");else for(t=1;t<=this._row;t++)this._grid_rows.push("min-content")},set_grid_template:function(){for(var e,t,i,n,o,s=this._grid_cols.slice(),a=this._grid_rows.slice(),r=[],l=[],c=0;c<s.length;c++)r.push([]);for(c=0;c<a.length;c++)l.push([]);for(o of this.el.children()){for(o=jQuery(o),e=parseInt(o.css("grid-column-start"),10),t=parseInt(o.css("grid-column-end"),10),i=parseInt(o.css("grid-row-start"),10),n=parseInt(o.css("grid-row-end"),10),c=e;c<t;c++)r[c-1].push(o);for(c=i;c<n;c++)l[c-1].push(o)}function d(e){var t=!0;for(const i of e.children(":not(.tooltip)"))if("none"!=jQuery(i).css("display")){t=!1;break}return e.toggleClass("form-empty",t),t}for(c=0;c<s.length;c++)r[c].every(d)&&(s[c]="0px");for(c=0;c<a.length;c++)l[c].every(d)&&(a[c]="0px");this.el.css("grid-template-columns",s.join(" ")),this.el.css("grid-template-rows",a.join(" "))}}),Sao.View.Form.StateWidget=Sao.class_(Object,{init:function(e){this.attributes=e},set_state:function(e){e=e?e.expr_eval(this.attributes.states||{}):{},e=e.invisible;(e=void 0===e?this.attributes.invisible:e)?this.hide():this.show()},show:function(){this.el.show()},hide:function(){this.el.hide()}}),Sao.View.Form.LabelMixin=Sao.class_(Sao.View.Form.StateWidget,{set_state:function(e){var t,i;Sao.View.Form.LabelMixin._super.set_state.call(this,e),this.attributes.name&&e&&(t=e.model.fields[this.attributes.name]),void 0===this.attributes.string||this.attributes.string||(i="",t&&e&&(i=t.get_client(e)||""),this.label_el.text(i)),void 0===(i=e?e.expr_eval(this.attributes.states||{}):{}).readonly&&(i.readonly=!t),Sao.common.apply_label_attributes(this.label_el,t&&t.description.readonly||i.readonly,t&&t.description.required||i.required)}}),Sao.View.Form.Separator=Sao.class_(Sao.View.Form.LabelMixin,{init:function(e,t){Sao.View.Form.Separator._super.init.call(this,t),this.el=jQuery("<div/>",{class:"form-separator"}),this.label_el=jQuery("<label/>"),e&&this.label_el.text(e),this.el.append(this.label_el),this.el.append(jQuery("<hr/>"))}}),Sao.View.Form.Label=Sao.class_(Sao.View.Form.LabelMixin,{class_:"form-label",init:function(e,t){Sao.View.Form.Label._super.init.call(this,t),this.el=this.label_el=jQuery("<label/>",{text:e,class:this.class_})}}),Sao.View.Form.Notebook=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-notebook",init:function(e){Sao.View.Form.Notebook._super.init.call(this,e),this.el=jQuery("<div/>",{class:this.class_}),this.nav=jQuery("<ul/>",{class:"nav nav-tabs",role:"tablist"}).appendTo(this.el),this.panes=jQuery("<div/>",{class:"tab-content"}).appendTo(this.el),this.selected=!1},add:function(e,t,i){var n=jQuery("<div/>",{role:"tabpanel",class:"tab-pane"}).uniqueId(),o=n.attr("id"),i=Sao.common.ICONFACTORY.get_icon_img(i),o=jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{"aria-controls":o,role:"tab","data-toggle":"tab",href:"#"+o}).text(t).prepend(i)).appendTo(this.nav);return n.append(e).appendTo(this.panes),this.selected||(o.addClass("active"),n.addClass("active"),this.selected=!0),o},set_current_page:function(e=null){e=null===e?":visible:first":":eq("+e+"):visible";this.nav.find("li"+e+" a").tab("show")},get_n_pages:function(){return this.nav.find("li[role='presentation']").length},get_nth_page:function(e){return jQuery(this.panes.find("div[role='tabpanel']")[e])}}),Sao.View.Form.Page=Sao.class_(Sao.View.Form.StateWidget,{init:function(e,t){Sao.View.Form.Page._super.init.call(this,t),this.el=e},hide:function(){Sao.View.Form.Page._super.hide.call(this),this.el.hasClass("active")&&this.el.siblings(":visible").first().find("a").tab("show")}}),Sao.View.Form.Group=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-group_",init:function(e){Sao.View.Form.Group._super.init.call(this,e),this.el=jQuery("<fieldset/>",{class:this.class_}),e.string&&this.el.append(jQuery("<legend/>").text(e.string))},add:function(e){this.el.append(e.el)}}),Sao.View.Form.Expander=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-group-expandable",init:function(e){Sao.View.Form.Expander._super.init.call(this,e),this.el=jQuery("<div/>",{class:"panel panel-default "+this.class_});var t=jQuery("<div/>",{class:"panel-heading"}).appendTo(this.el),t=(t.uniqueId(),this.collapsible=jQuery("<div/>",{class:"panel-collapse collapse","aria-labelledby":t.attr("id")}).appendTo(this.el),this.collapsible.uniqueId(),this.body=jQuery("<div/>",{class:"panel-body"}).appendTo(this.collapsible),jQuery("<label/>",{class:"panel-title"}).appendTo(t)),t=jQuery("<a/>",{role:"button","data-toggle":"collapse",href:"#"+this.collapsible.attr("id"),"aria-controls":this.collapsible.attr("id"),"aria-expanded":"1"==e.expandable}).appendTo(t);e.string&&t.text(e.string),t.append(jQuery("<span/>",{class:"caret"}))},add:function(e){this.body.empty(),this.body.append(e.el)},set_expanded:function(e){e?this.collapsible.collapse("show"):this.collapsible.collapse("hide")}}),Sao.View.Form.Link=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-link",init:function(e){var t;Sao.View.Form.Link._super.init.call(this,e),this.el=jQuery("<button/>",{class:this.class_+" btn btn-link",name:e.name,type:"button"}),e.icon&&(t=jQuery("<img/>",{class:"icon"}).prependTo(this.el),Sao.common.ICONFACTORY.get_icon_url(e.icon).done(function(e){t.attr("src",e)})),this.label=jQuery("<div/>").appendTo(this.el),this._current=null},get action_id(){return parseInt(this.attributes.id,10)},set_state:function(e){if(Sao.View.Form.Link._super.set_state.call(this,e),"none"!=this.el.css("display")){var t={},i={},n={};if(e){if(e.id<0)return void this.hide();t={model:e.model.name,id:e.id,ids:[e.id]},i=e.get_context(),n={active_model:e.model.name,active_id:e.id,active_ids:[e.id]},this._current=e.id}else this._current=null;n.context=i,this.el.off("click"),this.el.click([t,i],this.clicked.bind(this));var o,s,a=Sao.rpc({method:"model.ir.action.get_action_value",params:[this.action_id,i]},Sao.Session.current_session,!1),r=(this.label.text(a.name),this.el.attr("title",a.name),new Sao.PYSON.Decoder(n)),l=r.decode(a.pyson_domain),c=(a.pyson_search_value&&(l=[l,r.decode(a.pyson_search_value)]),a.domains.filter(function(e){return e[2]}).map(function(e){var t=e[0],e=e[1];return[t,r.decode(e)]}));const d=[];return e&&e.links_counts[this.action_id]?(o=e.links_counts[this.action_id],this.set_label(a.name,c,o)):(o=c.length?c.map(function(){return 0}):[0],e&&(e.links_counts[this.action_id]=o),s=this._current,c.length?c.map(function(e,t){e=e[1],e=Sao.rpc({method:"model."+a.res_model+".search_count",params:[["AND",l,e],0,100,i]},Sao.Session.current_session).then(e=>{this._set_count(e,t,s,o,a.name,c)});d.push(e)},this):(t=Sao.rpc({method:"model."+a.res_model+".search_count",params:[l,0,100,i]},Sao.Session.current_session).then(e=>{this._set_count(e,0,s,o,a.name,c)}),d.push(t))),jQuery.when.apply(jQuery,d)}},_set_count:function(e,t,i,n,o,s){i==this._current&&(n[t]=e=99<e?"99+":e,this.set_label(o,s,n))},set_label:function(e,t,i){this.label.text(e),this.el.attr("accesskey",Sao.common.accesskey(e)),t.length?t.map(function(e,t){e=e[0];this.label.append(jQuery("<br/>")),this.label.append(e+" "),jQuery("<span/>",{class:"badge"}).text(i[t]).appendTo(this.label)},this):(this.label.append(" "),jQuery("<span/>",{class:"badge"}).text(i[0]).appendTo(this.label)),"hide"===this.attributes.empty&&(i.filter(function(e){return 0!=e}).length?this.el.show():this.el.hide())},clicked:function(e){Sao.Action.execute(this.action_id,e.data[0],e.data[1],!0)}}),Sao.View.Form.Image_=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-image_",init:function(e){switch(Sao.View.Form.Image_._super.init.call(this,e),this.el=jQuery("<div/>",{class:this.class_}),this.img=jQuery("<img/>",{class:"center-block",width:(e.size||48)+"px",height:(e.size||48)+"px"}).appendTo(this.el),e.border){case"rounded":this.img.addClass("img-rounded");break;case"circle":this.img.addClass("img-circle")}},set_state:function(e){var t;Sao.View.Form.Image_._super.set_state.call(this,e),e&&((t=this.attributes.name)in e.model.fields&&(t=e.model.fields[t].get(e)),"url"==this.attributes.type?t?(this.attributes.url_size&&((e=new URL(t,window.location)).searchParams.set(this.attributes.url_size,this.attributes.size||48),t=e.href),this.img.attr("src",t)):this.img.removeAttr("src"):Sao.common.ICONFACTORY.get_icon_url(t).done(e=>{e?this.img.attr("src",e):this.img.removeAttr("src")}))}}),Sao.View.Form.Widget=Sao.class_(Object,{expand:!1,init:function(e,t){this.view=e,this.attributes=t,this.el=null,this.position=0,this.visible=!0,this.labelled=null},display:function(){var e,t=this.field,i=this.record,n=this.attributes.readonly,o=this.attributes.invisible,s=this.attributes.required;t?(i=t.get_state_attrs(i),void 0===n&&void 0===(n=i.readonly)&&(n=!1),void 0===s&&void 0===(s=i.required)&&(s=!1),this.view.screen.attributes.readonly&&(n=!0),this.set_readonly(n),n?this.el.addClass("readonly"):this.el.removeClass("readonly"),e=this._required_el(),this.set_required(s),!n&&s?e.addClass("required"):e.removeClass("required"),e=i.invalid,i=this._invalid_el(),!n&&e?i.addClass("has-error"):i.removeClass("has-error"),void 0===o&&void 0===(o=t.get_state_attrs(this.record).invisible)&&(o=!1),this.set_invisible(o)):(void 0===o&&(o=!1),void 0===s&&(s=!1),this.set_readonly(n=void 0===n?!0:n),this.set_invisible(o),this.set_required(s))},_required_el:function(){return this.el},_invalid_el:function(){return this.el},get field_name(){return this.attributes.name},get model_name(){return this.view.screen.model_name},get model(){return this.view.screen.model},get record(){return this.view.record},get field(){var e=this.record;if(e)return e.model.fields[this.field_name]},focus_out:function(){this.field&&this.visible&&this.set_value()},get_value:function(){},set_value:function(){},set_readonly:function(e){this._readonly=e},set_required:function(e){},get modified(){return!1},send_modified:function(){window.setTimeout(()=>{var e=this.get_value();window.setTimeout(()=>{this.record&&this.get_value()==e&&this.modified&&this.view.screen.record_modified(!1)},300)})},set_invisible:function(e){this.visible=!e,e?this.el.hide():this.el.show()},focus:function(){this.el.focus()}}),Sao.View.Form.TranslateDialog=Sao.class_(Object,{class_:"form",init:function(e,t){var i=new Sao.Dialog(Sao.i18n.gettext("Translate"),this.class_,"md");this.languages=e,this.read(t,i),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(i)}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(this.write.bind(this,t,i)).appendTo(i.footer),i.content.submit(function(e){e.preventDefault(),i.footer.find("button.btn-primary").first().click()}),i.modal.modal("show"),i.modal.on("shown.bs.modal",function(){i.modal.find("input,select").filter(":visible").first().focus()}),i.modal.on("hide.bs.modal",function(){jQuery(this).remove()})},close:function(e){e.modal.modal("hide")},read:function(r,l){function c(e){return e[0][r.field_name]||""}l.content.addClass("form-horizontal"),this.languages.forEach(e=>{var t=jQuery("<div/>",{class:"form-group"}),i=r.translate_widget(),n=(i.attr("data-lang-id",e.id),jQuery("<button/>",{type:"button",class:"btn btn-default"}).text(Sao.i18n.gettext("Edit"))),o=(r._readonly&&n.attr("disabled",!0),jQuery("<span>",{class:"label"})),s=Sao.rpc({method:"model."+r.model.name+".read",params:[[r.record.id],[r.field_name],{language:e.code}]},r.model.session).then(c),a=Sao.rpc({method:"model."+r.model.name+".read",params:[[r.record.id],[r.field_name],{language:e.code,fuzzy_translation:!0}]},r.model.session).then(c);jQuery.when(s,a).done(function(e,t){r.translate_widget_set(i,t),r.translate_widget_set_readonly(i,!0),e!==t&&(o.addClass("label-warning"),o.text(Sao.i18n.gettext("Fuzzy")))}),n.click(function(){jQuery(this).toggleClass("active"),r.translate_widget_set_readonly(i,!jQuery(this).hasClass("active"))}),l.body.append(t),i.uniqueId(),t.append(jQuery("<label/>",{for:i.attr("id"),class:"col-sm-3 control-label"}).append(" "+e.name)),t.append(jQuery("<div/>",{class:"col-sm-9 input-group"}).append(i).append(jQuery("<span/>",{class:"input-group-addon"}).append(n).append(o)))})},write:function(e,t){for(const s of this.languages){var i,n,o=jQuery("[data-lang-id="+s.id+"]");o.attr("readonly")||(e.model.session.context.language,(i={}).language=s.code,i.fuzzy_translation=!1,(n={})[e.field_name]=e.translate_widget_get(o),o=[[e.record.id],n,i],n={method:"model."+e.model.name+".write",params:o},Sao.rpc(n,e.model.session,!1))}e.record.cancel(),e.view.display(),this.close(t)}}),Sao.View.Form.TranslateMixin={},Sao.View.Form.TranslateMixin.init=function(){this.translate||(this.translate=Sao.View.Form.TranslateMixin.translate.bind(this)),this.translate_dialog||(this.translate_dialog=Sao.View.Form.TranslateMixin.translate_dialog.bind(this)),this.translate_widget_set_readonly||(this.translate_widget_set_readonly=Sao.View.Form.TranslateMixin.translate_widget_set_readonly.bind(this)),this.translate_widget_set||(this.translate_widget_set=Sao.View.Form.TranslateMixin.translate_widget_set.bind(this)),this.translate_widget_get||(this.translate_widget_get=Sao.View.Form.TranslateMixin.translate_widget_get.bind(this))},Sao.View.Form.TranslateMixin.translate=function(){var t,e;this.record.id<0||this.record.modified?(e=Sao.i18n.gettext("You need to save the record before adding translations."),Sao.common.message.run(e)):(t=this.model.session,e={method:"model.ir.lang.search",params:[[["translatable","=",!0]]].concat({})},Sao.rpc(e,t).then(e=>{jQuery.isEmptyObject(e)?Sao.common.message.run(Sao.i18n.gettext("No other language available.")):(e={method:"model.ir.lang.read",params:[e,["code","name"]].concat({})},Sao.rpc(e,t).then(e=>{this.translate_dialog(e)}))}))},Sao.View.Form.TranslateMixin.translate_dialog=function(e){new Sao.View.Form.TranslateDialog(e,this)},Sao.View.Form.TranslateMixin.translate_widget_set_readonly=function(e,t){e.prop("readonly",t)},Sao.View.Form.TranslateMixin.translate_widget_set=function(e,t){e.val(t)},Sao.View.Form.TranslateMixin.translate_widget_get=function(e){return e.val()},Sao.View.Form.Char=Sao.class_(Sao.View.Form.Widget,{class_:"form-char",init:function(e,t){Sao.View.Form.Char._super.init.call(this,e,t),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_}),this.group=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el),this.input=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:t.name}).appendTo(this.group),jQuery.isEmptyObject(t.autocomplete)||(this.datalist=jQuery("<datalist/>").appendTo(this.el),this.datalist.uniqueId(),this.input.attr("list",this.datalist.attr("id")),this.input.attr("autocomplete","off")),this.el.change(this.focus_out.bind(this)),this.el.on("keydown",this.send_modified.bind(this)),t.size||this.group.css("width","100%"),this.attributes.translate&&Sao.common.ICONFACTORY.get_icon_img("tryton-translate").appendTo(jQuery("<div/>",{class:"icon-input icon-secondary","aria-label":Sao.i18n.gettext("Translate"),title:Sao.i18n.gettext("Translate")}).appendTo(this.group.addClass("input-icon input-icon-secondary"))).click(this.translate.bind(this))},get_client_value:function(){var e=this.field,t=this.record,i="";return i=e?e.get_client(t):i},display:function(){Sao.View.Form.Char._super.display.call(this);var e=this.record;if(this.datalist){this.datalist.empty();for(const n of e&&(this.field_name in e.autocompletion||e.do_autocomplete(this.field_name),e.autocompletion[this.field_name])||[])jQuery("<option/>",{value:n}).appendTo(this.datalist)}var t="",i="100%";e&&0<(t=e.expr_eval(this.attributes.size))&&(i=null),this.input.val(this.get_client_value()),this.input.attr("maxlength",t),this.input.attr("size",t),this.group.css("width",i)},get modified(){return!(!this.record||!this.field)&&this.get_client_value()!=this.get_value()},set_value:function(){this.field.set_client(this.record,this.input.val())},get_value:function(){return this.input.val()},set_readonly:function(e){Sao.View.Form.Char._super.set_readonly.call(this,e),this.input.prop("readonly",e)},focus:function(){this.input.focus()},translate_widget:function(){return jQuery("<input/>",{class:"form-control",readonly:"readonly",name:this.attributes.name})}}),Sao.View.Form.Password=Sao.class_(Sao.View.Form.Char,{class_:"form-password",init:function(e,t){Sao.View.Form.Password._super.init.call(this,e,t),this.input.prop("type","password"),this.button=jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button"}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group)),this._set_password_label(),this.button.click(this.toggle_visibility.bind(this))},toggle_visibility:function(){"password"==this.input.prop("type")?(this.input.prop("type","text"),this.input.attr("autocomplete","off")):(this.input.prop("type","password"),this.input.removeAttr("autocomplete")),this._set_password_label()},_set_password_label:function(){"password"==this.input.prop("type")?(this.button.text(Sao.i18n.gettext("Show")),this.button.attr("title",Sao.i18n.gettext("Show"))):(this.button.text(Sao.i18n.gettext("Hide")),this.button.attr("title",Sao.i18n.gettext("Hide")))}}),Sao.View.Form.Date=Sao.class_(Sao.View.Form.Widget,{class_:"form-date",_width:"10em",_input:"date",_input_format:"%Y-%m-%d",_format:Sao.common.format_date,_parse:Sao.common.parse_date,init:function(e,t){Sao.View.Form.Date._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_});var e=this.labelled=jQuery("<div/>",{class:"input-group input-group-sm input-icon input-icon-secondary"}).appendTo(this.el),n=(this.date=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:t.name}).appendTo(e),this.date.uniqueId(),this.date.on("keydown",this.send_modified.bind(this)),this.input=jQuery("<input/>",{type:this._input,role:"button",tabindex:-1}),this.input.click(()=>{var e=this.get_value(),e=this._format(this._input_format,e);this.input.val(e)}),this.input.change(()=>{var e=this.input.val();e&&(e=this._parse(this._input_format,e),e=this._format(this.get_format(),e),this.date.val(e).change(),~navigator.userAgent.indexOf("Firefox")||this.date.focus()),this.send_modified()}),this.input[0].type==this._input&&(this.icon=jQuery("<div/>",{class:"icon-input icon-secondary","aria-label":Sao.i18n.gettext("Open the calendar"),title:Sao.i18n.gettext("Open the calendar"),tabindex:-1}).appendTo(e),this.input.appendTo(this.icon),Sao.common.ICONFACTORY.get_icon_img("tryton-date").appendTo(this.icon)),this.date.css("max-width",this._width),this.date.change(this.focus_out.bind(this)),new Mousetrap(this.date[0]));n.bind("enter",(e,t)=>{this.date.prop("readonly")||this.focus_out()}),n.bind("=",(e,t)=>{this.date.prop("readonly")||(e.preventDefault(),this.date.val(this._format(this.get_format(),moment())).change())}),Sao.common.DATE_OPERATORS.forEach(i=>{n.bind(i[0],(e,t)=>{this.date.prop("readonly")||(e.preventDefault(),(e=this.get_value()||Sao.DateTime()).add(i[1]),this.date.val(this._format(this.get_format(),e)).change())})})},get_format:function(){return this.field&&this.record?this.field.date_format(this.record):Sao.common.date_format(this.view.screen.context.date_format)},get_value:function(){return this._parse(this.get_format(),this.date.val())},display:function(){var e,t=this.record,i=this.field;Sao.View.Form.Date._super.display.call(this),t&&(e=i.get_client(t)),this.date.val(this._format(this.get_format(),e))},focus:function(){this.date.focus()},get modified(){var e;return!(!this.record||!this.field)&&(e=this.cast(this.field.get_client(this.record)),JSON.stringify(e)!=JSON.stringify(this.get_value()))},set_value:function(){this.field.set_client(this.record,this.get_value())},set_readonly:function(e){Sao.View.Form.Date._super.set_readonly.call(this,e),this.el.find("input").prop("readonly",e),this.icon&&(e?this.icon.hide():this.icon.show())},cast:function(e){return e=e&&e.isDateTime?e.todate():e}}),Sao.View.Form.DateTime=Sao.class_(Sao.View.Form.Date,{class_:"form-datetime",_width:"20em",_input:"datetime-local",_input_format:"%Y-%m-%dT%H:%M:%S",_format:Sao.common.format_datetime,_parse:Sao.common.parse_datetime,get_format:function(){return this.field&&this.record?this.field.date_format(this.record)+" "+this.field.time_format(this.record):Sao.common.date_format(this.view.screen.context.date_format)+" %X"},cast:function(e){return e}}),Sao.View.Form.Time=Sao.class_(Sao.View.Form.Date,{class_:"form-time",_width:"10em",_input:"time",_input_format:"%H:%M:%S",_format:Sao.common.format_time,_parse:Sao.common.parse_time,init:function(e,t){Sao.View.Form.Time._super.init.call(this,e,t),~navigator.userAgent.indexOf("Firefox")&&this.input.parent().hide()},get_format:function(){return this.field&&this.record?this.field.time_format(this.record):"%X"},cast:function(e){return e=e&&e.isDateTime?e.totime():e}}),Sao.View.Form.TimeDelta=Sao.class_(Sao.View.Form.Widget,{class_:"form-timedelta",init:function(e,t){Sao.View.Form.TimeDelta._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_}),this.input=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:t.name}).appendTo(this.el),this.el.change(this.focus_out.bind(this)),this.el.on("keydown",this.send_modified.bind(this))},display:function(){Sao.View.Form.TimeDelta._super.display.call(this);var e=this.record;e?(e=e.field_get_client(this.field_name),this.input.val(e||"")):this.input.val("")},focus:function(){this.input.focus()},get modified(){var e;return!(!this.record||!this.field)&&(e=this.input.val(),this.field.get_client(this.record)!=e)},set_value:function(){this.field.set_client(this.record,this.input.val())},set_readonly:function(e){Sao.View.Form.TimeDelta._super.set_readonly.call(this,e),this.input.prop("readonly",e)}});function i(e,t){var i=e.attr("id"),n=e.attr("aria-labelledby"),o=t.attr("id"),s=t.attr("aria-labelledby");e.attr("id",o),e.attr("aria-labelledby",s),t.attr("id",i),t.attr("aria-labelledby",n)}function n(e){var t=e.clone().prependTo(e.parent());return t.attr("type","text"),e.attr("type","number"),e.attr("step",1),e.attr("lang",Sao.i18n.getlang()),e.hide().on("focusout",function(){e[0].checkValidity()&&(i(e,t),e.hide(),t.show())}),t.on("focusin",function(){e.prop("readonly")||(i(e,t),t.hide(),e.show(),window.setTimeout(function(){e.focus()}))}),t}Sao.View.Form.Integer=Sao.class_(Sao.View.Form.Char,{class_:"form-integer",init:function(e,t){Sao.View.Form.Integer._super.init.call(this,e,t),this.input_text=this.labelled=n(this.input),this.attributes.symbol&&(this.symbol_start=jQuery("<span/>",{class:"input-group-addon symbol symbol-start"}).prependTo(this.group),this.symbol_end=jQuery("<span/>",{class:"input-group-addon symbol symbol-end"}).appendTo(this.group)),this.group.css("width",""),this.factor=Number(t.factor||1),this.grouping=Boolean(Number(t.grouping||1))},get modified(){var e;return!(!this.record||!this.field)&&(e=this.get_client_value(),JSON.stringify(this.field.convert(e))!=JSON.stringify(this.field.convert(this.get_value())))},set_value:function(){this.field.set_client(this.record,this.get_value(),void 0,this.factor)},get_value:function(){return this.input.val()},get_client_value:function(){var e="",t=this.field;return t&&(null!==(e=t.get(this.record))?(e*=this.factor,(t=t.digits(this.record,this.factor))&&(e=e.toFixed(t[1]))):e=""),e},get width(){return this.attributes.width||8},display:function(){function e(e,t){t?(e.text(t),e.show()):(e.text(""),e.hide())}Sao.View.Form.Integer._super.display.call(this);var t=this.field,i=this.record,n="";null!==this.width&&(this.input_text.css("width",this.width+"ch"),this.input.css("width",this.width+5+"ch")),t&&(n=t.get_client(i,this.factor,this.grouping)),t&&this.attributes.symbol&&(i=(t=t.get_symbol(i,this.attributes.symbol))[0],t[1]<.5?(e(this.symbol_start,i),e(this.symbol_end,"")):(e(this.symbol_start,""),e(this.symbol_end,i))),this.input_text.val(n),this.input_text.attr("maxlength",this.input.attr("maxlength")),this.input_text.attr("size",this.input.attr("size"))},set_readonly:function(e){Sao.View.Form.Integer._super.set_readonly.call(this,e),this.input_text.prop("readonly",e)},focus:function(){(this.input.prop("readonly")?this.input_text:(this.input_text.hide(),this.input.show())).focus()}}),Sao.View.Form.Float=Sao.class_(Sao.View.Form.Integer,{class_:"form-float",get digits(){var e=this.record,t=this.field;if(e&&t)return t.digits(e,this.factor)},get width(){var e=this.digits;return e?e.reduce(function(e,t){return e+t}):this.attributes.width||18},display:function(){var e=this.record,t=(this.field,"any");e&&(e=this.digits)&&(t=Math.pow(10,-e[1]).toFixed(e[1])),this.input.attr("step",t),Sao.View.Form.Float._super.display.call(this)}}),Sao.View.Form.Selection=Sao.class_(Sao.View.Form.Widget,{class_:"form-selection",init:function(e,t){Sao.View.Form.Selection._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_}),this.select=this.labelled=jQuery("<select/>",{class:"form-control input-sm mousetrap",name:t.name}),this.el.append(this.select),this.select.change(this.focus_out.bind(this)),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e,this.set_selection.bind(this))},update_selection:function(e,t,i){Sao.common.selection_mixin.update_selection.call(this,e,t,(e,t)=>{this.set_selection(e,t),i&&i(t)})},set_selection:function(e,t){var i=this.select;i.empty();for(const n of e)i.append(jQuery("<option/>",{value:JSON.stringify(n[0]),text:n[1],title:t[n[0]]}))},display_update_selection:function(){var s=this.record,a=this.field;this.update_selection(s,a,t=>{if(a){var e,i=a.get(s),n=!1;for(const o of this.selection)if(o[0]===i){n=!0;break}n?e=jQuery.when():(e=Sao.common.selection_mixin.get_inactive_selection.call(this,i)).done(e=>{this.select.append(jQuery("<option/>",{value:JSON.stringify(e[0]),text:e[1],disabled:!0}))}),e.done(()=>{this.select.val(JSON.stringify(i));var e=t[i]||null;this.attributes.help&&(e=e&&this.attributes.help+"\n"+e),this.select.attr("title",e)})}else this.select.val("")})},display:function(){Sao.View.Form.Selection._super.display.call(this),this.display_update_selection()},focus:function(){this.select.focus()},get_value:function(){return JSON.parse(this.select.val())},get modified(){return!(!this.record||!this.field)&&this.field.get(this.record)!=this.get_value()},set_value:function(){var e=this.get_value();this.field.set_client(this.record,e)},set_readonly:function(e){Sao.View.Form.Selection._super.set_readonly.call(this,e),this.select.prop("disabled",e)}}),Sao.View.Form.Boolean=Sao.class_(Sao.View.Form.Widget,{class_:"form-boolean",init:function(e,t){Sao.View.Form.Boolean._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_}),this.input=this.labelled=jQuery("<input/>",{type:"checkbox",class:"form-control input-sm mousetrap",name:t.name}).appendTo(this.el),this.input.change(this.focus_out.bind(this)),this.input.click(function(){return!jQuery(this).prop("readonly")})},display:function(){Sao.View.Form.Boolean._super.display.call(this);var e=this.record;e?this.input.prop("checked",e.field_get(this.field_name)):this.input.prop("checked",!1)},focus:function(){this.input.focus()},set_value:function(){var e=this.input.prop("checked");this.field.set_client(this.record,e)},set_readonly:function(e){Sao.View.Form.Boolean._super.set_readonly.call(this,e),this.input.prop("readonly",e)}}),Sao.View.Form.Text=Sao.class_(Sao.View.Form.Widget,{class_:"form-text",expand:!0,init:function(e,t){Sao.View.Form.Text._super.init.call(this,e,t),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_}),this.group=jQuery("<div/>",{class:"input-group"}).appendTo(this.el),this.input=this.labelled=jQuery("<textarea/>",{class:"form-control input-sm mousetrap",name:t.name}).appendTo(this.group),this.input.change(this.focus_out.bind(this)),this.input.on("keydown",this.send_modified.bind(this)),this.attributes.translate&&((e=jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button","aria-label":Sao.i18n.gettext("Translate"),title:Sao.i18n.gettext("Translate")}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group))).append(Sao.common.ICONFACTORY.get_icon_img("tryton-translate")),e.click(this.translate.bind(this)))},display:function(){Sao.View.Form.Text._super.display.call(this);var e,t=this.record;t?(e=t.field_get_client(this.field_name),this.input.val(e),this.attributes.spell&&(this.input.attr("lang",Sao.i18n.BC47(t.expr_eval(this.attributes.spell))),this.input.attr("spellcheck","true"))):this.input.val("")},focus:function(){this.input.focus()},get modified(){return!(!this.record||!this.field)&&this._normalize_newline(this.field.get_client(this.record))!=this.get_value()},get_value:function(){return this._normalize_newline(this.input.val()||"")},set_value:function(){var e=this.get_value(),t=this.field.get_client(this.record);e==this._normalize_newline(t)&&(e=t),this.field.set_client(this.record,e)},_normalize_newline:function(e){return e.replace(/\r\n/g,"\n").replace(/\r/g,"\n")},set_readonly:function(e){Sao.View.Form.Text._super.set_readonly.call(this,e),this.input.prop("readonly",e)},translate_widget:function(){var e=jQuery("<textarea/>",{class:"form-control",readonly:"readonly"});return e.css("min-height",this.el.height()),e}}),Sao.View.Form.RichText=Sao.class_(Sao.View.Form.Widget,{class_:"form-richtext",expand:!0,init:function(e,t){Sao.View.Form.RichText._super.init.call(this,e,t),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"}),parseInt(t.toolbar||"1",10)&&(this.toolbar=Sao.common.richtext_toolbar().appendTo(jQuery("<div/>",{class:"panel-heading"}).appendTo(this.el))),this.group=jQuery("<div/>",{class:"input-group"}).appendTo(jQuery("<div/>",{class:"panel-body"}).appendTo(this.el)),this.input=this.labelled=jQuery("<div/>",{class:"richtext mousetrap",contenteditable:!0}).appendTo(this.group),this.group.focusout(this.focus_out.bind(this)),this.attributes.translate&&((e=jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button","aria-label":Sao.i18n.gettext("Translate"),title:Sao.i18n.gettext("Translate")}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group))).append(Sao.common.ICONFACTORY.get_icon_img("tryton-translate")),e.click(this.translate.bind(this)))},focus_out:function(){window.setTimeout(()=>{0===this.el.find(":focus").length&&Sao.View.Form.RichText._super.focus_out.call(this)},0)},display:function(){Sao.View.Form.RichText._super.display.call(this);var e="",t=this.record;t&&(e=t.field_get_client(this.field_name),this.attributes.spell)&&(this.input.attr("lang",Sao.i18n.BC47(t.expr_eval(this.attributes.spell))),this.input.attr("spellcheck","true")),this.input.html(Sao.HtmlSanitizer.sanitize(e||""))},focus:function(){this.input.focus()},get_value:function(){return this._normalize_markup(this.input.html())},set_value:function(){var e=this.get_value(),t=this.field.get_client(this.record);e==this._normalize_markup(t)&&(e=t),this.field.set_client(this.record,e)},_normalize_markup:function(e){return Sao.common.richtext_normalize(Sao.HtmlSanitizer.sanitize(e||""))},get modified(){return!(!this.record||!this.field)&&this._normalize_markup(this.field.get_client(this.record))!=this.get_value()},set_readonly:function(e){Sao.View.Form.RichText._super.set_readonly.call(this,e),this.input.prop("contenteditable",!e),this.toolbar&&this.toolbar.find("button,input,select").prop("disabled",e)},translate_widget:function(){var e=jQuery("<div/>",{class:this.class_+" panel panel-default"});parseInt(this.attributes.toolbar||"1",10)&&Sao.common.richtext_toolbar().appendTo(jQuery("<div/>",{class:"panel-heading"}).appendTo(e)),jQuery("<div/>",{class:"richtext mousetrap",contenteditable:!0}).appendTo(jQuery("<div/>",{class:"panel-body"}).appendTo(e));return e},translate_widget_set_readonly:function(e,t){Sao.View.Form.TranslateMixin.translate_widget_set_readonly.call(this,e,t),e.find("button,input,select").prop("disabled",t),e.find("div[contenteditable]").prop("contenteditable",!t)},translate_widget_set:function(e,t){e.find("div[contenteditable]").html(Sao.HtmlSanitizer.sanitize(t||""))},translate_widget_get:function(e){return this._normalize_markup(e.find("div[contenteditable]").html())}}),Sao.View.Form.Many2One=Sao.class_(Sao.View.Form.Widget,{class_:"form-many2one",init:function(e,t){Sao.View.Form.Many2One._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_});e=jQuery("<div/>",{class:"input-group input-group-sm input-icon"}).appendTo(this.el);this.entry=this.labelled=jQuery("<input/>",{type:"input",class:"form-control input-sm mousetrap",name:t.name}).appendTo(e),this.but_primary=jQuery("<img/>",{class:"icon"}).appendTo(jQuery("<div/>",{class:"icon-input icon-primary"}).appendTo(e)),this.but_secondary=jQuery("<img/>",{class:"icon"}).appendTo(jQuery("<div/>",{class:"icon-input icon-secondary"}).appendTo(e)),this.but_primary.click("primary",this.edit.bind(this)),this.but_secondary.click("secondary",this.edit.bind(this)),this.entry.on("keydown",this.send_modified.bind(this)),this.entry.on("keydown",this.key_press.bind(this)),t.completion&&"1"!=t.completion||(this.wid_completion=Sao.common.get_completion(e,this._update_completion.bind(this),this._completion_match_selected.bind(this)),this.entry.completion=this.wid_completion),this.el.change(this.focus_out.bind(this)),this._readonly=!1},get_screen:function(e){var t=this.field.get_domain(this.record),e=e?this.field.get_search_context(this.record):this.field.get_context(this.record),i=(this.attributes.view_ids||"").split(","),n=(jQuery.isEmptyObject(i)||i.shift(),this.get_model()),o=jQuery.extend([],this.view.screen.breadcrumb);return o.push(this.attributes.string||Sao.common.MODELNAME.get(n)),new Sao.Screen(this.get_model(),{context:e,domain:t,mode:["form"],view_ids:i,views_preload:this.attributes.views,readonly:this._readonly,exclude_field:this.attributes.relation_field,breadcrumb:o})},set_text:function(e){jQuery.isEmptyObject(e)&&(e=""),this.entry.val(e)},get_text:function(){var e=this.record;return e?s(e.field_get_client(this.field_name)):""},focus_out:function(){(this.attributes.completion&&"1"!=this.attributes.completion||!this.el.find(".dropdown").hasClass("open"))&&Sao.View.Form.Many2One._super.focus_out.call(this)},set_value:function(){var e=this.record,t=this.field;this.get_text()!=this.entry.val()&&(t.set_client(e,this.value_from_id(null,"")),this.entry.val(""))},display:function(){var e,t,i,n=this.record,o=this.field;Sao.View.Form.Many2One._super.display.call(this),this._set_button_sensitive(),this._set_completion(),n?(this.set_text(o.get_client(n)),o=o.get(n),n=this.has_target(o)?(e="tryton-open",t=Sao.i18n.gettext("Open the record"),i="tryton-clear",Sao.i18n.gettext("Clear the field")):(e=null,t="",i="tryton-search",Sao.i18n.gettext("Search a record")),this.entry.prop("readonly")&&(i=null),[[e,t,this.but_primary,"primary"],[i,n,this.but_secondary,"secondary"]].forEach(function(e){var t=e[0],i=e[1],n=e[2],o=n.parent(),e="input-icon-"+e[3];t?(o.show(),o.parent().addClass(e),Sao.common.ICONFACTORY.get_icon_url(t).then(function(e){n.attr("src",e)})):(o.hide(),o.parent().removeClass(e)),n.attr("aria-label",i),n.attr("title",i)})):this.entry.val("")},focus:function(){this.entry.focus()},set_readonly:function(e){Sao.View.Form.Many2One._super.set_readonly.call(this,e),this._readonly=e,this._set_button_sensitive()},_set_button_sensitive:function(){this.entry.prop("readonly",this._readonly),this.but_primary.prop("disabled",!this.read_access),this.but_secondary.prop("disabled",this._readonly)},get_access:function(e){var t=this.get_model();return!t||Sao.common.MODELACCESS.get(t)[e]},get read_access(){return this.get_access("read")},get create_access(){var e=this.attributes.create;return void 0===e?e=!0:"string"==typeof e&&(e=Boolean(parseInt(e,10))),e&&this.get_access("create")},get modified(){var e;return!(!this.record||!this.field)&&(e=this.entry.val(),this.get_text()!=e)},id_from_value:function(e){return e},value_from_id:function(e,t=""){return[e,t]},get_model:function(){return this.attributes.relation},has_target:function(e=null){return null!==e},edit:function(t){var e=this.get_model();if(e&&Sao.common.MODELACCESS.get(e).read){var i,n,o=this.record,s=o.field_get(this.field_name);if(t&&"secondary"==t.data&&!this._readonly&&this.has_target(s))this.record.field_set_client(this.field_name,this.value_from_id(null,"")),this.entry.val(""),this.focus();else if(this.has_target(s)){var a=this.id_from_value(o.field_get(this.field_name));if(t&&(t.ctrlKey||t.metaKey))return(s={}).model=this.get_model(),s.res_id=a,s.mode=["form"],s.name=this.attributes.string,s.context=this.field.get_context(this.record),void Sao.Tab.create(s);var r=this.get_screen();let e=e=>{e&&r.current_record.rec_name().done(e=>{e=this.value_from_id(r.current_record.id,e);this.record.field_set_client(this.field_name,e,!0)})};void r.switch_view().done(()=>{r.load([a]),r.current_record=r.group.get(a),new Sao.Window.Form(r,e,{save_current:!0})})}else e&&(t=this.field.get_domain(o),s=this.field.get_search_context(o),o=this.field.get_search_order(o),i=this.entry.val(),n=new Sao.common.DomainParser,new Sao.Window.Search(e,e=>{jQuery.isEmptyObject(e)||(e=this.value_from_id(e[0][0],e[0][1]),this.record.field_set_client(this.field_name,e,!0))},{sel_multi:!1,context:s,domain:t,order:o,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:this.create_access,search_filter:n.quote(i),title:this.attributes.string,exclude_field:this.attributes.relation_field}))}},new_:function(e=null){var t=this.get_model();if(t&&Sao.common.MODELACCESS.get(t).create){var i=this.get_screen(!0);(e=e?jQuery.extend({},e):{}).rec_name=this.entry.val();const n=e=>{e&&i.current_record.rec_name().done(e=>{e=this.value_from_id(i.current_record.id,e);this.record.field_set_client(this.field_name,e)})};i.switch_view().done(()=>{new Sao.Window.Form(i,n,{new_:!0,save_current:!0,defaults:e})})}},key_press:function(e){var t=!this.entry.prop("readonly"),i=[Sao.common.TAB_KEYCODE],n=[Sao.common.BACKSPACE_KEYCODE,Sao.common.DELETE_KEYCODE];this.wid_completion||i.push(Sao.common.RETURN_KEYCODE),e.which==Sao.common.F3_KEYCODE&&t&&this.create_access?(e.preventDefault(),this.new_()):e.which==Sao.common.F2_KEYCODE&&this.read_access?(e.preventDefault(),this.edit()):~i.indexOf(e.which)&&t?(this.attributes.completion&&"1"!=this.attributes.completion||!this.el.find(".dropdown").hasClass("open"))&&this.activate():this.has_target(this.record.field_get(this.field_name))&&t&&(this.get_text()==this.entry.val()&&!~n.indexOf(e.which)||(this.entry.val(""),this.record.field_set_client(this.field_name,this.value_from_id(null,""))))},activate:function(){var e,t,i,n,o,s=this.get_model();s&&Sao.common.MODELACCESS.get(s).read&&(e=(n=this.record).field_get(this.field_name),new Sao.Model(s),s)&&!this.has_target(e)&&(e=this.entry.val(),this._readonly||!e&&!this.field.get_state_attrs(this.record).required||(t=this.field.get_domain(n),i=this.field.get_search_context(n),n=this.field.get_search_order(n),o=new Sao.common.DomainParser,new Sao.Window.Search(s,e=>{jQuery.isEmptyObject(e)?this.entry.val(""):(e=this.value_from_id(e[0][0],e[0][1]),this.record.field_set_client(this.field_name,e,!0))},{sel_multi:!1,context:i,domain:t,order:n,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:this.create_access,search_filter:o.quote(e),title:this.attributes.string,exclude_field:this.attributes.relation_field})))},_set_completion:function(){this.wid_completion&&this.wid_completion.set_actions(this._completion_action_activated.bind(this),this.read_access,this.create_access)},_update_completion:function(e){var t=this.record;if(!t)return jQuery.when();var i=this.field,n=i.get(t);if(this.has_target(n)){n=this.id_from_value(n);if(void 0!==n&&0<=n)return jQuery.when()}n=this.get_model();return Sao.common.update_completion(this.entry,t,i,n)},_completion_match_selected:function(e){null!==e.id?this.record.field_set_client(this.field_name,this.value_from_id(e.id,e.rec_name),!0):this.new_(e.defaults)},_completion_action_activated:function(e){"search"==e?this.edit():"create"==e&&this.new_()}}),Sao.View.Form.One2One=Sao.class_(Sao.View.Form.Many2One,{class_:"form-one2one"}),Sao.View.Form.Reference=Sao.class_(Sao.View.Form.Many2One,{class_:"form-reference",init:function(e,t){Sao.View.Form.Reference._super.init.call(this,e,t),this.el.addClass("form-inline"),this.select=jQuery("<select/>",{class:"form-control input-sm","aria-label":t.string,title:t.string}),this.el.prepend(this.select),this.select.change(this.select_changed.bind(this)),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e,this.set_selection.bind(this))},update_selection:function(e,t,i){Sao.common.selection_mixin.update_selection.call(this,e,t,(e,t)=>{this.set_selection(e,t),i&&i()})},set_selection:function(e,t){var i=this.select;i.empty();for(const n of e)i.append(jQuery("<option/>",{value:n[0],text:n[1],title:t[n[0]]}))},get modified(){var e,t,i;return!(!this.record||!this.field)&&(i=t="",(e=this.field.get_client(this.record))&&(t=e[0],i=s(e[1])),t!=this.get_model()||i!=this.entry.val())},id_from_value:function(e){return parseInt(e.split(",")[1],10)},value_from_id:function(e,t){return t=t||"",[this.get_model(),[e,t]]},get_text:function(){var e=this.record;return e?s(e.field_get_client(this.field_name)[1]):""},get_model:function(){return this.select.val()},has_target:function(e){var t;return null!==e&&(t=e.split(",")[0],e=e.split(",")[1],(jQuery.isEmptyObject(e)||(e=parseInt(e,10),isNaN(e)))&&(e=null),t==this.get_model())&&0<=e},_set_button_sensitive:function(){Sao.View.Form.Reference._super._set_button_sensitive.call(this),this.select.prop("disabled",this.entry.prop("readonly"))},select_changed:function(){this.entry.val("");var e=this.get_model(),e=e?[e,[-1,""]]:["",""];this.record.field_set_client(this.field_name,e)},set_value:function(){var e,t,i,n=this.record,o=this.field;this.get_model()?(i=(t=o.get_client(n,this.field_name))instanceof Array?(e=t[0],s(t[1])):e="",e==this.get_model()&&i==this.entry.val()||(o.set_client(n,null),this.entry.val(""))):(t=this.entry.val(),jQuery.isEmptyObject(t)?o.set_client(n,null):o.set_client(n,["",t]))},set_text:function(e){var t;e=e?(t=e[0],e[1]):t=null,Sao.View.Form.Reference._super.set_text.call(this,e),t?this.select.val(t):this.select.val("")},display:function(){this.update_selection(this.record,this.field,()=>{Sao.View.Form.Reference._super.display.call(this)})},set_readonly:function(e){Sao.View.Form.Reference._super.set_readonly.call(this,e),this.select.prop("disabled",e)}}),Sao.View.Form.One2Many=Sao.class_(Sao.View.Form.Widget,{class_:"form-one2many",expand:!0,init:function(e,t){Sao.View.Form.One2Many._super.init.call(this,e,t),this._readonly=!0,this._required=!1,this._position=0,this._length=0,this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"}),this.menu=jQuery("<div/>",{class:this.class_+"-menu panel-heading"}),this.el.append(this.menu),this.title=jQuery("<label/>",{class:this.class_+"-string",text:t.string}),this.menu.append(this.title),this.title.uniqueId(),this.el.uniqueId(),this.el.attr("aria-labelledby",this.title.attr("id")),this.title.attr("for",this.el.attr("id"));function i(i){return function(e){var t=jQuery(e.target);t.prop("disabled",!0),(i(e)||jQuery.when()).always(function(){t.prop("disabled",!1)})}}var e=jQuery("<div/>",{class:this.class_+"-toolbar"}),e=(this.menu.append(e),jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(e)),n=jQuery("<div/>",{class:"input-group-btn"}).appendTo(e),e=(this.but_switch=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Switch"),title:Sao.i18n.gettext("Switch")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-switch")).appendTo(n),this.but_switch.click(i(this.switch_.bind(this))),this.but_previous=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Previous"),title:Sao.i18n.gettext("Previous")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-back")).appendTo(n),this.but_previous.click(i(this.previous.bind(this))),this.label=jQuery("<span/>",{class:"badge"}).text("_ / 0").appendTo(jQuery("<span/>",{class:"btn hidden-xs"}).appendTo(n)),this.but_next=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Next"),title:Sao.i18n.gettext("Next")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-forward")).appendTo(n),this.but_next.click(i(this.next.bind(this))),t.add_remove&&(this.wid_text=jQuery("<input/>",{type:"text",class:"form-control input-sm",name:t.name}).appendTo(e),t.completion&&"1"!=t.completion||(this.wid_completion=Sao.common.get_completion(this.wid_text,this._update_completion.bind(this),this._completion_match_selected.bind(this),this._completion_action_activated.bind(this),this.read_access,this.create_access),this.wid_text.completion=this.wid_completion),n=jQuery("<div/>",{class:"input-group-btn"}).appendTo(e),this.but_add=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Add"),title:Sao.i18n.gettext("Add")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).appendTo(n),this.but_add.click(i(this.add.bind(this))),this.but_remove=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Remove"),title:Sao.i18n.gettext("Remove")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).appendTo(n),this.but_remove.click(i(this.remove.bind(this)))),this.but_new=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("New"),title:Sao.i18n.gettext("New")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-create")).appendTo(n),this.but_new.click(i(()=>this.new_())),this.but_open=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Open"),title:Sao.i18n.gettext("Open")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-open")).appendTo(n),this.but_open.click(i(this.open.bind(this))),this.but_del=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Delete"),title:Sao.i18n.gettext("Delete")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-delete")).appendTo(n),this.but_del.click(i(this.delete_.bind(this))),this.but_undel=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Undelete"),title:Sao.i18n.gettext("Undelete")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-undo")).appendTo(n),this.but_undel.click(i(this.undelete.bind(this))),this.content=jQuery("<div/>",{class:this.class_+"-content panel-body"}),this.el.append(this.content),(t.mode||"tree,form").split(",")),n=t.relation,o=jQuery.extend([],this.view.screen.breadcrumb);o.push(t.string||Sao.common.MODELNAME.get(n)),this.screen=new Sao.Screen(n,{mode:e,view_ids:(t.view_ids||"").split(","),views_preload:t.views||{},order:t.order,row_activate:this.activate.bind(this),exclude_field:t.relation_field||null,limit:null,context:this.view.screen.context,pre_validate:t.pre_validate,breadcrumb:o}),this.screen.pre_validate=1==t.pre_validate,this.screen.windows.push(this),this.prm=this.screen.switch_view().done(()=>{this.content.append(this.screen.screen_container.el)}),t.add_remove&&this.wid_text.on("keydown",this.key_press.bind(this))},get_access:function(e){var t=this.attributes.relation;return!t||Sao.common.MODELACCESS.get(t)[e]},get read_access(){return this.get_access("read")},get create_access(){var e=this.attributes.create;return void 0===e?e=!0:"string"==typeof e&&(e=Boolean(parseInt(e,10))),e&&this.get_access("create")},get write_access(){return this.get_access("write")},get delete_access(){var e=this.attributes.delete;return void 0===e?e=!0:"string"==typeof e&&(e=Boolean(parseInt(e,10))),e&&this.get_access("delete")},get modified(){return this.screen.current_view.modified},set_readonly:function(e){Sao.View.Form.One2Many._super.set_readonly.call(this,e),this.prm.done(()=>this._set_button_sensitive()),this._set_label_state()},set_required:function(e){this._required=e,this._set_label_state()},_set_label_state:function(){Sao.common.apply_label_attributes(this.title,this._readonly,this._required)},_set_button_sensitive:function(){var e=this.record,t=this.field,e=(t=e&&t?(i=e.expr_eval(this.attributes.size),n=t.get_eval(e).length,null!=i&&i<=n&&0<=i):(n=null,!1),this.screen.deletable),i=this.screen.current_view.view_type,n=1<this.screen.number_of_views;this.but_switch.prop("disabled",!((this._position||"form"==i)&&n)),this.but_new.prop("disabled",this._readonly||!this.create_access||t),this.but_del.prop("disabled",this._readonly||!this.delete_access||!this._position||!e),this.but_undel.prop("disabled",this._readonly||t||!this._position),this.but_open.prop("disabled",!this._position||!this.read_access),this.but_next.prop("disabled",0<this.position&&this._position>=this._length),this.but_previous.prop("disabled",this._position<=1),this.attributes.add_remove&&(this.but_add.prop("disabled",this._readonly||t||!this.write_access||!this.read_access),this.wid_text.prop("disabled",this.but_add.prop("disabled")),this.but_remove.prop("disabled",this._readonly||!this.position||!this.write_access||!this.read_access))},_sequence:function(){for(const t of this.screen.views)if("tree"==t.view_type){var e=t.attributes.sequence;if(e)return e}},display:function(){Sao.View.Form.One2Many._super.display.call(this),this.prm.done(()=>{this._set_button_sensitive();var e,t,i=this.record,n=this.field;n?((e=i.field_get_client(this.field_name))!=this.screen.group&&(this.screen.set_group(e),"form"==this.screen.current_view.view_type)&&this.screen.group.length&&(this.screen.current_record=this.screen.group[0]),e=[],t=null,i&&(e=n.get_domain(i),t=i.expr_eval(this.attributes.size)),!this._readonly&&this.create_access||(t=null==t?this.screen.group.length:Math.min(t,this.screen.group.length)),Sao.common.compare(this.screen.domain,e)||(this.screen.domain=e),this.screen.size_limit=t,this.screen.display(),void 0!==this.attributes.height&&this.screen.current_view.el.find(".treeview,.list-form").first().css("min-height",this.attributes.height+"px").css("max-height",this.attributes.height+"px")):(this.screen.new_group(),this.screen.current_record=null,this.screen.group.parent=null,this.screen.display())})},focus:function(){this.attributes.add_remove&&this.wid_text.focus()},activate:function(e){this.edit()},add:function(e){var t,i,n,s,o,a;this.write_access&&this.read_access&&(this.view.set_value(),i=this.field.get_domain(this.record),t=this.field.get_search_context(this.record),i=["OR",i=[i,this.record.expr_eval(this.attributes.add_remove)],["id","in",this.field.get_removed_ids(this.record)]],n=this.wid_text.val(),s=this._sequence(),o=new Sao.common.DomainParser,a=this.field.get_search_order(this.record),new Sao.Window.Search(this.attributes.relation,e=>{var t=jQuery.when();if(!jQuery.isEmptyObject(e)){for(var i=[],n=0,o=e.length;n<o;n++)i.push(e[n][0]);this.screen.group.load(i,!0),t=this.screen.display(),s&&this.screen.group.set_sequence(s,this.screen.new_position)}t.done(()=>{this.screen.set_cursor()}),this.wid_text.val("")},{sel_multi:!0,context:t,domain:i,order:a,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:!this.but_new.prop("disabled"),search_filter:o.quote(n),title:this.attributes.string,exclude_field:this.attributes.relation_field}))},remove:function(e){var t=!this.screen.readonly;this.write_access&&this.read_access&&t&&this.screen.remove(!1,!0,!1)},new_:function(e=null){Sao.common.MODELACCESS.get(this.screen.model_name).create&&(this.attributes.add_remove&&((e=e?jQuery.extend({},e):{}).rec_name=this.wid_text.val()),this.validate().done(()=>{this.attributes.product?this.new_product(e):this.new_single(e)}))},new_single:function(e=null){var t,i,n=this._sequence(),o=()=>{n&&this.screen.group.set_sequence(n,this.screen.new_position)};this.screen.current_view.creatable?(this.screen.new_().then(o),this.screen.current_view.el.prop("disabled",!1)):(i=(t=this.record).expr_eval(this.attributes.size)||-1,i-=this.field.get_eval(t).length,new Sao.Window.Form(this.screen,o,{new_:!0,defaults:e,many:i}))},new_product:function(e=null){var l=this.attributes.product.split(","),c={},d=this.screen;d.new_(!1).then(r=>{r.default_get(e).then(o=>{r.set_default(o);const s=()=>{if(jQuery.isEmptyObject(l))return a();var t=d.model.fields[l.pop()],e=t.description.relation,i=(e||s(),t.get_domain(r)),n=t.get_search_context(r),o=t.get_search_order(r);new Sao.Window.Search(e,function(e){jQuery.isEmptyObject(e)||(c[t.name]=e),s()},{sel_multi:!0,context:n,domain:i,order:o,search_filter:"",title:this.attributes.string})},a=()=>{var t,e;d.group.remove(r,!0),!jQuery.isEmptyObject(c)&&(e=(t=Object.keys(c)).map(function(e){return c[e]}),Sao.common.product(e).forEach(function(n){d.new_(!1).then(function(e){var i=jQuery.extend({},o);t.forEach(function(e,t){i[e]=n[t][0],i[e+".rec_name"]=n[t][1]}),e.set_default(i)})}),e=this._sequence())&&d.group.set_sequence(e,d.new_position)};s()})})},open:function(e){return this.edit()},delete_:function(e){Sao.common.MODELACCESS.get(this.screen.model_name).delete&&this.screen.deletable&&this.screen.remove(!1,!1,!1)},undelete:function(e){this.screen.unremove()},previous:function(e){return this.validate().then(()=>this.screen.display_previous())},next:function(e){return this.validate().then(()=>this.screen.display_next())},switch_:function(e){return this.screen.switch_view()},edit:function(){if(Sao.common.MODELACCESS.get(this.screen.model_name).read)return this.validate().then(()=>{this.screen.current_record&&new Sao.Window.Form(this.screen,function(){})})},key_press:function(e){var t;e.which==Sao.common.F3_KEYCODE?(e.preventDefault(),this.new_()):e.which==Sao.common.F2_KEYCODE&&(e.preventDefault(),this.add(e)),this.attributes.add_remove&&(t=[Sao.common.TAB_KEYCODE],this.wid_completion||t.push(Sao.common.RETURN_KEYCODE),~t.indexOf(e.which))&&this.wid_text.val()&&this.add(e)},record_message:function(e,t){this._position=e,this._length=t;var i="_",e=(e&&(i=" "+e,1<(e=this.screen.selected_records.length))&&(i+="#"+e),i+" / "+Sao.common.humanize(t));this.label.text(e).attr("title",e),this.prm.done(()=>this._set_button_sensitive())},validate:function(){var e,t=jQuery.Deferred(),i=(this.view.set_value(),this.screen.current_record);return i?(e=this.screen.current_view.get_fields(),i.validate(e).then(e=>{if(e)return this.screen.pre_validate?i.pre_validate().then(t.resolve,t.reject):void t.resolve();this.screen.display(!0),t.reject()})):t.resolve(),t},set_value:function(){this.screen.save_tree_state(),this.screen.modified()&&this.view.screen.record_modified(!1)},_update_completion:function(e){var t,i,n;return this.record?(t=this.attributes.relation,i=[i=this.field.get_domain(this.record),this.record.expr_eval(this.attributes.add_remove)],n=this.field.get_removed_ids(this.record),Sao.common.update_completion(this.wid_text,this.record,this.field,t,i=["OR",i,["id","in",n]])):jQuery.when()},_completion_match_selected:function(e){null!==e.id?(this.screen.group.load([e.id],!0),this.wid_text.val("")):this.new_(e.defaults)},_completion_action_activated:function(e){"search"==e?this.add():"create"==e&&this.new_()}}),Sao.View.Form.Many2Many=Sao.class_(Sao.View.Form.Widget,{class_:"form-many2many",expand:!0,init:function(e,t){Sao.View.Form.Many2Many._super.init.call(this,e,t),this._readonly=!0,this._required=!1,this._position=0,this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"}),this.menu=jQuery("<div/>",{class:this.class_+"-menu panel-heading"}),this.el.append(this.menu),this.title=jQuery("<label/>",{class:this.class_+"-string",text:t.string}),this.menu.append(this.title),this.title.uniqueId(),this.el.uniqueId(),this.el.attr("aria-labelledby",this.title.attr("id")),this.title.attr("for",this.el.attr("id"));var e=jQuery("<div/>",{class:this.class_+"-toolbar"}),e=(this.menu.append(e),jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(e)),e=(this.entry=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:t.name}).appendTo(e),this.entry.on("keydown",this.key_press.bind(this)),t.completion&&"1"!=t.completion||(this.wid_completion=Sao.common.get_completion(e,this._update_completion.bind(this),this._completion_match_selected.bind(this),this._completion_action_activated.bind(this),this.read_access,this.create_access),this.entry.completion=this.wid_completion),jQuery("<div/>",{class:"input-group-btn"}).appendTo(e)),e=(this.but_add=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Add"),title:Sao.i18n.gettext("Add")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).appendTo(e),this.but_add.click(this.add.bind(this)),this.label=jQuery("<span/>",{class:"badge"}).text("_ / 0").appendTo(jQuery("<span/>",{class:"btn hidden-xs"}).appendTo(e)),this.but_remove=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Remove"),title:Sao.i18n.gettext("Remove")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).appendTo(e),this.but_remove.click(this.remove.bind(this)),this.content=jQuery("<div/>",{class:this.class_+"-content panel-body"}),this.el.append(this.content),t.relation),i=jQuery.extend([],this.view.screen.breadcrumb);i.push(t.string||Sao.common.MODELNAME.get(e)),this.screen=new Sao.Screen(t.relation,{mode:["tree"],view_ids:(t.view_ids||"").split(","),views_preload:t.views||{},order:t.order,row_activate:this.activate.bind(this),readonly:!0,limit:null,context:this.view.screen.context,breadcrumb:i}),this.screen.windows.push(this),this.prm=this.screen.switch_view("tree").done(()=>{this.content.append(this.screen.screen_container.el)})},get_access:function(e){var t=this.attributes.relation;return!t||Sao.common.MODELACCESS.get(t)[e]},get read_access(){return this.get_access("read")},get create_access(){var e=this.attributes.create;return void 0===e?e=!0:"string"==typeof e&&(e=Boolean(parseInt(e,10))),e&&this.get_access("create")},set_readonly:function(e){Sao.View.Form.Many2Many._super.set_readonly.call(this,e),this._set_button_sensitive(),this._set_label_state()},set_required:function(e){this._required=e,this._set_label_state()},_set_label_state:function(){Sao.common.apply_label_attributes(this.title,this._readonly,this._required)},_set_button_sensitive:function(){var e,t=!1,i=this.record,n=this.field;i&&n&&(e=i.expr_eval(this.attributes.size),n=n.get_eval(i).length,t=null!=e&&e<=n&&0<=e),this.entry.prop("disabled",this._readonly),this.but_add.prop("disabled",this._readonly||t),this.but_remove.prop("disabled",this._readonly||0===this._position)},record_message:function(e,t){var i="_",e=((this._position=e)&&(i=" "+e,1<(e=this.screen.selected_records.length))&&(i+="#"+e),i+" / "+Sao.common.humanize(t));this.label.text(e).attr("title",e),this._set_button_sensitive()},display:function(){Sao.View.Form.Many2Many._super.display.call(this),this.prm.done(()=>{var e=this.record;this.field?((e=e.field_get_client(this.field_name))!=this.screen.group&&this.screen.set_group(e),this.screen.display(),void 0!==this.attributes.height&&this.screen.current_view.el.find(".treeview,.list-form").first().css("min-height",this.attributes.height+"px").css("max-height",this.attributes.height+"px")):(this.screen.new_group(),this.screen.current_record=null,this.screen.group.parent=null,this.screen.display())})},focus:function(){this.entry.focus()},activate:function(){this.edit()},add:function(){var e=this.field.get_domain(this.record),t=this.record.expr_eval(this.attributes.add_remove),t=(jQuery.isEmptyObject(t)||(e=[e,t]),this.field.get_search_context(this.record)),i=this.field.get_search_order(this.record),n=this.entry.val(),o=new Sao.common.DomainParser;new Sao.Window.Search(this.attributes.relation,e=>{if(!jQuery.isEmptyObject(e)){for(var t=[],i=0,n=e.length;i<n;i++)t.push(e[i][0]);this.screen.group.load(t,!0),this.screen.display()}this.entry.val("")},{sel_multi:!0,context:t,domain:e,order:i,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:this.create_access,search_filter:o.quote(n),title:this.attributes.string})},remove:function(){this.screen.remove(!1,!0,!1)},key_press:function(e){var t=[Sao.common.TAB_KEYCODE];this.wid_completion||t.push(Sao.common.RETURN_KEYCODE),e.which==Sao.common.F3_KEYCODE?(e.preventDefault(),this.new_()):e.which==Sao.common.F2_KEYCODE?(e.preventDefault(),this.add()):~t.indexOf(e.which)&&this.entry.val()&&this.add()},_get_screen_form:function(){var e=this.field.get_domain(this.record),t=this.record.expr_eval(this.attributes.add_remove),t=(jQuery.isEmptyObject(t)||(e=[e,t]),this.field.get_context(this.record)),i=(this.attributes.view_ids||"").split(","),n=(jQuery.isEmptyObject(i)||i.shift(),this.attributes.relation),o=jQuery.extend([],this.view.screen.breadcrumb);return o.push(this.attributes.string||Sao.common.MODELNAME.get(n)),new Sao.Screen(n,{domain:e,view_ids:i,mode:["form"],views_preload:this.attributes.views,context:t,breadcrumb:o})},edit:function(){if(!jQuery.isEmptyObject(this.screen.current_record)){var t=this._get_screen_form();const e=e=>{e&&t.current_record.save().done(()=>{var e="id"in this.screen.current_record.modified_fields;this.screen.current_record.cancel(),e&&(this.screen.current_record.modified_fields.id=!0)})};t.switch_view().done(()=>{t.load([this.screen.current_record.id]),t.current_record=t.group.get(this.screen.current_record.id),new Sao.Window.Form(t,e)})}},new_:function(e=null){var t=this._get_screen_form();(e=e?jQuery.extend({},e):{}).rec_name=this.entry.val();const i=e=>{e&&(e=t.current_record,this.screen.group.load([e.id],!0)),this.entry.val("")};t.switch_view().done(()=>{new Sao.Window.Form(t,i,{new_:!0,save_current:!0,defaults:e})})},_update_completion:function(e){var t,i,n;return this.record?(t=this.attributes.relation,i=this.field.get_domain(this.record),n=this.record.expr_eval(this.attributes.add_remove),jQuery.isEmptyObject(n)||(i=[i,n]),Sao.common.update_completion(this.entry,this.record,this.field,t,i)):jQuery.when()},_completion_match_selected:function(e){null!==e.id?(this.screen.group.load([e.id],!0),this.entry.val("")):this.new_(e.defaults)},_completion_action_activated:function(e){"search"==e?this.add():"create"==e&&this.new_()}}),Sao.View.Form.BinaryMixin=Sao.class_(Sao.View.Form.Widget,{init:function(e,t){Sao.View.Form.BinaryMixin._super.init.call(this,e,t),this.filename=t.filename||null},toolbar:function(e){e=jQuery("<div/>",{class:e,role:"group"});return this.but_save_as=jQuery("<button/>",{class:"btn btn-default",type:"button","aria-label":Sao.i18n.gettext("Save As"),title:Sao.i18n.gettext("Save As...")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-download")).appendTo(e),this.but_save_as.click(this.save_as.bind(this)),this.input_select=jQuery("<input/>",{type:"file"}).change(this.select.bind(this)),this.but_select=jQuery("<div/>",{class:"btn btn-default input-file",type:"button","aria-label":Sao.i18n.gettext("Select"),title:Sao.i18n.gettext("Select...")}).append(this.input_select).append(Sao.common.ICONFACTORY.get_icon_img("tryton-search")).appendTo(e),this.but_clear=jQuery("<button/>",{class:"btn btn-default",type:"button","aria-label":Sao.i18n.gettext("Clear"),title:Sao.i18n.gettext("Clear")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-clear")).appendTo(e),this.but_clear.click(this.clear.bind(this)),e},get filename_field(){if(this.filename){var e=this.record;if(e)return e.model.fields[this.filename]}},update_buttons:function(e){e?(this.but_save_as.show(),this.but_select.hide(),this.but_clear.show()):(this.but_save_as.hide(),this.but_select.show(),this.but_clear.hide())},select:function(){var i=this.record,n=this.field,o=this.filename_field;Sao.common.get_input_data(this.input_select,function(e,t){n.set_client(i,e),o&&o.set_client(i,t)},!n.get_size)},open:function(){this.save_as()},save_as:function(){var e=this.field,t=this.record,e=e.get_data?e.get_data(t):jQuery.when(e.get(t));e.done(e=>{var t,i=this.filename_field;i&&(t=i.get(this.record)),Sao.common.download_file(e,t)})},clear:function(){this.input_select.val(null);var e=this.filename_field;e&&e.set_client(this.record,null),this.field.set_client(this.record,null)}}),Sao.View.Form.Binary=Sao.class_(Sao.View.Form.BinaryMixin,{class_:"form-binary",blob_url:"",init:function(e,t){Sao.View.Form.Binary._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_});e=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el);this.size=jQuery("<input/>",{type:"input",class:"form-control input-sm",readonly:!0,name:t.name}).appendTo(e),this.filename&&t.filename_visible&&(this.text=jQuery("<input/>",{type:"input",class:"form-control input-sm"}).prependTo(e),this.text.change(this.focus_out.bind(this)),this.text.on("keydown",this.key_press.bind(this)),this.text.css("width","50%"),this.size.css("width","50%"),this.but_open=jQuery("<button/>",{class:"btn btn-default",type:"button","aria-label":Sao.i18n.gettext("Open..."),title:Sao.i18n.gettext("Open...")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-open")).appendTo(jQuery("<span/>",{class:"input-group-btn"}).prependTo(e)),this.but_open.click(this.open.bind(this))),this.toolbar("input-group-btn").appendTo(e)},display:function(){Sao.View.Form.Binary._super.display.call(this);var e=this.record,t=this.field;t?(t=t.get_size?t.get_size(e):t.get(e).length,this.size.val(Sao.common.humanize(t,"B")),this.text&&(this.text.val(this.filename_field.get(e)||""),t?this.but_open.parent().show():this.but_open.parent().hide()),this.update_buttons(Boolean(t))):(this.text&&this.text.val(""),this.size.val(""),this.but_save_as.hide())},key_press:function(e){var t=!this.text.prop("readonly");e.which==Sao.common.F3_KEYCODE&&t?(e.preventDefault(),this.new_()):e.which==Sao.common.F2_KEYCODE&&(e.preventDefault(),this.open())},set_value:function(){this.text&&this.filename_field.set_client(this.record,this.text.val()||"")},set_readonly:function(e){Sao.View.Form.Binary._super.set_readonly.call(this,e),this.but_select.prop("disabled",e),this.but_clear.prop("disabled",e),this.text&&this.text.prop("readonly",e)}}),Sao.View.Form.MultiSelection=Sao.class_(Sao.View.Form.Selection,{class_:"form-multiselection",expand:!0,init:function(e,t){this.nullable_widget=!1,Sao.View.Form.MultiSelection._super.init.call(this,e,t),this.select.prop("multiple",!0)},set_selection:function(e,t){Sao.View.Form.MultiSelection._super.set_selection.call(this,e,t);var i=this.attributes.help;i&&this.select.children().each(function(){var e=jQuery(this),t=e.attr("title");t&&e.attr("title",i+"\n"+t)})},get modified(){var e,t;return!(!this.record||!this.field||(e=new Set(this.field.get_eval(this.record)),t=new Set(this.get_value()),Sao.common.compare(t,e)))},display_update_selection:function(){var t=this.record,i=this.field;this.update_selection(t,i,()=>{var e=this.attributes.yexpand;(e=void 0===e?this.expand:e)||this.select.prop("size",this.select.children().length),i&&(e=(e=i.get_eval(t)).map(function(e){return JSON.stringify(e)}),this.select.val(e))})},get_value:function(){var e=this.select.val();return e?e.map(function(e){return JSON.parse(e)}):[]}}),Sao.View.Form.Image=Sao.class_(Sao.View.Form.BinaryMixin,{class_:"form-image",init:function(e,t){switch(Sao.View.Form.Image._super.init.call(this,e,t),this.height=parseInt(t.height||100,10),this.width=parseInt(t.width||300,10),this.el=jQuery("<div/>",{class:this.class_+" thumbnail"}),this.image=jQuery("<img/>",{class:"center-block"}).appendTo(this.el),this.image.css("max-height",this.height),this.image.css("max-width",this.width),this.image.css("height","auto"),this.image.css("width","auto"),t.border){case"rounded":this.image.addClass("img-rounded");break;case"circle":this.image.addClass("img-circle")}e=this.toolbar("btn-group");t.readonly||jQuery("<div/>",{class:"text-center caption"}).append(e).appendTo(this.el)},set_readonly:function(e){Sao.View.Form.Image._super.set_readonly.call(this,e),this.but_select.prop("disabled",e),this.but_clear.prop("disabled",e)},clear:function(){Sao.View.Form.Image._super.clear.call(this),this.update_img()},update_img:function(){var e,t=this.record;(e=!(e=t?t.field_get_client(this.field_name):e)||e>Sao.config.image_max_size?jQuery.when(null):t.model.fields[this.field_name].get_data(t)).done(e=>{t===this.record&&(this.image.attr("src",Sao.common.image_url(e)),this.update_buttons(Boolean(e)))})},display:function(){Sao.View.Form.Image._super.display.call(this),this.update_img()}}),Sao.View.Form.Document=Sao.class_(Sao.View.Form.BinaryMixin,{class_:"form-document",expand:!0,init:function(e,t){Sao.View.Form.Document._super.init.call(this,e,t),this._blob_url=null,this.el=jQuery("<div/>",{class:this.class_}),this.object=jQuery("<object/>",{class:"center-block"}).appendTo(this.el),t.height&&this.object.css("height",parseInt(t.height,10)),t.width&&this.object.css("width",parseInt(t.width,10))},display:function(){Sao.View.Form.Document._super.display.call(this);var n,o=this.record,e=o?o.model.fields[this.field_name].get_data(o):jQuery.when(null),t=this.filename_field;t&&(n=t.get_client(o)),e.done(e=>{var t,i;o===this.record&&(window.URL.revokeObjectURL(this.object.attr("data")),t=e?("application/octet-binary"==(i=Sao.common.guess_mimetype(n))&&(i=null),e=new Blob([e],{type:i}),window.URL.createObjectURL(e)):null,(i=this.object.clone()).get(0).onload=function(){this.onload=null,window.URL.revokeObjectURL(t)},i.attr("data",t),this.object.replaceWith(i),this.object=i)})}}),Sao.View.Form.URL=Sao.class_(Sao.View.Form.Char,{class_:"form-url",_type:"url",init:function(e,t){Sao.View.Form.URL._super.init.call(this,e,t),this.input.attr("type",this._type),this.button=this.labelled=jQuery("<a/>",{class:"btn btn-default",target:"_blank",rel:"noreferrer noopener"}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group)),this.icon=jQuery("<img/>").appendTo(this.button),this.set_icon()},display:function(){Sao.View.Form.URL._super.display.call(this);var e="",t=this.record;this.field;t&&(e=t.field_get_client(this.field_name)),this.set_url(e),t&this.attributes.icon&&(t=(e=this.attributes.icon)in t.model.fields?t.field_get_client(e):e,this.set_icon(t))},set_icon:function(e){Sao.common.ICONFACTORY.get_icon_url(e=e||"tryton-public").done(e=>{this.icon.attr("src",e)})},set_url:function(e){this.button.attr("href",e),this.button.toggle(Boolean(e))},set_invisible:function(e){Sao.View.Form.URL._super.set_invisible.call(this,e),e?this.input.attr("type",""):this.input.attr("type",this._type)}}),Sao.View.Form.Email=Sao.class_(Sao.View.Form.URL,{class_:"form-email",_type:"email",set_url:function(e){Sao.View.Form.Email._super.set_url.call(this,"mailto:"+e)}}),Sao.View.Form.CallTo=Sao.class_(Sao.View.Form.URL,{class_:"form-callto",set_url:function(e){Sao.View.Form.CallTo._super.set_url.call(this,"callto:"+e)}}),Sao.View.Form.SIP=Sao.class_(Sao.View.Form.URL,{class_:"form-sip",set_url:function(e){Sao.View.Form.SIP._super.set_url.call(this,"sip:"+e)}}),Sao.View.Form.HTML=Sao.class_(Sao.View.Form.Widget,{class_:"form-html",init:function(e,t){Sao.View.Form.HTML._super.init.call(this,e,t),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_}),this.button=jQuery("<a/>",{class:"btn btn-lnk",target:"_blank",rel:"noreferrer noopener"}).text(t.string).appendTo(this.el),t.translate&&((e=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Translate"),title:Sao.i18n.gettext("Translate")}).appendTo(this.el)).append(Sao.common.ICONFACTORY.get_icon_img("tryton-translate")),e.click(this.translate.bind(this)))},uri:function(e){var t=this.record,i=!t||t.id<0?"":(i="/"+t.model.session.database+"/ir/html/"+t.model.name+"/"+t.id+"/"+this.field_name,(i+="?language="+encodeURIComponent(e||Sao.i18n.getlang()))+"&title="+encodeURIComponent(Sao.config.title));return i},display:function(){Sao.View.Form.HTML._super.display.call(this),this.button.attr("href",this.uri())},set_readonly:function(e){Sao.View.Form.HTML._super.set_readonly.call(this,e),this.el.find("button").prop("disabled",e),e?this.el.find("a").hide():this.el.find("a").show()},translate_dialog:function(e){var t={};for(const i of e)t[i.name]=i.code;Sao.common.selection(Sao.i18n.gettext("Choose a language"),t).done(e=>{window.open(this.uri(e),"_blank","noreferrer,noopener")})}}),Sao.View.Form.ProgressBar=Sao.class_(Sao.View.Form.Widget,{class_:"form-char",init:function(e,t){Sao.View.Form.ProgressBar._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_+" progress"}),this.progressbar=jQuery("<div/>",{class:"progress-bar",role:"progressbar","aria-valuemin":0,"aria-valuemax":100}).appendTo(this.el),this.progressbar.css("min-width: 2em")},display:function(){Sao.View.Form.ProgressBar._super.display.call(this);var e,t=this.record,i=this.field,n=i?(e=i.get(t),(n=i.get_client(t,100))&&Sao.i18n.gettext("%1%",n)):(e=0,"");this.progressbar.attr("aria-valuenow",100*e),this.progressbar.css("width",100*e+"%"),this.progressbar.text(n)}}),Sao.View.Form.Dict=Sao.class_(Sao.View.Form.Widget,{class_:"form-dict",expand:!0,init:function(e,t){Sao.View.Form.Dict._super.init.call(this,e,t),this.schema_model=t.schema_model,this.fields={},this.rows={},this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"});e=jQuery("<div/>",{class:this.class_+"-heading panel-heading"}).appendTo(this.el),e=jQuery("<label/>",{class:this.class_+"-string",text:t.string}).appendTo(e),e.uniqueId(),this.el.uniqueId(),this.el.attr("aria-labelledby",e.attr("id")),e.attr("for",this.el.attr("id")),e=jQuery("<div/>",{class:this.class_+"-body panel-body form-horizontal"}).appendTo(this.el),this.container=jQuery("<div/>",{class:this.class_+"-container"}).appendTo(e),e=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(jQuery("<div>",{class:"col-sm-10 col-sm-offset-2"}).appendTo(jQuery("<div/>",{class:"form-group"}).appendTo(e)));this.wid_text=jQuery("<input/>",{type:"text",class:"form-control input-sm",placeholder:Sao.i18n.gettext("Search"),name:t.name}).appendTo(e),t.completion&&"1"!=t.completion||(this.wid_completion=Sao.common.get_completion(e,this._update_completion.bind(this),this._completion_match_selected.bind(this)),this.wid_text.completion=this.wid_completion),this.but_add=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Add"),title:Sao.i18n.gettext("Add")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).appendTo(jQuery("<div/>",{class:"input-group-btn"}).appendTo(e)),this.but_add.click(this.add.bind(this)),this._readonly=!1,this._record_id=null},_required_el:function(){return this.wid_text},_invalid_el:function(){return this.wid_text},add:function(){var e=this.field.get_context(this.record),t=this.wid_text.val(),i=this.field.get_domain(this.record),n=new Sao.common.DomainParser;new Sao.Window.Search(this.schema_model,e=>{jQuery.isEmptyObject(e)||(e=e.map(function(e){return e[0]}),this.add_new_keys(e)),this.wid_text.val("")},{sel_multi:!0,context:e,domain:i,new_:!1,search_filter:n.quote(t),title:this.attributes.string})},add_new_keys:function(e){this.field.add_new_keys(e,this.record).then(e=>{this.send_modified();var t=!1;for(const i of e)i in this.fields||(this.add_line(i),t)||(this.fields[i].input.focus(),t=!0)})},remove:function(e,t=!0){delete this.fields[e],this.rows[e].remove(),delete this.rows[e],t&&(this.send_modified(),this.set_value(this.record,this.field))},set_value:function(){this.field.set_client(this.record,this.get_value())},get_value:function(){var e,t={};for(e in this.fields){var i=this.fields[e];t[e]=i.get_value()}return t},get modified(){if(this.record&&this.field){var e,t=this.field.get_client(this.record);for(e in this.fields)if(this.fields[e].modified(t))return!0}return!1},set_readonly:function(e){for(var t in Sao.View.Form.Dict._super.set_readonly.call(this,e),this._set_button_sensitive(),this.fields)this.fields[t].set_readonly(e);this.wid_text.prop("disabled",e)},_set_button_sensitive:function(){var e,t=this.attributes.create,i=(void 0===t?t=1:"string"==typeof t&&(t=Boolean(parseInt(t,10))),this.attributes.delete);for(e in void 0===i?i=1:"string"==typeof i&&(i=Boolean(parseInt(i,10))),this.but_add.prop("disabled",this._readonly||!t),this.fields)this.fields[e].button.prop("disabled",this._readonly||!i)},add_line:function(e){var t,i,n=this.field.keys[e],n=(this.fields[e]=t=new(this.get_entries(n.type))(e,this),this.rows[e]=i=jQuery("<div/>",{class:"form-group"}),n.string+Sao.i18n.gettext(":")),n=jQuery("<label/>",{text:n}).appendTo(jQuery("<div/>",{class:"dict-label col-sm-2 control-label"}).appendTo(i));t.el.addClass("col-sm-10").appendTo(i),n.uniqueId(),t.labelled.uniqueId(),t.labelled.attr("aria-labelledby",n.attr("id")),n.attr("for",t.labelled.attr("id")),t.button.click(()=>{this.remove(e,!0)}),i.appendTo(this.container)},display:function(){Sao.View.Form.Dict._super.display.call(this);var e=this.record,c=this.field;if(c){var t,i=e?e.id:null;if(i!=this._record_id){for(t in this.fields)this.remove(t,!1);this._record_id=i}var d=c.get_client(e),i=Object.keys(d).filter(e=>!this.fields[e]),i=jQuery.isEmptyObject(i)?jQuery.when():c.add_keys(i,e);i.then(()=>{for(var e=Object.keys(d).filter(function(e){return c.keys[e]}).sort(function(e,t){e=c.keys[e].sequence,t=c.keys[t].sequence;return e<t?-1:t<e?1:0}),t=new Sao.PYSON.Decoder,i=new Sao.common.DomainInversion,n=0,o=e.length;n<o;n++){var s=e[n],a=d[s],r=(this.fields[s]||this.add_line(s),this.fields[s]),a=(r.set_value(a),r.set_readonly(this._readonly),t.decode(c.keys[s].domain||"null"));null!==a&&(i.eval_domain(a,d)?r.el.removeClass("has-error"):r.el.addClass("has-error"))}var l=Object.keys(this.fields).filter(function(e){return!(e in d)});for(n=0,o=l.length;n<o;n++)s=l[n],this.remove(s,!1)}),this._set_button_sensitive()}},_update_completion:function(e){return!this.wid_text.prop("disabled")&&this.record?Sao.common.update_completion(this.wid_text,this.record,this.field,this.schema_model):jQuery.when()},_completion_match_selected:function(e){this.add_new_keys([e.id]),this.wid_text.val("")},get_entries:function(e){switch(e){case"char":return Sao.View.Form.Dict.Entry;case"boolean":return Sao.View.Form.Dict.Boolean;case"selection":return Sao.View.Form.Dict.Selection;case"multiselection":return Sao.View.Form.Dict.MultiSelection;case"integer":return Sao.View.Form.Dict.Integer;case"float":return Sao.View.Form.Dict.Float;case"numeric":return Sao.View.Form.Dict.Numeric;case"date":return Sao.View.Form.Dict.Date;case"datetime":return Sao.View.Form.Dict.DateTime}}}),Sao.View.Form.Dict.Entry=Sao.class_(Object,{init:function(e,t){this.name=e,this.definition=t.field.keys[e],this.parent_widget=t,this.create_widget(),this.definition.help&&this.el.attr("title",this.definition.help)},create_widget:function(){this.el=jQuery("<div/>",{class:this.class_});var e=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el);this.input=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:this.name}).appendTo(e),this.button=jQuery("<button/>",{class:"btn btn-default",type:"button","arial-label":Sao.i18n.gettext("Remove"),title:Sao.i18n.gettext("Remove")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).appendTo(jQuery("<div/>",{class:"input-group-btn"}).appendTo(e)),this.el.on("keydown",this.parent_widget.send_modified.bind(this.parent_widget)),this.el.change(this.parent_widget.focus_out.bind(this.parent_widget))},modified:function(e){return JSON.stringify(this.get_value())!=JSON.stringify(e[this.name])},get_value:function(){return this.input.val()},set_value:function(e){this.input.val(e||"")},set_readonly:function(e){this._readonly=e,this.input.prop("readonly",e)}}),Sao.View.Form.Dict.Char=Sao.class_(Sao.View.Form.Dict.Entry,{class_:"dict-char",modified:function(e){return JSON.stringify(this.get_value())!=JSON.stringify(e[this.name]||"")}}),Sao.View.Form.Dict.Boolean=Sao.class_(Sao.View.Form.Dict.Entry,{class_:"dict-boolean",create_widget:function(){Sao.View.Form.Dict.Boolean._super.create_widget.call(this),this.input.attr("type","checkbox"),this.input.change(this.parent_widget.focus_out.bind(this.parent_widget))},get_value:function(){return this.input.prop("checked")},set_readonly:function(e){this._readonly=e,this.input.prop("disabled",e)},set_value:function(e){this.input.prop("checked",Boolean(e))}}),Sao.View.Form.Dict.SelectionEntry=Sao.class_(Sao.View.Form.Dict.Entry,{create_widget:function(){Sao.View.Form.Dict.SelectionEntry._super.create_widget.call(this);var e=jQuery("<select/>",{class:"form-control input-sm mousetrap",name:this.name}),t=(e.change(this.parent_widget.focus_out.bind(this.parent_widget)),this.input.replaceWith(e),this.input=this.labelled=e,jQuery.extend([],this.definition.selection));void 0!==this.definition.sort&&!this.definition.sort||t.sort(function(e,t){return e[1].localeCompare(t[1])});for(const i of t)e.append(jQuery("<option/>",{value:JSON.stringify(i[0]),text:i[1],title:this.definition.help_selection[i[0]]}))},set_readonly:function(e){this._readonly=e,this.input.prop("disabled",e)}}),Sao.View.Form.Dict.Selection=Sao.class_(Sao.View.Form.Dict.SelectionEntry,{class_:"dict-selection",create_widget:function(){Sao.View.Form.Dict.Selection._super.create_widget.call(this),this.input.prepend(jQuery("<option/>",{value:JSON.stringify(null),text:""}))},get_value:function(){return JSON.parse(this.input.val())},set_value:function(e){this.input.val(JSON.stringify(e));e=this.definition.help_selection[e]||null;this.definition.help&&(e=e&&this.definition.help+"\n"+e),this.input.attr("title",e)}}),Sao.View.Form.Dict.MultiSelection=Sao.class_(Sao.View.Form.Dict.SelectionEntry,{class_:"dict-multiselection",create_widget:function(){Sao.View.Form.Dict.MultiSelection._super.create_widget.call(this),this.input.prop("multiple",!0);var i=this.definition.help;i&&this.input.children().each(function(){var e=jQuery(this),t=e.attr("title");t&&e.attr("title",i+"\n"+t)})},get_value:function(){return this.input.val().map(function(e){return JSON.parse(e)})},set_value:function(e){e=e&&e.map(function(e){return JSON.stringify(e)}),this.input.val(e)}}),Sao.View.Form.Dict.Integer=Sao.class_(Sao.View.Form.Dict.Entry,{class_:"dict-integer",create_widget:function(){Sao.View.Form.Dict.Integer._super.create_widget.call(this),this.input_text=this.labelled=n(this.input)},get_value:function(){var e=parseInt(this.input.val(),10);return isNaN(e)?null:e},set_value:function(e,t){"number"==typeof e||e instanceof Sao.Decimal?(this.input.val(e),this.input_text.val(e.toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),t))):(this.input.val(""),this.input_text.val(""))},set_readonly:function(e){Sao.View.Form.Dict.Integer._super.set_readonly.call(this,e),this.input_text.prop("readonly",e)}}),Sao.View.Form.Dict.Float=Sao.class_(Sao.View.Form.Dict.Integer,{class_:"dict-float",get digits(){var e=this.parent_widget.record;if(e){e=e.expr_eval(this.definition.digits);if(e&&e.every(function(e){return null!==e}))return e}},get_value:function(){var e=this.input.val();return!e&&0!==e||(e=Number(e),isNaN(e))?null:e},set_value:function(e){var t="any",i={},n=this.digits;n&&(t=Math.pow(10,-n[1]).toFixed(n[1]),i.minimumFractionDigits=n[1],i.maximumFractionDigits=n[1]),this.input.attr("step",t),Sao.View.Form.Dict.Float._super.set_value.call(this,e,i)}}),Sao.View.Form.Dict.Numeric=Sao.class_(Sao.View.Form.Dict.Float,{class_:"dict-numeric",get_value:function(){var e=this.input.val();return!e&&0!==e||(e=new Sao.Decimal(e),isNaN(e.valueOf()))?null:e}}),Sao.View.Form.Dict.Date=Sao.class_(Sao.View.Form.Dict.Entry,{class_:"dict-date",format:"%x",_input:"date",_input_format:"%Y-%m-%d",_format:Sao.common.format_date,_parse:Sao.common.parse_date,create_widget:function(){Sao.View.Form.Dict.Date._super.create_widget.call(this);var e=this.input.parent().find(".input-group-btn"),t=(this.input_date=jQuery("<input/>",{type:this._input,role:"button",tabindex:-1}),this.input_date.click(()=>{var e=this.get_value(),e=this._format(this._input_format,e);this.input_date.val(e)}),this.input_date.change(()=>{var e=this.input_date.val();e&&(e=this._parse(this._input_format,e),e=this._format(this.format,e),this.input.val(e).change(),this.input.focus())}),this.input_date[0].type==this._input&&(e=jQuery("<div/>",{class:"btn btn-default","aria-label":Sao.i18n.gettext("Open the calendar"),title:Sao.i18n.gettext("Open the calendar")}).prependTo(e),this.input_date.appendTo(e),Sao.common.ICONFACTORY.get_icon_img("tryton-date").appendTo(e)),new Mousetrap(this.el[0]));t.bind("enter",(e,t)=>{var i=this._parse(this.format,this.input.val()),i=this._format(this.format,i);this.input.val(i).change()}),t.bind("=",(e,t)=>{e.preventDefault(),this.input.val(this._format(this.format,moment())).change()}),Sao.common.DATE_OPERATORS.forEach(i=>{t.bind(i[0],(e,t)=>{e.preventDefault();e=this.get_value()||Sao.DateTime();e.add(i[1]),this.input.val(this._format(this.format,e)).change()})})},get_value:function(){return this._parse(this.format,this.input.val())},set_value:function(e){e=e instanceof Sao.DateTime||e instanceof Sao.Date?this._format(this.format,e):"",this.input.val(e)}}),Sao.View.Form.Dict.DateTime=Sao.class_(Sao.View.Form.Dict.Date,{class_:"dict-datetime",format:"%x %X",_input:"datetime-local",_input_format:"%Y-%m-%dT%H:%M:%S",_format:Sao.common.format_datetime,_parse:Sao.common.parse_datetime}),Sao.View.Form.PYSON=Sao.class_(Sao.View.Form.Char,{class_:"form-pyson",init:function(e,t){Sao.View.Form.PYSON._super.init.call(this,e,t),this.encoder=new Sao.PYSON.Encoder({}),this.decoder=new Sao.PYSON.Decoder({},!0),this.el.keyup(this.validate_pyson.bind(this)),this.icon=jQuery("<img/>",{class:"icon form-control-feedback"}).appendTo(this.group),this.group.addClass("has-feedback")},display:function(){Sao.View.Form.PYSON._super.display.call(this),this.validate_pyson()},get_encoded_value:function(){var e=this.input.val();if(!e)return e;try{return this.encoder.encode(eval_pyson(e))}catch(e){return null}},set_value:function(){var e=this.get_encoded_value(),t=this.record,i=this.field,n=i.get_client(t);e&&n&&Sao.common.compare(e,this.encoder.encode(this.decoder.decode(n)))&&(e=n),i.set_client(t,e)},get_client_value:function(){var e=Sao.View.Form.PYSON._super.get_client_value.call(this);return e=e&&Sao.PYSON.toString(this.decoder.decode(e))},validate_pyson:function(){var e="ok";null===this.get_encoded_value()&&(e="error"),Sao.common.ICONFACTORY.get_icon_url("tryton-"+e).then(e=>{this.icon.attr("src",e)})},focus_out:function(){this.validate_pyson(),Sao.View.Form.PYSON._super.focus_out.call(this)}}),Sao.View.FormXMLViewParser.WIDGETS={binary:Sao.View.Form.Binary,boolean:Sao.View.Form.Boolean,callto:Sao.View.Form.CallTo,char:Sao.View.Form.Char,date:Sao.View.Form.Date,datetime:Sao.View.Form.DateTime,dict:Sao.View.Form.Dict,document:Sao.View.Form.Document,email:Sao.View.Form.Email,float:Sao.View.Form.Float,html:Sao.View.Form.HTML,image:Sao.View.Form.Image,integer:Sao.View.Form.Integer,many2many:Sao.View.Form.Many2Many,many2one:Sao.View.Form.Many2One,multiselection:Sao.View.Form.MultiSelection,numeric:Sao.View.Form.Float,one2many:Sao.View.Form.One2Many,one2one:Sao.View.Form.One2One,password:Sao.View.Form.Password,progressbar:Sao.View.Form.ProgressBar,pyson:Sao.View.Form.PYSON,reference:Sao.View.Form.Reference,richtext:Sao.View.Form.RichText,selection:Sao.View.Form.Selection,sip:Sao.View.Form.SIP,text:Sao.View.Form.Text,time:Sao.View.Form.Time,timedelta:Sao.View.Form.TimeDelta,timestamp:Sao.View.Form.DateTime,url:Sao.View.Form.URL}}(),!function(){"use strict";var g;function v(e){var t,i,n,o="";e.parents(".form").length||e.parents("#menu").length||(t="100vh",e.parents(".modal-body").length&&(t=e.parents(".modal-body").css("max-height")),i=" ",e.parents(".panel-body").each(function(e,t){t=jQuery(t),i=(i+="- "+t.css("padding-top"))+" - "+t.css("padding-bottom")}),n=" ",e.parents(".panel").each(function(e,t){t=(t=jQuery(t)).css("box-shadow").match(/\d+px/g);t&&t.length&&(t=t.map(function(e){return e.replace("px","")}),n+="- "+Math.max.apply(null,t)+"px")}),o="calc("+t+" - "+e[0].getBoundingClientRect().y+"px"+i+n+")"),e.css("height",o)}function i(s,a,r){function l(){for(;d<s.length;d++){for(var e,t=s[d],i=t.record,n=0;n<t.tree.columns.length;n++){var o=t.tree.columns[n];if("field"==o.type){e=o.attributes.name;break}}if(e&&!i.is_loaded(e))return void i.load(e,!0,!1).done(l);t.redraw(a,r)}c.resolve()}var c=jQuery.Deferred(),d=0;return l(),c.promise()}"IntersectionObserver"in window&&(g=new IntersectionObserver(function(e,t){for(const i of e)i.isIntersecting&&jQuery(i.target).trigger("click")},{rootMargin:"0px 0px 50px 0px"})),jQuery(window).resize(function(){jQuery(".treeview").each(function(e,t){v(jQuery(t))})}),Sao.View.TreeXMLViewParser=Sao.class_(Sao.View.XMLViewParser,{_parse_tree:function(e,t){for(const i of e.childNodes)this.parse(i)},_parse_field:function(e,t){var i=t.name,n=new Sao.View.TreeXMLViewParser.WIDGETS[t.widget](this.view.screen.model,t);this.view.widgets[i]||(this.view.widgets[i]=[]),n.tree=this.view,this.view.widgets[i].push(n);"symbol"in t&&n.suffixes.push(new Sao.View.Tree.Symbol(t,1)),~["url","email","callto","sip"].indexOf(t.widget)&&n.prefixes.push(new Sao.View.Tree.Affix(t,t.widget)),"icon"in t&&n.prefixes.push(new Sao.View.Tree.Affix(t));for(const s of e.childNodes){var o={};for(const a of s.attributes)o[a.name]=a.value;o.name||(o.name=i);let e;(e="prefix"==s.tagName?n.prefixes:n.suffixes).push(new Sao.View.Tree.Affix(o))}"symbol"in t&&n.prefixes.push(new Sao.View.Tree.Symbol(t,0)),this.view.attributes.sequence||this.view.children_field||!1===this.field_attrs[i].sortable||(n.sortable=!0),this.view.columns.push(n),t.optional&&i!==this.exclude_field&&this.view.optionals.push(n),Boolean(parseInt(t.sum||"0",10))&&(e=jQuery("<label/>",{text:t.string}),t=jQuery("<div/>",{class:"value"}),this.view.sum_widgets.set(n,[e,t]))},_parse_button:function(e,t){t=new Sao.View.Tree.ButtonColumn(this.view,t);this.view.columns.push(t)}}),Sao.View.Tree=Sao.class_(Sao.View,{view_type:"tree",xml_parser:Sao.View.TreeXMLViewParser,draggable:!1,display_size:Sao.config.display_size,init:function(e,t,i,n){this.children_field=n,this.optionals=[],this.sum_widgets=new Map,this.columns=[],this.selection_mode=t.attributes.selection_mode||Sao.common.SELECTION_MULTIPLE,this.el=jQuery("<div/>").css("display","grid"),this.scrollbar=jQuery("<div/>").appendTo(jQuery("<div/>",{class:"scrollbar responsive"}).appendTo(this.el)),this.treeview=jQuery("<div/>",{class:"treeview responsive"}).appendTo(this.el),this.treeview.scroll(()=>{this.scrollbar.parent().scrollLeft(this.treeview.scrollLeft())}),this.scrollbar.parent().scroll(()=>{this.treeview.scrollLeft(this.scrollbar.parent().scrollLeft())}),this.expanded=new Set,Sao.View.Tree._super.init.call(this,e,t,i),this.rows=[],this.edited_row=null,this.table=jQuery("<table/>",{class:"tree table table-hover table-condensed"}),this.editable&&this.table.addClass("table-bordered"),this.treeview.append(this.table),this.colgroup=jQuery("<colgroup/>").appendTo(this.table);var o,s=jQuery("<col/>",{class:"selection-state"}).appendTo(this.colgroup),a=(this.selection_mode==Sao.common.SELECTION_NONE&&s.css("width",0),this.thead=jQuery("<thead/>").appendTo(this.table),jQuery("<tr/>")),r=jQuery("<th/>",{class:"selection-state"});this.selection=jQuery("<input/>",{type:"checkbox"}),this.selection.change(this.selection_changed.bind(this)),r.append(this.selection),a.append(r),this.thead.append(a),this.tfoot=null,this.sum_widgets.size&&((o=jQuery("<tr/>")).append(jQuery("<th/>")),this.tfoot=jQuery("<tfoot/>"),this.tfoot.append(o),this.table.prepend(this.tfoot)),this.children_field&&(this.expander=jQuery("<span/>",{class:"expander"}).append(jQuery("<img/>",{tabindex:0,class:"icon"})),this.update_expander("more"),this.expander.on("click keypress",Sao.common.click_press(this.unfold.bind(this))),Sao.common.ICONFACTORY.get_icon_url("tryton-unfold-"+this.expander.action).then(e=>{this.expander.children().attr("src",e)}));for(const h of this.columns){s=jQuery("<col/>",{class:h.attributes.widget}).appendTo(this.colgroup),(r=jQuery("<th/>",{class:h.attributes.widget})).uniqueId();var l,c,d=jQuery("<label/>").text(h.attributes.string).attr("title",h.attributes.string);this.editable&&(h.attributes.required&&d.addClass("required"),h.attributes.readonly||d.addClass("editable")),h.attributes.help&&d.attr("title",h.attributes.help),h.sortable&&(l=jQuery("<img/>",{class:"icon"}),d.append(l),h.arrow=l,r.click(h,this.sort_model.bind(this)),d.addClass("sortable")),a.append(r.append(d)),h.header=r,h.col=s,h.footers=[],this.sum_widgets.size&&(h.attributes.name,l=jQuery("<th/>",{class:h.class_}),this.sum_widgets.has(h)&&(d=this.sum_widgets.get(h)[0],c=this.sum_widgets.get(h)[1],l.append(d),l.append(c)),o.append(l),h.footers.push(l))}this.tbody=jQuery("<tbody/>"),this.table.append(this.tbody),this.colgroup.prepend(jQuery("<col/>",{class:"tree-menu"})),this.thead.children().prepend(jQuery("<th/>",{class:"tree-menu"})),this.tfoot&&this.tfoot.children().prepend(jQuery("<th/>")),this.set_drag_and_drop(),r=this.thead.find("th").first(),this.optionals.length&&r.addClass("optional");n=jQuery("<ul/>",{class:"dropdown-menu"}).click(function(e){e.stopImmediatePropagation()}),e=jQuery("<div/>",{class:"dropdown"}).append(jQuery("<a/>",{"data-toggle":"dropdown","aria-haspopup":!0,"aria-expanded":!1,title:Sao.i18n.gettext("Menu")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-menu")).click(n,this.tree_menu.bind(this))).append(n);e.on("hide.bs.dropdown",()=>{this.save_optional(!0),Sao.common.set_overflow(r,"hide")}),e.on("show.bs.dropdown",()=>{Sao.common.set_overflow(r,"show")}),r.append(e)},tree_menu:function(e){var t=e=>{e.data.set_visible(jQuery(e.delegateTarget).prop("checked")),this.save_optional(),this.display();for(const t of this.rows)t.update_visible()},i=e.data;i.empty();for(const n of this.optionals)i.append(jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem"}).append(jQuery("<label/>",{class:"checkbox"}).append(jQuery("<input/>",{type:"checkbox",checked:n.get_visible()}).change(n,t)).append(" "+n.attributes.string))));this.optionals.length&&i.append(jQuery("<li/>",{role:"separator",class:"divider hidden-xs"})),i.append(jQuery("<li/>",{role:"presentation",class:this.selected_records.length||!navigator.clipboard?"":"disabled"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(" "+Sao.i18n.gettext("Copy")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-copy",{"aria-hidden":"true"})).click(e=>{e.preventDefault(),this.on_copy(),i.dropdown("toggle")})))},save_optional:function(e=!0){if(this.optionals.length){var t={};for(const i of this.optionals)t[i.attributes.name]=!i.get_visible();e&&new Sao.Model("ir.ui.view_tree_optional").execute("set_optional",[this.view_id,t],{}),Sao.Screen.tree_column_optional[this.view_id]=t}},reset:function(){this.display_size=Sao.config.display_size},get editable(){return parseInt(this.attributes.editable||0,10)&&!this.screen.attributes.readonly},get creatable(){return!!this.editable&&(!this.attributes.creatable||Boolean(parseInt(this.attributes.creatable,10)))},unfold:function(){var t,e;this.expander&&(e="more"==this.expander.action?(t=function(e){e.is_selected()&&!e.is_expanded()&&e.expand_row(),e.rows.forEach(t)},"less"):(t=function(e){e.is_selected()&&e.is_expanded()&&e.collapse_row(),e.rows.forEach(t)},"more"),this.rows.forEach(t),this.update_expander(e))},update_expander:function(e){this.expander&&(e&&(this.expander.action=e),Sao.common.ICONFACTORY.get_icon_url("tryton-unfold-"+this.expander.action).then(e=>{this.expander.children().attr("src",e)}),jQuery.isEmptyObject(this.selected_records)?this.expander.css("visibility","hidden"):this.expander.css("visibility","visible"))},sort_model:function(e){var t=e.data,i=t.arrow;for(const o of this.columns)o.arrow&&o!=t&&o.arrow.attr("src")&&o.arrow.attr("src","");this.screen.order=this.screen.default_order,"ASC"==i.data("order")?(i.data("order","DESC"),Sao.common.ICONFACTORY.get_icon_url("tryton-arrow-up").then(function(e){i.attr("src",e)}),this.screen.order=[[t.attributes.name,"DESC"]]):"DESC"==i.data("order")?(i.data("order",""),i.attr("src","")):(i.data("order","ASC"),Sao.common.ICONFACTORY.get_icon_url("tryton-arrow-down").then(function(e){i.attr("src",e)}),this.screen.order=[[t.attributes.name,"ASC"]]);var n=[];for(const s of this.group)s.id<0&&(n=s.group);e=this.screen.screen_container.get_text();!jQuery.isEmptyObject(n)||this.screen.search_count==this.group.length||this.group.parent?this.screen.search_filter(e,!0).then(i=>{this.group.sort(function(e,t){return(e=(e=i.indexOf(e.id))<0?i.length:e)<(t=(t=i.indexOf(t.id))<0?i.length:t)?-1:t<e?1:0}),this.screen.display()}):this.screen.search_filter(e)},update_arrow:function(){var e=this.screen.order,i=null,n=null,o="";e&&1==e.length&&(i=e[0][0],n=e[0][1])&&(n=n.trim().split(" ",1)[0],o={ASC:"tryton-arrow-down",DESC:"tryton-arrow-up"}[n]),this.columns.forEach(function(e){var t=e.arrow;t&&(e.attributes.name!=i?(t.data("order",""),t.attr("src","")):(t.data("order",n),Sao.common.ICONFACTORY.get_icon_url(o).then(function(e){t.attr("src",e)})))})},on_copy:function(){var e=[];this.selected_records.forEach(i=>{var n=[];this.columns.forEach(e=>{if(e.get_visible()&&e.attributes.name&&!(e instanceof Sao.View.Tree.ButtonColumn)){var t;if(i.is_loaded(e.attributes.name))t=e.get_textual_value(i);else try{i.load(e.attributes.name,!1,!1),t=e.get_textual_value(i)}catch(e){Sao.Logger.error("Error loading "+this.attributes.name+" for "+i),t=Sao.i18n.gettext("#ERROR")}n.push('"'+String(t).replace('"','""')+'"')}}),e.push(n.join("\t"))}),navigator.clipboard.writeText(e.join("\n"))},_add_drag_n_drop:function(){Sortable.create(this.tbody[0],{handle:".draggable-handle",ghostClass:"dragged-row"}),this.tbody.on("dragstart",this.drag_data_get.bind(this)),this.tbody.on("drop",this.drag_data_received.bind(this))},set_drag_and_drop:function(){var e,t=!1;this.children_field?(e=this.screen.model.fields[this.children_field])&&(e=e.description.relation_field,t=Boolean(this.widgets[e])):this.attributes.sequence&&(t=!0),this.screen.readonly&&(t=!1),(this.draggable=t)&&(this.thead.find("th").first().addClass("draggable-handle"),this._add_drag_n_drop())},drag_data_get:function(t){function i(e){e.el[0]===t.target&&(t.originalEvent.dataTransfer.setData("path",e.path),t.originalEvent.dataTransfer.setData("position",n)),0===e.rows.length&&o.push(e),n+=1,e.rows.forEach(i.bind(this))}var n=0,o=[];this.rows.forEach(i.bind(this))},drag_data_received:function(e){var t=e.originalEvent.dataTransfer,i=t.getData("path").split(".");if(0!==i.length){for(var r=this;0<i.length;)r=r.rows[i[0]],i=i.slice(1);for(var n,l,o,s,c,d,h=r.record,u=null,a=(l=(e.ctrlKey||e.metaKey)&&this.children_field?((u=this._find_row(r.el.prev()))||this).rows.length:e.shiftKey?(n=this._find_row(r.el.prev()))?((u=n.parent_)||this).rows.indexOf(n)+1:(u=null,0):(n=this._find_row(r.el.next()))?((u=n.parent_)||this).rows.indexOf(n):(u=null,this.rows.length),u);a&&a!=r;)a=a.parent_;a?(e=t.getData("position"),jQuery(this.tbody.children()[e]).before(r.el)):(s=function(e){o.el.after(e.el),(o=e).rows.forEach(s)},(o=r).rows.forEach(s),c=h.group,d=r.group_position,(u?u.record.children_group(this.children_field):jQuery.Deferred().resolve(this.group)).then(e=>{var t=(r.parent_||this).rows,i=(u||this).rows;c===e?(d<l&&--l,c.splice(d,1),c.splice(l,0,h),c.record_modified()):(c.remove(h,!0,!0),c.record_removed.splice(c.record_removed.indexOf(h)),e.add(h,l),h.parent_name?h.modified_fields[c.parent_name]=!0:(h.modified_fields[c.parent_name]=!0,h._values[c.parent_name]=null)),i.splice(l,0,r),t.splice(d,1),r.parent_=u,r.record.group=e;for(const s of i.slice(l))s.reset_path();for(const a of t.slice(d))a.reset_path();function n(e){e.redraw(o),e.rows.forEach(n)}var o=this.get_selected_paths();r.redraw(o);r.rows.forEach(n),this.attributes.sequence&&r.record.group.set_sequence(this.attributes.sequence,this.screen.new_position)}))}},get_fields:function(){return Object.keys(this.widgets)},get_buttons:function(){var e=[];for(const t of this.columns)t instanceof Sao.View.Tree.ButtonColumn&&e.push(t);return e},display:function(e,a){v(this.treeview);this.tbody;var t=this.record;if(jQuery.isEmptyObject(e)&&t)if(e=this.get_selected_paths(),this.selection.prop("checked")&&!this.selection.prop("indeterminate"))for(const p of this.screen.group.slice(this.rows.length,this.display_size))e.push([p.id]);else{t=(t=t.get_path(this.group)).map(function(e){return e[1]});Sao.common.contains(e,t)||(e=[t])}a=a||this.get_expanded_paths(),this.selection_mode==Sao.common.SELECTION_MULTIPLE?this.selection.show():this.selection.hide();const r=(e,t)=>{var i=[];for(const s of e){i.push(s);var n,o=t.concat([s.id]);Sao.common.contains(a,o)&&(n=s.field_get_client(this.children_field),Array.prototype.push.apply(i,r(n,o)))}return i},n=e=>{var t=[];for(const i of e)t.push(i.record),i.is_expanded()&&Array.prototype.push.apply(t,n(i.rows));return t};var t=Math.min(this.group.length,this.display_size),o=(this.children_field?Sao.common.compare(r(this.group.slice(0,t),[]),n(this.rows))||this.construct():t>this.rows.length&&Sao.common.compare(this.group.slice(0,this.rows.length),n(this.rows))?this.construct(!0):t==this.rows.length&&Sao.common.compare(this.group.slice(0,this.rows.length),n(this.rows))||this.construct(),2),i=[],t=(jQuery.isEmptyObject(this.screen.domain)||i.push(this.screen.domain),this.screen.screen_container.get_tab_domain()),s=(jQuery.isEmptyObject(t)||i.push(t),new Sao.common.DomainInversion),i=s.simplify(i),l=new Sao.PYSON.Decoder(this.screen.context),c=[],d=Sao.Screen.tree_column_optional[this.view_id]||{};for(const f of this.columns){o+=1;var h=f.attributes.name;if(!h)return;var u,_,m=d.hasOwnProperty(h)?d[h]:Boolean(parseInt(f.attributes.optional||"0",10));l.decode(f.attributes.tree_invisible||"0")||m||h===this.screen.exclude_field?(--o,f.set_visible(!1)):h in this.screen.model.fields&&(m=this.screen.model.fields[h],"boolean"!=typeof(h=s.domain_inversion(i,h))&&(h=s.simplify(h)),s.unique_value(h,m._single_value)[0]&&jQuery.isEmptyObject(this.children_field)?(--o,f.set_visible(!1)):f.set_visible(!0)),f.get_visible()?f.col.hasClass("draggable-handle")||f.col.hasClass("optional")||f.col.hasClass("selection-state")||f.col.hasClass("favorite")||(f.attributes.width?(u=_=f.attributes.width,c.push(u+"px")):(u={integer:8,selection:9,reference:20,one2many:5,many2many:5,boolean:3,binary:20}[f.attributes.widget]||10,f.attributes.symbol&&(u+=2),h=1,f.attributes.expand&&(h+=parseInt(f.attributes.expand,10)),_=100*u*h+"%",c.push(u+"em")),f.col.css("width",_),f.col.show()):(f.col.css("width",0),f.col.hide())}return this.children_field&&this.columns.every(e=>!(!e.col.hasClass("draggable-handle")&&!e.header.hasClass("invisible")&&(this.expander.parent()[0]!==e.header[0]&&e.header.prepend(this.expander),1))),this.table.css("min-width","calc("+c.join(" + ")+")"),this.scrollbar.css("min-width",this.table.css("min-width")),!this.table.hasClass("no-responsive")&1<this.columns.filter(function(e){return e.get_visible()}).length?(this.table.addClass("responsive"),this.table.addClass("responsive-header")):(this.table.removeClass("responsive"),this.table.removeClass("responsive-header")),this.update_arrow(),this.redraw(e,a).then(()=>{var e,t,i=this.table.children("tbody");i.length?i!==this.tbody&&i.replaceWith(this.tbody):this.table.append(this.tbody),this.tbody.append(this.rows.filter(function(e){return!e.el.parent().length}).map(function(e){return e.el})),this.update_selection(),this.display_size<this.group.length&&!this.tbody.children().last().hasClass("more-row")&&(i=jQuery("<tr/>",{class:"more-row"}),e=jQuery("<td/>",{colspan:o}),t=jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("More")}).text(Sao.i18n.gettext("More")).click(()=>{var e=this.table.height();this.display_size+=Sao.config.display_size,this.display(),e=e-this.treeview.height()-50,this.tfoot&&(e-=this.tfoot.height()),this.treeview[0].scroll({top:e})}),e.append(t),i.append(e),this.tbody.append(i),g)&&g.observe(t[0])}).done(Sao.common.debounce(this.update_sum.bind(this),250))},construct:function(e){e?this.tbody.find("tr.more-row").remove():(this.rows=[],this.tbody=jQuery("<tbody/>"),this.draggable&&this._add_drag_n_drop(),this.edited_row=null);for(const i of this.group.slice(this.rows.length,this.display_size)){var t=this.editable?Sao.View.Tree.RowEditable:Sao.View.Tree.Row;this.rows.push(new t(this,i,this.rows.length))}},redraw:function(e,t){return i(this.rows,e,t)},switch_:function(e){this.screen.row_activate()},select_changed:function(e){this.edited_row&&(e=this.edited_row.record,this.edited_row.set_selection(!0)),this.record=e},update_sum:function(){for(var[e,t]of this.sum_widgets){for(var i,n,o=e.attributes.name,s=this.selected_records,e="-",a=t[0],t=t[1],r=null,l=null,c=!0,d=0,h=this.screen.model.fields[o],u=s.map(function(e){return e.id}),_=0;_<this.group.length;_++){if(!(i=this.group[_]).get_loaded([o])&&0<=i.id){c=!1;break}var m=h.get(i);null!==(m=m&&m.isTimeDelta?m.asSeconds():m)&&(null===r?r=m:r+=m,!~u.indexOf(i.id)&&s||(null===l?l=m:l+=m),h.digits)&&(d=(m=h.digits(i))&&null!==d?Math.max(m[1],d):null)}c&&(r="timedelta"==h.description.type?(n=h.converter(this.group),l=Sao.common.timedelta.format(Sao.TimeDelta(null,l),n),Sao.common.timedelta.format(Sao.TimeDelta(null,r),n)):null!==d?((n={}).minimumFractionDigits=d,n.maximumFractionDigits=d,l=(l||0).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),n),(r||0).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),n)):(l=(l||0).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang())),(r||0).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()))),e=l+"\n"+r),t.text(e),t.parent().attr("title",a.text()+"\n"+t.text())}},get selected_records(){if(this.selection_mode==Sao.common.SELECTION_NONE)return[];function t(e){e.is_selected()&&i.push(e.record),e.rows.forEach(t)}var i=[];if(this.rows.forEach(t),this.selection.prop("checked")&&!this.selection.prop("indeterminate"))for(const e of this.group.slice(this.rows.length))i.push(e);return i},get listed_records(){if(!this.children_field)return this.group.slice();const l=e=>{for(var t=[],i=((a=this.find_row(e))||this).rows,n=0,o=this.n_children(a);n<o;n++){var s,a,r=e.concat([n]);(a=i[n])&&(s=a.record,t.push(s),a.is_expanded())&&(t=t.concat(l(r)))}return t};return l([]).concat(this.group.slice(this.rows.length))},get_listed_paths:function(){if(!this.children_field)return this.group.map(function(e){return[e.id]});const c=(e,t)=>{for(var i=[],n=((r=this.find_row(e))||this).rows,o=0,s=this.n_children(r);o<s;o++){var a,r,l=e.concat([o]);(r=n[o])&&(a=r.record,a=t.concat([a.id]),i.push(a),r.is_expanded())&&(i=i.concat(c(l,a)))}return i};return c([],[]).concat(this.group.slice(this.rows.length).map(function(e){return[e.id]}))},select_records:function(i,n){if((i=!i&&n?this.rows[0].record:i)&&n){for(var e,t=i.get_index_path(this.screen.group),o=n.get_index_path(this.screen.group),s=Math.min(t.length,o.length),a=0;a<s;a++)if(t[a]>o[a]){e=i,i=n,n=e;break}!e&&t.length>o.length&&(e=i,i=n,n=e)}var r=this.rows[0].record===i,l=function(e){var t=e.record;t===i&&(r=!0),e.set_selection(r),t===n&&(r=!1),e.rows.forEach(l)};this.rows.forEach(l)},selection_changed:function(){var t=this.selection.prop("checked"),i=function(e){e.set_selection(t),e.rows.forEach(i)};this.rows.forEach(i),t&&this.rows[0]?this.select_changed(this.rows[0].record):this.select_changed(null),this.update_expander(t?"more":null),this.update_sum()},update_selection:function(){this.update_sum();var e=this.selected_records;this.selection.prop("indeterminate",!1),jQuery.isEmptyObject(e)?this.selection.prop("checked",!1):(this.rows.every(e=>e.is_selected())&&e.length>=this.tbody.children().length||this.selection.prop("indeterminate",!0),this.selection.prop("checked",!0)),this.update_expander()},get_selected_paths:function(){var r=[];return function e(t,i){for(var n,o,s=0,a=t.rows.length;s<a;s++)n=t.rows[s],o=i.concat([n.record.id]),n.is_selected()&&r.push(o),e(n,o)}(this,[]),r},get_expanded_paths:function(e=[],t=[]){for(var i,n,o=[],s=this.find_row(e),a=(s||this).rows,r=0,l=this.n_children(s);r<l;r++)n=e.concat([r]),(s=a[r])&&s.is_expanded()&&(i=t.concat(s.record.id),o.push(i),o=o.concat(this.get_expanded_paths(n,i)));return o},find_row:function(e){for(var t,i=null,n=this.rows,o=0,s=e.length;o<s;o++){if(t=e[o],!n||t>=n.length)return null;if(n=(i=n[t]).rows,!this.children_field)break}return i},n_children:function(e){return e&&this.children_field?e.record.is_loaded(this.children_field)?e.record.field_get_client(this.children_field).length:0:this.rows.length},set_cursor:function(t,e){var i,n,o,s,a;this.record&&(i=this.record.get_index_path(this.group),this.rows.length<=i[0]&&(this.display_size=this.group.length,this.display()),a=()=>{var e;(o=this.find_row(i))&&null!==(n=o.next_column(null,t))&&(o=o._get_column_td(n),this.editable&&t&&o.trigger("click"),e=Sao.common.find_focusable_child(o))&&e.focus()},(s=1<i.length?this.rows[i[0]].expand_to_path(i.slice(1),[this.record.get_path(this.group).map(function(e){return e[1]})]):s)?s.then(a):a())},save_row:function(){var e,t=this.edited_row;if(!this.editable||!this.edited_row)return jQuery.when();if(this.edited_row.record.validate(this.get_fields(),!1,!1,!0))return(e=this.group.parent?this.screen.attributes.pre_validate?this.record.pre_validate():jQuery.when():this.edited_row.record.save()).fail(()=>{this.edited_row!=t&&(this.edit_row(null),t.set_selection(!0),t.selection_changed(),this.edit_row(t))}),e;for(var i=!1,n=this.edited_row.record.invalid_fields(),o=0;o<this.columns.length;o++){var s,a=this.columns[o];a.attributes.name in n&&(s=this.edited_row._get_column_td(o),(s=this.edited_row.get_editable_el(s).data("widget")).display(this.edited_row.record,a.field),i||(s.focus(),i=!0))}},edit_row:function(e){this.editable&&this.edited_row!=e&&(this.edited_row&&this.edited_row.unset_editable(),e&&e.set_editable(),this.edited_row=e)},_find_row:function(t){function i(e){e.el[0]==t[0]?n=e:e.rows.forEach(i)}var n=null;return this.rows.forEach(i),n}}),Sao.View.Tree.Row=Sao.class_(Object,{init:function(e,t,i,n){this.tree=e,this.current_column=null,this.rows=[],this.record=t,this.parent_=n,this.children_field=e.children_field,this.expander=null,this._group_position=null,this._path=null,this._drawed_record=null,this.el=jQuery("<tr/>"),this.el.on("click",this.select_row.bind(this)),this._construct()},get group_position(){return null===this._group_position&&(this._group_position=this.record.group.indexOf(this.record)),this._group_position},get path(){var e;return this._path||((e=this.parent_?jQuery.extend([],this.parent_.path.split(".")):[]).push(this.group_position),this._path=e.join(".")),this._path},reset_path:function(){this._group_position=null,this._path=null;for(const e of this.rows)e.reset_path()},is_expanded:function(){return this.tree.expanded.has(this)},get_id_path:function(){return this.parent_?this.parent_.get_id_path().concat([this.record.id]):[this.record.id]},_construct:function(){this.tree.el.uniqueId(),i=jQuery("<td/>"),this.tree.draggable&&(i.addClass("draggable-handle"),i.append(Sao.common.ICONFACTORY.get_icon_img("tryton-drag"))),this.tree.optionals.length&&i.addClass("optional"),this.el.append(i),i=jQuery("<td/>",{class:"selection-state"}).click(e=>{e.stopPropagation(),this.selection.click()}),this.el.append(i),this.selection=jQuery("<input/>",{type:"checkbox",name:"tree-selection-"+this.tree.el.attr("id")}),this.selection.click(function(e){e.stopPropagation()}),this.selection.change(this.selection_changed.bind(this)),i.append(this.selection);var e=e=>{this.expander&&!this.is_expanded()&&this.tree.n_children(this)<=Sao.config.limit&&this.toggle_row(),this.select_column(e.data.index)};this.children_field&&(this.expander=jQuery("<span/>",{class:"expander"}).append("<img/>",{tabindex:0,class:"icon"}),this.expander.children().html(" "),this.expander.on("click keypress",Sao.common.click_press(this.toggle_row.bind(this))),this.expander.dblclick(e=>{e.preventDefault(),e.stopImmediatePropagation()}));for(var t=0;t<this.tree.columns.length;t++){var i,n,o=this.tree.columns[t],s=((i=o instanceof Sao.View.Tree.ButtonColumn?jQuery("<td>"):jQuery("<td/>",{"data-title":o.attributes.string+Sao.i18n.gettext(": ")}).append(jQuery("<span/>",{"aria-hidden":!0}))).attr("headers",o.header.attr("id")),i.on("click keypress",{index:t},e),this.tree.editable?(o.attributes.required&&i.addClass("required"),o.attributes.readonly||i.addClass("editable")):i.dblclick(this.switch_row.bind(this)),jQuery("<div>",{class:"cell"}));if(i.append(s),o.prefixes)for(n=0;n<o.prefixes.length;n++){o.prefixes[n];s.append(jQuery("<span/>",{class:"prefix"}))}if(s.append(jQuery("<span/>",{class:"widget"})),o.suffixes)for(n=0;n<o.suffixes.length;n++){o.suffixes[n];s.append(jQuery("<span/>",{class:"suffix"}))}this.el.append(i)}},_get_column_td:function(e,t){return t=t||this.el,jQuery(t.children()[e+2])},redraw:function(t,i){switch(t=t||[],i=i||[],this.tree.selection_mode){case Sao.common.SELECTION_NONE:this.selection.hide();break;case Sao.common.SELECTION_SINGLE:this.selection.attr("type","radio"),this.selection.show();break;case Sao.common.SELECTION_MULTIPLE:this.selection.attr("type","checkbox"),this.selection.show()}function n(e,t){for(const n of["muted","success","warning","danger"]){var i="muted"==n?"text-muted":n;n==t?e.addClass(i):e.removeClass(i)}}if(this._drawed_record!==this.record.identity){for(var o=0;o<this.tree.columns.length;o++){var s=this.tree.columns[o],a=this._get_column_td(o),r=a.find(".cell");if(s.prefixes)for(var l=0;l<s.prefixes.length;l++){var c,d=s.prefixes[l],h=jQuery(r.children(".prefix")[l]);(c=h.children()).length?d.render(this.record,c):h.empty().append(d.render(this.record))}var u=r.children(".widget");if((c=u.children()).length?s.render(this.record,c):u.empty().append(s.render(this.record)),s.suffixes)for(var _=0;_<s.suffixes.length;_++){var m=s.suffixes[_],p=jQuery(r.children(".suffix")[_]);(c=p.children()).length?m.render(this.record,c):p.empty().append(m.render(this.record))}let e=this.record.expr_eval(s.attributes.visual);n(a,e=this.record.deleted||this.record.removed?"muted":e)}this.update_visible()}this.children_field&&this.tree.columns.every((e,t)=>{return!(!e.col.hasClass("draggable-handle")&&!e.header.hasClass("invisible")&&(e=this._get_column_td(t).find(".cell"),this.expander.parent()[0]!==e[0]&&e.prepend(this.expander),1))}),this._drawed_record=this.record.identity;var e,f,g=this.get_id_path();this.set_selection(Sao.common.contains(t,g)),this.children_field&&(e=this.path.split(".").length,f="margin-left",Sao.i18n.rtl&&(f="margin-right"),this.expander.children().css(f,e-1+"em"),f=()=>{var e=this.record.field_get_client(this.children_field).length;e&&(this.is_expanded()||Sao.common.contains(i,g))?(this.expander.css("visibility","visible"),this.tree.expanded.add(this),this.expand_children(t,i),this.update_expander(!0)):(this.expander.css("visibility",e?"visible":"hidden"),this.update_expander(!1))},this.record.is_loaded(this.children_field)?f():this.record.load(this.children_field,!0,!1).done(f));let v=this.record.expr_eval(this.tree.attributes.visual);this.record.deleted||this.record.removed?(this.record.deleted&&this.el.css("text-decoration","line-through"),v="muted"):this.el.css("text-decoration","inherit"),n(this.el,v)},update_visible:function(){for(var e=this.tree.thead.is(":visible"),t=0;t<this.tree.columns.length;t++){var i=this.tree.columns[t],n=this._get_column_td(t);i.header.is(":hidden")&&e||"none"==i.header.css("display")?(n.hide(),n.addClass("invisible")):(n.show(),n.removeClass("invisible"))}},toggle_row:function(){return this.is_expanded()?this.collapse_row():this.expand_row(),!1},expand_row:function(){this.tree.n_children(this)>Sao.config.limit?(this.tree.record=this.record,this.tree.screen.switch_view("form")):(this.update_expander(!0),this.tree.expanded.add(this),this.expand_children())},collapse_row:function(){for(const e of this.rows)e.exception&&e.record.cancel();this.update_expander(!1),this.tree.expanded.delete(this),this.collapse_children()},update_expander:function(e){e=e?"tryton-arrow-down":"tryton-arrow-right";Sao.common.ICONFACTORY.get_icon_url(e).then(e=>{this.expander.children().attr("src",e)})},collapse_children:function(){for(const e of this.rows)e.collapse_children(),e.el.remove();this.rows=[]},expand_children:function(e,t){return this.record.load(this.children_field,!0,!1).done(()=>{0===this.rows.length&&this.record.field_get_client(this.children_field).forEach((e,t,i)=>{this.rows.push(new this.Class(this.tree,e,t,this))}),i(this.rows,e,t).then(()=>{this.el.after(this.rows.filter(function(e){return!e.el.parent().length}).map(function(e){return e.el})),this.tree.update_selection()})})},switch_row:function(){window.getSelection?window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges():document.selection&&document.selection.empty(),this.tree.selection_mode!=Sao.common.SELECTION_NONE&&(this.set_selection(!0),this.selection_changed(),!this.is_selected())||this.tree.switch_(this.path)},select_column:function(e){},select_row:function(e){var t;this.tree.selection_mode==Sao.common.SELECTION_NONE?(this.tree.select_changed(this.record),this.switch_row()):(e.shiftKey&&this.tree.selection_mode!=Sao.common.SELECTION_SINGLE?(t=this.tree.screen.current_record,this.tree.select_records(t,this.record)):((e.ctrlKey||e.metaKey)&&this.tree.selection_mode!=Sao.common.SELECTION_SINGLE||this.tree.select_records(null,null),this.set_selection(!this.is_selected())),this.selection_changed(),t&&(this.tree.screen.current_record=t))},is_selected:function(){return this.tree.selection_mode!=Sao.common.SELECTION_NONE&&this.selection.prop("checked")},set_selection:function(e){this.tree.selection_mode==Sao.common.SELECTION_NONE||(this.selection.prop("checked",e),e?this.el.addClass("selected"):this.el.removeClass("selected"),e)||this.tree.selection.prop("checked",!1)},selection_changed:function(){var e=this.is_selected();this.set_selection(e),e?(this.tree.select_changed(this.record),this.expander&&(this.is_expanded()?this.tree.update_expander("less"):"visible"==this.expander.css("visibility")&&this.tree.update_expander("more"))):this.tree.select_changed(this.tree.selected_records[0]||null),this.tree.update_selection()},expand_to_path:function(e,t){if(e.length&&this.record.field_get_client(this.children_field).length)return this.expander.css("visibility","visible"),this.tree.expanded.add(this),this.update_expander(!0),this.expand_children(t).done(()=>this.rows[e[0]].expand_to_path(e.slice(1),t))},next_column:function(e,t,i){var n,o;for(i=i||1,null===e&&0<i?e=-1:null===e&&(e=0),n=o=0;n<this.tree.columns.length;n++)if((o=(e+i*(n+1))%this.tree.columns.length)<0&&(o+=this.tree.columns.length),(a=this.tree.columns[o]).field){var s,a,r,l=(r=a.field.get_state_attrs(this.record)).invisible;if(a.header.is(":hidden")&&(l=!0),a=!!t&&(s=Sao.View.EditableTree.WIDGETS[a.attributes.widget],a.attributes.readonly||r.readonly||!s),!l&&!a)return o}}}),Sao.View.Tree.RowEditable=Sao.class_(Sao.View.Tree.Row,{init:function(e,t,i,n){Sao.View.Tree.RowEditable._super.init.call(this,e,t,i,n),this.edited_column=null,this.el.on("keypress",e=>{e.which==Sao.common.RETURN_KEYCODE&&this.tree.edited_row!=this&&(e.preventDefault(),this.tree.edit_row(this))})},redraw:function(e,t){Sao.View.Tree.RowEditable._super.redraw.call(this,e,t);for(var i=t=>{var i=this.record;return function(){var e=i.model.fields[t.field_name];e.set_state(i),t.display(i,e)}},n=0;n<this.tree.columns.length;n++){var o=this.tree.columns[n],s=this._get_column_td(n).children(".cell");(s=jQuery(s.children(".widget-editable")).data("widget"))&&(s=i(s),this.record.is_loaded(o.attributes.name)?s():this.record.load(o.attributes.name,!0,!1).done(s))}},select_column:function(e){this.edited_column=e},select_row:function(e){var t,i,n;e.stopPropagation(),this.tree.edited_row&&e.currentTarget==this.tree.edited_row.el[0]||(i=this.tree.screen.current_record,this.record!=i&&i&&!i.validate(this.tree.get_fields(),!1,!1,!0))||((t=i=jQuery(document.body)).hasClass("modal-open")&&(i=this.tree.el.parents(".modal").last()),(n=e=>{if(e.currentTarget!=t[0]||!t.hasClass("modal-open")){if(this.tree.save_row())return t.off("click.sao.editabletree"),this.tree.edit_row(null),!0;e.preventDefault(),e.stopPropagation()}})(e)&&(i.on("click.sao.editabletree",n),Sao.View.Tree.RowEditable._super.select_row.call(this,e),e.shiftKey||e.ctrlKey||e.metaKey||this.tree.edit_row(this)))},unset_editable:function(){this.tree.columns.forEach((e,t)=>{t=this._get_column_td(t);this.get_static_el(t).empty().append(e.render(this.record)).show(),this.get_editable_el(t).empty().data("widget",null).hide().parents(".treeview td").addBack().removeClass("edited")})},set_editable:function(){for(var e=null,t=0,i=this.tree.columns.length;t<i;t++){var n,o,s=this._get_column_td(t),a=this.tree.columns[t];a.field&&(n=Sao.View.EditableTree.WIDGETS[a.attributes.widget],!a.attributes.readonly)&&n&&((n=new n(this.tree,a.attributes)).el.on("keydown",this.key_press.bind(this)),(o=this.get_editable_el(s)).append(n.el),o.data("widget",n),n.display(this.record,a.field),this.get_static_el(s).hide(),o.show(),o.parents(".treeview td").addBack().addClass("edited"),this.edited_column==t)&&(e=n)}e&&e.focus()},get_static_el:function(e){return(e=e||this.get_active_td()).find(".widget")},get_editable_el:function(e){var t=(e=e||this.get_active_td()).find(".widget-editable");return t=t.length?t:jQuery("<span/>",{class:"widget-editable"}).insertAfter(e.find(".widget"))},get_active_td:function(){return this._get_column_td(this.edited_column)},key_press:function(s){var a,r,e,t,l,i,n;s.which!=Sao.common.TAB_KEYCODE&&s.which!=Sao.common.UP_KEYCODE&&s.which!=Sao.common.DOWN_KEYCODE&&s.which!=Sao.common.ESC_KEYCODE&&s.which!=Sao.common.RETURN_KEYCODE||jQuery(s.currentTarget).find(".dropdown-menu:visible").length||(s.preventDefault(),e=this._get_column_td(this.edited_column),t=this.get_editable_el(e),(l=t.data("widget")).focus_out(),(i=this.tree.columns[this.edited_column]).field.validate(this.record)?s.which==Sao.common.TAB_KEYCODE?(n=1,s.shiftKey&&(n=-1),null!==(n=this.next_column(this.edited_column,!0,n))&&(this.edited_column=n,e=this._get_column_td(n),t=this.get_editable_el(e),(l=t.data("widget")).focus())):s.which==Sao.common.UP_KEYCODE||s.which==Sao.common.DOWN_KEYCODE||s.which==Sao.common.RETURN_KEYCODE?(a=this.edited_column,this.record.validate(this.tree.get_fields()).then(e=>{if(e){var t,i,n,e=jQuery.when();this.tree.screen.group.parent?this.tree.screen.attributes.pre_validate&&(e=this.record.pre_validate()):e=this.record.save(),e.fail(function(){l.focus()}),!(t=s.which!=Sao.common.UP_KEYCODE&&(s.which==Sao.common.DOWN_KEYCODE||-1==this.tree.screen.new_position)?this.el.next("tr"):this.el.prev("tr")).length&&(s.which==Sao.common.RETURN_KEYCODE||s.which==Sao.common.UP_KEYCODE&&0==this.tree.screen.new_position||s.which==Sao.common.DOWN_KEYCODE&&-1==this.tree.screen.new_position)?(n=this.tree.screen.group,i=Sao.common.MODELACCESS.get(this.tree.screen.model_name),n=null!==this.tree.screen.size_limit&&n.length>=this.tree.screen.size_limit,this.tree.creatable&&i.create&&!n&&e.then(()=>this.tree.screen.new_()).then(e=>{var t=this.tree.attributes.sequence;t&&e.group.set_sequence(t,this.tree.screen.new_position)})):e.then(()=>{this._get_column_td(a,t).trigger("click").find(":input,[tabindex=0]").focus()})}else{var o=this.record.invalid_fields();for(r=0;r<this.tree.columns.length;r++)if(this.tree.columns[r].attributes.name in o){a=r;break}this._get_column_td(a).find(":input,[tabindex=0]").focus()}})):s.which==Sao.common.ESC_KEYCODE&&(this.tree.edit_row(null),this.get_static_el().show().find("[tabindex=0]").focus()):l.display(this.record,i.field))}}),Sao.View.Tree.Affix=Sao.class_(Object,{init:function(e,t){this.attributes=e,this.protocol=t||null,this.icon=e.icon,this.protocol&&!this.icon&&(this.icon="tryton-public")},get_cell:function(){var e;return this.protocol?((e=jQuery("<a/>",{target:"_blank",rel:"noreferrer noopener"})).append(jQuery("<img/>")),e.click({cell:e},this.clicked.bind(this))):this.icon?e=jQuery("<img/>"):(e=jQuery("<span/>")).attr("tabindex",0),e.addClass("column-affix"),e},render:function(o,s){s=s||this.get_cell();var e=()=>{var e,t,i,n=o.model.fields[this.attributes.name];if(n.set_state(o,["invisible"]),n.get_state_attrs(o).invisible?s.hide():s.show(),this.protocol){if(e=n.get(o),!jQuery.isEmptyObject(e))switch(this.protocol){case"email":e="mailto:"+e;break;case"callto":e="callto:"+e;break;case"sip":e="sip:"+e}s.attr("href",e)}if(this.icon)switch(e=this.icon in o.model.fields?o.model.fields[this.icon].get_client(o):this.icon,t=s.children("img").length?s.children("img"):s,"url"==this.attributes.icon_type?e?(this.attributes.url_size&&((i=new URL(e,window.location)).searchParams.set(this.attributes.url_size,20),e=i.href),t.attr("src",e)):t.removeAttr("src"):Sao.common.ICONFACTORY.get_icon_url(e).done(e=>{e?t.attr("src",e):t.removeAttr("src")}),this.attributes.border){case"rounded":t.addClass("img-rounded");break;case"circle":t.addClass("img-circle")}else e=(e=this.attributes.string||"")||n.get_client(o)||"",s.text(e)};return o.is_loaded(this.attributes.name)?e():o.load(this.attributes.name,!0,!1).done(e),s},clicked:function(e){e.stopPropagation()}}),Sao.View.Tree.Symbol=Sao.class_(Object,{class_:"column-symbol",init:function(e,t){this.attributes=e,this.position=t},get_cell:function(){return jQuery("<span/>",{class:this.class_,tabindex:0})},render:function(i,n){n=n||this.get_cell();var e=()=>{var e,t=i.model.fields[this.attributes.name];t.set_state(i,["invisible"]),!t.get_state_attrs(i).invisible&&(e=(t=t.get_symbol(i,this.attributes.symbol))[0],t=t[1],Math.round(t)===this.position)?(n.text(e),n.show()):(n.text(""),n.hide())};return i.is_loaded(this.attributes.name)?e():i.load(this.attributes.name,!0,!1).done(e),n}}),Sao.View.Tree.CharColumn=Sao.class_(Object,{class_:"column-char",init:function(e,t){this.type="field",this.model=e,this.field=e.fields[t.name],this.tree=null,this.attributes=t,this.prefixes=[],this.suffixes=[],this.header=null,this.footers=[]},get field_name(){return this.attributes.name},get model_name(){return this.model.name},get_cell:function(){return jQuery("<div/>",{class:this.class_,tabindex:0})},get_textual_value:function(e){return this.field.get_client(e)},update_text:function(e,t){t=this.get_textual_value(t);e.text(t).attr("title",t)},render:function(e,t){t=t||this.get_cell();var i=()=>{this.update_text(t,e),this.field.set_state(e),this.field.get_state_attrs(e).invisible?t.hide():t.show()},n=()=>{var e=Sao.i18n.gettext("#ERROR");t.text(e).attr("title",e)};return e.is_loaded(this.attributes.name)?(e.exception?n:i)():e.load(this.attributes.name,!0,!1).done(i).fail(n),t},set_visible:function(e){var t=this.footers.slice();t.push(this.header);for(const i of t)e?(i.show(),i.removeClass("invisible")):(i.hide(),i.addClass("invisible"))},get_visible:function(){return!this.header.hasClass("invisible")}}),Sao.View.Tree.TextColum=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-text"}),Sao.View.Tree.IntegerColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-integer",init:function(e,t){Sao.View.Tree.IntegerColumn._super.init.call(this,e,t),this.factor=Number(t.factor||1),this.grouping=Boolean(Number(t.grouping||1))},get_cell:function(){return Sao.View.Tree.IntegerColumn._super.get_cell.call(this)},get_textual_value:function(e){return this.field.get_client(e,this.factor,this.grouping)}}),Sao.View.Tree.FloatColumn=Sao.class_(Sao.View.Tree.IntegerColumn,{class_:"column-float"}),Sao.View.Tree.BooleanColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-boolean",get_cell:function(){return jQuery("<input/>",{type:"checkbox",class:this.class_,tabindex:0})},update_text:function(e,t){e.prop("checked",this.field.get(t))},render:function(e,t){var i=!t,n=(t=Sao.View.Tree.BooleanColumn._super.render.call(this,e,t),!0);return this.tree.editable&&(i&&t.on("click",null,{record:e,cell:t},this.clicked.bind(this)),i=this.field.get_state_attrs(e),n=this.attributes.readonly||i.readonly),t.prop("disabled",n),t},clicked:function(e){var t=e.data.record,i=e.data.cell,n=this.tree.screen.current_record,o=this.tree.get_fields();!n||n.validate(o,!1,!1,!0)?(n=i.prop("checked"),this.field.set_client(t,n)):e.preventDefault()}}),Sao.View.Tree.Many2OneColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-many2one",get_cell:function(){var e=Sao.View.Tree.Many2OneColumn._super.get_cell.call(this);return e.append(jQuery("<a/>",{href:"#"})),e},update_text:function(e,t){(e=e.children("a")).unbind("click"),Sao.View.Tree.Many2OneColumn._super.update_text.call(this,e,t),e.click(e=>{e.stopPropagation();e={};e.model=this.attributes.relation,e.res_id=this.field.get(t),e.mode=["form"],e.name=this.attributes.string,e.context=this.field.get_context(t),Sao.Tab.create(e)})}}),Sao.View.Tree.One2OneColumn=Sao.class_(Sao.View.Tree.Many2OneColumn,{class_:"column-one2one"}),Sao.View.Tree.SelectionColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-selection",init:function(e,t){Sao.View.Tree.SelectionColumn._super.init.call(this,e,t),Sao.common.selection_mixin.init.call(this),this.tree&&!this.tree.editable||this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e)},update_selection:function(e,t){this.selection||this.init_selection(),Sao.common.selection_mixin.update_selection.call(this,e,this.field,t)},get_textual_value:function(e){var t=this.field.name+":string";if(!this.tree.editable&&t in e._values)return e._values[t];var i=this.field.get(e);for(const n of this.selection)if(n[0]===i)return n[1];return i},update_text:function(o,s){var e;!this.tree.editable&&this.field.name+":string"in s._values?(e=this.get_textual_value(s),o.text(e).attr("title",e)):this.update_selection(s,()=>{var e,t=this.field.get(s),i=!1;for(const n of this.selection)if(n[0]===t){i=!0,e=n[1];break}(i?jQuery.when(e):Sao.common.selection_mixin.get_inactive_selection.call(this,t).then(function(e){return e[1]})).done(e=>{o.text(e).attr("title",e)})})}}),Sao.View.Tree.MultiSelectionColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-multiselection",init:function(e,t){Sao.View.Tree.MultiSelectionColumn._super.init.call(this,e,t),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e)},update_selection:function(e,t){Sao.common.selection_mixin.update_selection.call(this,e,this.field,t)},get_textual_value:function(e){var t=this.field.name+":string";return!this.tree.editable&&t in e._values?e._values[t]:this.field.get_eval(e).map(e=>{for(const t of this.selection)if(t[0]===e)return t[1];return""}).join(";")},update_text:function(t,i){var e;!this.tree.editable&&this.field_name+":string"in i._values?(e=this.get_textual_value(i),t.text(e).attr("title",e)):this.update_selection(i,()=>{var e=this.get_textual_value(i);t.text(e).attr("title",e)})}}),Sao.View.Tree.ReferenceColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-reference",init:function(e,t){Sao.View.Tree.ReferenceColumn._super.init.call(this,e,t),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e)},update_selection:function(e,t){Sao.common.selection_mixin.update_selection.call(this,e,this.field,t)},get_cell:function(){var e=Sao.View.Tree.ReferenceColumn._super.get_cell.call(this);return e.append(jQuery("<a/>",{href:"#"})),e},get_textual_value:function(e){var t,i,e=Sao.View.Tree.ReferenceColumn._super.get_textual_value.call(this,e),e=e?(t=e[0],e[1]):t="";if(t){for(const n of this.selection)if(n[0]===t){t=n[1];break}i=t+","+e}else i=e;return i},update_text:function(t,i){(t=t.children("a")).unbind("click"),this.update_selection(i,()=>{var e=this.get_textual_value(i);t.text(e).attr("title",e),t.click(e=>{e.stopPropagation();var e=this.field.get(i);e&&(e={model:e.split(",")[0],res_id:parseInt(e.split(",")[1],10),mode:["form"],name:this.attributes.string,context:this.field.get_context(i)},Sao.Tab.create(e))})})}}),Sao.View.Tree.DictColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-dict",get_textual_value:function(e){return"("+Object.keys(this.field.get_client(e)).length+")"}}),Sao.View.Tree.DateColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-date",get_textual_value:function(e){var t=this.field.get_client(e),e=this.field.date_format(e);return Sao.common.format_date(e,t)}}),Sao.View.Tree.TimeColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-time",get_textual_value:function(e){var t=this.field.get_client(e);return Sao.common.format_time(this.field.time_format(e),t)}}),Sao.View.Tree.TimeDeltaColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-timedelta"}),Sao.View.Tree.One2ManyColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-one2many",get_textual_value:function(e){return"( "+this.field.get_client(e).length+" )"}}),Sao.View.Tree.Many2ManyColumn=Sao.class_(Sao.View.Tree.One2ManyColumn,{class_:"column-many2many"}),Sao.View.Tree.BinaryColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-binary",init:function(e,t){Sao.View.Tree.BinaryColumn._super.init.call(this,e,t),this.filename=t.filename||null},get_cell:function(){var e=Sao.View.Tree.BinaryColumn._super.get_cell.call(this);return jQuery("<span/>").appendTo(e),e},get_textual_value:function(e){e=this.field.get_size?this.field.get_size(e):this.field.get(e).length;return e?Sao.common.humanize(e,"B"):""},update_text:function(e,t){var i=this.get_textual_value(t),n=(e.children("span").text(i).attr("title",i),e.children("button"));n.length||(n=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",title:Sao.i18n.gettext("Save As...")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-download")).appendTo(e).click(t,e=>{e.stopPropagation(),this.save_as(e.data)})),i?n.show():n.hide()},save_as:function(e){var t,i=e.model.fields[this.filename];i&&(t=i.get_client(e),Sao.common.guess_mimetype(t)),(this.field.get_data?this.field.get_data(e):jQuery.when(this.field.get(e))).done(e=>{Sao.common.download_file(e,t)})}}),Sao.View.Tree.ImageColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-image",get_cell:function(){var e=jQuery("<img/>",{class:this.class_+" center-block",tabindex:0});return this.height=parseInt(this.attributes.height||100,10),this.width=parseInt(this.attributes.width||300,10),e.css("max-height",this.height),e.css("max-width",this.width),e.css("height","auto"),e.css("width","auto"),e},render:function(i,n){n=n||this.get_cell();var e=()=>{var e=e=>{n.attr("src",Sao.common.image_url(e))},t=this.field.get_client(i);!t||t>Sao.config.image_max_size?e(null):this.field.get_data(i).done(e)},t=()=>{n.attr("src",null)};return i.is_loaded(this.attributes.name)?(e.exception?t:e)():i.load(this.attributes.name,!0,!1).done(e).fail(t),n}}),Sao.View.Tree.URLColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-url",render:function(e,t){return t=Sao.View.Tree.URLColumn._super.render.call(this,e,t),this.field.set_state(e),this.field.get_state_attrs(e).readonly?t.hide():t.show(),t}}),Sao.View.Tree.ProgressBar=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-progressbar",get_cell:function(){var e=jQuery("<div/>",{class:this.class_+" progress",tabindex:0});return jQuery("<div/>",{class:"progress-bar",role:"progressbar","aria-valuemin":0,"aria-valuemax":100}).appendTo(e).css("min-width: 2em"),e},get_textual_value:function(e){e=this.field.get_client(e,100);return e=e&&Sao.i18n.gettext("%1%",e)},update_text:function(e,t){var i=this.get_textual_value(t),t=this.field.get(t)||0,e=e.find(".progress-bar");e.attr("aria-valuenow",100*t),e.css("width",100*t+"%"),e.text(i).attr("title",i)}}),Sao.View.Tree.ButtonColumn=Sao.class_(Object,{init:function(e,t){this.view=e,this.type="button",this.attributes=t,this.footers=[]},render:function(e,t){var i=new Sao.common.Button(this.attributes,t,"btn-sm");t||i.el.click([e,i],this.button_clicked.bind(this)),jQuery.map(this.view.screen.model.fields,function(e,t){if("eager"==(e.description.loading||"eager"))return t});return i.set_state(e),i.el},set_visible:function(e){var t=this.footers.slice();t.push(this.header);for(const i of t)e?(i.show(),i.removeClass("invisible")):(i.hide(),i.addClass("invisible"))},get_visible:function(){return!this.header.hasClass("invisible")},button_clicked:function(e){var t=e.data[0],e=e.data[1];if(t!=this.view.screen.current_record)return!0;var i=t.expr_eval(this.attributes.states||{});i.invisible||i.readonly||(e.el.prop("disabled",!0),(i=this.view.rows.find(function(e){return e.record==t}))&&(i._drawed_record=null),this.view.screen.button(this.attributes))}}),Sao.View.TreeXMLViewParser.WIDGETS={binary:Sao.View.Tree.BinaryColumn,boolean:Sao.View.Tree.BooleanColumn,callto:Sao.View.Tree.URLColumn,char:Sao.View.Tree.CharColumn,date:Sao.View.Tree.DateColumn,dict:Sao.View.Tree.DictColumn,email:Sao.View.Tree.URLColumn,float:Sao.View.Tree.FloatColumn,image:Sao.View.Tree.ImageColumn,integer:Sao.View.Tree.IntegerColumn,many2many:Sao.View.Tree.Many2ManyColumn,many2one:Sao.View.Tree.Many2OneColumn,numeric:Sao.View.Tree.FloatColumn,one2many:Sao.View.Tree.One2ManyColumn,one2one:Sao.View.Tree.One2OneColumn,progressbar:Sao.View.Tree.ProgressBar,reference:Sao.View.Tree.ReferenceColumn,selection:Sao.View.Tree.SelectionColumn,multiselection:Sao.View.Tree.MultiSelectionColumn,sip:Sao.View.Tree.URLColumn,text:Sao.View.Tree.TextColum,time:Sao.View.Tree.TimeColumn,timedelta:Sao.View.Tree.TimeDeltaColumn,url:Sao.View.Tree.URLColumn},Sao.View.EditableTree={},Sao.View.EditableTree.editable_mixin=function(e){e.el.on("keydown",function(e){e.which!=Sao.common.TAB_KEYCODE&&e.which!=Sao.common.UP_KEYCODE&&e.which!=Sao.common.DOWN_KEYCODE&&e.which!=Sao.common.ESC_KEYCODE&&e.which!=Sao.common.RETURN_KEYCODE||this.focus_out()}.bind(e))},Sao.View.EditableTree.Char=Sao.class_(Sao.View.Form.Char,{class_:"editabletree-char",init:function(e,t){Sao.View.EditableTree.Char._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.URL=Sao.class_(Sao.View.EditableTree.Char,{class_:"editable-url",set_readonly:function(e){Sao.View.EditableTree.URL._super.set_readonly.call(this,e),e?this.input.hide():this.input.show()}}),Sao.View.EditableTree.Date=Sao.class_(Sao.View.Form.Date,{class_:"editabletree-date",init:function(e,t){Sao.View.EditableTree.Date._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.Time=Sao.class_(Sao.View.Form.Time,{class_:"editabletree-time",init:function(e,t){Sao.View.EditableTree.Time._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.TimeDelta=Sao.class_(Sao.View.Form.TimeDelta,{class_:"editabletree-timedelta",init:function(e,t){Sao.View.EditableTree.TimeDelta._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.Integer=Sao.class_(Sao.View.Form.Integer,{class_:"editabletree-integer",init:function(e,t){delete(t=jQuery.extend({},t)).symbol,Sao.View.EditableTree.Integer._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)},get width(){}}),Sao.View.EditableTree.Float=Sao.class_(Sao.View.Form.Float,{class_:"editabletree-float",init:function(e,t){delete(t=jQuery.extend({},t)).symbol,Sao.View.EditableTree.Float._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)},get width(){}}),Sao.View.EditableTree.Selection=Sao.class_(Sao.View.Form.Selection,{class_:"editabletree-selection",init:function(e,t){Sao.View.EditableTree.Selection._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.Boolean=Sao.class_(Sao.View.Form.Boolean,{class_:"editabletree-boolean",init:function(e,t){Sao.View.EditableTree.Boolean._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.Many2One=Sao.class_(Sao.View.Form.Many2One,{class_:"editabletree-many2one",init:function(e,t){Sao.View.EditableTree.Many2One._super.init.call(this,e,t)}}),Sao.View.EditableTree.Reference=Sao.class_(Sao.View.Form.Reference,{class_:"editabletree-reference",init:function(e,t){Sao.View.EditableTree.Reference._super.init.call(this,e,t)}}),Sao.View.EditableTree.One2One=Sao.class_(Sao.View.Form.One2One,{class_:"editabletree-one2one",init:function(e,t){Sao.View.EditableTree.One2One._super.init.call(this,e,t)}}),Sao.View.EditableTree.One2Many=Sao.class_(Sao.View.EditableTree.Char,{class_:"editabletree-one2many",init:function(e,t){Sao.View.EditableTree.One2Many._super.init.call(this,e,t)},display:function(e,t){e?this.el.val("("+t.get_client(e).length+")"):this.el.val("")},key_press:function(e){e.which==Sao.common.TAB_KEYCODE&&this.focus_out()},set_value:function(e,t){}}),Sao.View.EditableTree.Binary=Sao.class_(Sao.View.Form.Binary,{class_:"editabletree-binary",init:function(e,t){Sao.View.EditableTree.Binary._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.WIDGETS={binary:Sao.View.EditableTree.Binary,boolean:Sao.View.EditableTree.Boolean,callto:Sao.View.EditableTree.URL,char:Sao.View.EditableTree.Char,date:Sao.View.EditableTree.Date,email:Sao.View.EditableTree.URL,float:Sao.View.EditableTree.Float,integer:Sao.View.EditableTree.Integer,many2many:Sao.View.EditableTree.Many2Many,many2one:Sao.View.EditableTree.Many2One,numeric:Sao.View.EditableTree.Float,one2many:Sao.View.EditableTree.One2Many,one2one:Sao.View.EditableTree.One2One,reference:Sao.View.EditableTree.Reference,selection:Sao.View.EditableTree.Selection,sip:Sao.View.EditableTree.URL,text:Sao.View.EditableTree.Char,time:Sao.View.EditableTree.Time,timedelta:Sao.View.EditableTree.TimeDelta,url:Sao.View.EditableTree.URL}}(),!function(){"use strict";Sao.View.GraphXMLViewParser=Sao.class_(Sao.View.XMLViewParser,{init:function(e,t,i){Sao.View.GraphXMLViewParser._super.init.call(this,e,t,i),this._xfield=null,this._yfields=[]},_node_attributes:function(e){var t={};for(const i of e.attributes)t[i.name]=i.value;return t.name&&!t.string&&"#"!=t.name&&(e=this.field_attrs[t.name],t.string=e.string),t},_parse_graph:function(e,t){for(const i of e.childNodes)this.parse(i);e=new Sao.View.GraphXMLViewParser.WIDGETS[t.type||"vbar"](this.view,this._xfield,this._yfields);this.view.el.append(e.el),this.view.widgets.root=e},_parse_x:function(e,t){for(const i of e.children)this._xfield=this._node_attributes(i)},_parse_y:function(e,t){for(const i of e.children)this._yfields.push(this._node_attributes(i))}}),Sao.View.Graph=Sao.class_(Sao.View,{editable:!1,view_type:"graph",xml_parser:Sao.View.GraphXMLViewParser,init:function(e,t,i,n){this.el=jQuery("<div/>",{class:"graph"}),Sao.View.Graph._super.init.call(this,e,t,i)},display:function(){return this.widgets.root.display(this.group)}}),Sao.View.Graph.Chart=Sao.class_(Object,{_chart_type:void 0,init:function(e,t,i){this.view=e,this.xfield=t,this.yfields=i,this.el=jQuery("<div/>"),this.el.uniqueId()},update_data:function(r){for(var l,c,d,h,u,_={},m=(this.ids={},_.columns=[["labels"]],_.names={},{}),e=[this.xfield.name],t=0,i=this.yfields.length;t<i;t++)c=this.yfields[t],d=c.key||c.name,_.columns.push([d]),_.names[d]=c.string,m[d]=t+1,e.push(c.name);var n=[],o=a=>()=>{var e,t,i=(l=r[a]).field_get_client(this.xfield.name),n=(i&&(i.isDate||i.isDateTime)&&(i=i.toString()),_.columns[0].indexOf(i));for(n<0&&(n=_.columns[0].push(i)-1),this._add_id(i,l.id),h=0,u=this.yfields.length;h<u;h++){if(c=this.yfields[h],d=c.key||c.name,void 0===(e=_.columns[m[d]])[n]&&(e[n]=null),c.domain){var o,s=jQuery.extend({},Sao.Session.current_session.context);for(o in(s.context=s)._user=Sao.Session.current_session.user_id,r.model.fields)s[o]=l.field_get(o);if(!new Sao.PYSON.Decoder(s).decode(c.domain))continue}e[n]||(e[n]=0),"#"==c.name?e[n]+=1:((t=l.field_get(c.name))&&t.isTimeDelta&&(t=t.asSeconds()),e[n]+=t||0)}},s=[];for(t=0,i=r.length;t<i;t++){l=r[t];for(const a of e)n.push(l.load(a));s.push(jQuery.when.apply(jQuery,n).then(o(t)))}return jQuery.when.apply(jQuery,s).then(function(){return _})},_add_id:function(e,t){e in this.ids||(this.ids[e]=[]),this.ids[e].push(t)},display:function(e){e=this.update_data(e);return e.done(e=>{c3.generate(this._c3_config(e))}),e},_c3_config:function(e){for(var t,i,n,o={},e=(o.bindto="#"+this.el.attr("id"),o.data=e,o.data.type=this._chart_type,o.data.x="labels",o.data.onclick=this.action.bind(this),this.view.screen.model.fields[this.xfield.name].description.type),e=("date"==e||"datetime"==e?(t=Sao.common.date_format(this.view.screen.context.date_format),i="%X",e="datetime"==e?(o.data.xFormat="%Y-%m-%d %H:%M:%S",function(e){return Sao.common.format_datetime(t+" "+i,moment(e))}):(o.data.xFormat="%Y-%m-%d",function(e){return Sao.common.format_date(t,moment(e))}),o.axis={x:{type:"timeseries",tick:{format:e}}}):o.axis={x:{type:"category"}},this.view.attributes.color||Sao.config.graph_color),s=Sao.common.hex2rgb(Sao.common.COLOR_SCHEMES[e]||e),s=Math.max.apply(null,s),a=[],r=0;r<this.yfields.length;r++)n=this.yfields[r],a.push(n.key||n.name);var l=Sao.common.generateColorscheme(e,a,s/(a.length||1));for(r=0;r<this.yfields.length;r++)(n=this.yfields[r]).color&&(l[n.key||n.name]=n.color);return o.data.color=function(e,t){t=t.id||t;return l[t]||e},o},action:function(e,t){var e=this.ids[this._action_key(e)],i=jQuery.extend({},this.view.screen.group._context);delete i.active_ids,delete i.active_id,Sao.Action.exec_keyword("graph_open",{model:this.view.screen.model_name,id:e[0],ids:e},i,!1)},_action_key:function(e){var e=e.x,t=this.view.screen.model.fields[this.xfield.name].description.type;return e&&"datetime"==t?e=Sao.DateTime(e).toString():e&&"date"==t&&(e=Sao.Date(e).toString()),e}}),Sao.View.Graph.VerticalBar=Sao.class_(Sao.View.Graph.Chart,{_chart_type:"bar"}),Sao.View.Graph.HorizontalBar=Sao.class_(Sao.View.Graph.Chart,{_chart_type:"bar",_c3_config:function(e){e=Sao.View.Graph.HorizontalBar._super._c3_config.call(this,e);return e.axis.rotated=!0,e}}),Sao.View.Graph.Line=Sao.class_(Sao.View.Graph.Chart,{_chart_type:"line",_c3_config:function(e){e=Sao.View.Graph.Line._super._c3_config.call(this,e);return e.line={connectNull:!0},e}}),Sao.View.Graph.Pie=Sao.class_(Sao.View.Graph.Chart,{_chart_type:"pie",_c3_config:function(e){for(var t,i,n=Sao.View.Graph.Pie._super._c3_config.call(this,e),o=[],s={},a=0,r=e.columns.length;a<r;a++)"labels"==e.columns[a][0]?t=e.columns[a].slice(1):i=e.columns[a].slice(1);delete n.axis,delete n.data.x;var l,c,d,h,u=this.view.screen.model.fields[this.xfield.name].description.type;for("date"!=u&&"datetime"!=u||(l=Sao.common.date_format(this.view.screen.context.date_format),c=l+" %X",d="datetime"==u?function(e){return Sao.common.format_datetime(c,e)}:function(e){return Sao.common.format_date(l,e)}),a=0,r=t.length;a<r;a++)h=t[a],d&&(h=d(h)),o.push([a,i[a]]),s[a]=h;return n.data.columns=o,n.data.names=s,n},_add_id:function(e,t){var i,n=this.xfield.type;"date"!=n&&"datetime"!=n||(i=Sao.common.date_format(this.view.screen.context.date_format),e="datetime"==n?Sao.common.format_datetime(i+" %X",e):Sao.common.format_date(i,e)),Sao.View.Graph.Pie._super._add_id.call(this,e,t)},_action_key:function(e){return e.id}}),Sao.View.GraphXMLViewParser.WIDGETS={hbar:Sao.View.Graph.HorizontalBar,line:Sao.View.Graph.Line,pie:Sao.View.Graph.Pie,vbar:Sao.View.Graph.VerticalBar}}(),!function(){"use strict";function i(e){var t,i=window.innerHeight-15;e.parents(".modal-body").length&&(t=parseInt(e.parents(".modal-body").css("max-height"),10),isNaN(t)?i-=200:i=t),i-=e.find(".fc-toolbar").height(),e.parents(".panel-body").each(function(e,t){t=jQuery(t),i=(i-=parseInt(t.css("padding-top"),10))-parseInt(t.css("padding-bottom"),10)}),e.parents(".panel").each(function(e,t){t=(t=jQuery(t)).css("box-shadow").match(/\d+px/g);t&&t.length&&(t=t.map(function(e){return e=parseInt(e,10),isNaN(e)?0:e}),i-=Math.max.apply(null,t))}),i-=e[0].getBoundingClientRect().y,e.fullCalendar("option","contentHeight",i)}jQuery(window).resize(function(){jQuery(".calendar").each(function(e,t){i(jQuery(t))})}),Sao.View.CalendarXMLViewParser=Sao.class_(Sao.View.XMLViewParser,{_parse_calendar:function(e,t){for(const o of e.childNodes)this.parse(o);var e="datetime"==this.view.screen.model.fields[t.dtstart].description.type?"agendaWeek":"basicWeek",i="datetime"==this.view.screen.model.fields[t.dtstart].description.type?"agendaDay":"basicDay",n="month",e=("week"==t.mode&&(n=e),"day"==t.mode&&(n=i),{left:"today prev,next",center:"title",right:"month,"+e+","+i});Sao.i18n.rtl&&((i=jQuery.extend({},e)).left=e.right,i.right=e.left,e=i),this.view.el.fullCalendar({defaultView:n,header:e,timeFormat:"H:mm",scrollTime:(this.view.screen.context.calendar_scroll_time||Sao.Time(6)).toString(),events:this.view.get_events.bind(this.view),locale:Sao.i18n.getlang().slice(0,2),isRTL:Sao.i18n.rtl,themeSystem:"bootstrap3",bootstrapGlyphicons:{prev:"chevron-"+(Sao.i18n.rtl?"right":"left"),next:"chevron-"+(Sao.i18n.rtl?"left":"right")},buttonTextOverride:{today:Sao.i18n.gettext("Today"),month:Sao.i18n.gettext("Month"),week:Sao.i18n.gettext("Week"),day:Sao.i18n.gettext("Day")},eventRender:this.view.event_render.bind(this.view),eventResize:this.view.event_resize.bind(this.view),eventDrop:this.view.event_drop.bind(this.view),eventClick:this.view.event_click.bind(this.view),dayClick:this.view.day_click.bind(this.view)}),void 0!==t.height&&this.view.el.css("min-height",t.height+"px"),void 0!==t.width&&this.view.el.css("min-width",t.width+"px")},_parse_field:function(e,t){this.view.fields.push(t.name)}}),Sao.View.Calendar=Sao.class_(Sao.View,{editable:!1,creatable:!1,view_type:"calendar",xml_parser:Sao.View.CalendarXMLViewParser,init:function(e,t,i){this.processing=!0,this.fields=[],this.el=jQuery("<div/>",{class:"calendar"}),Sao.View.Calendar._super.init.call(this,e,t,i)},get_colors:function(e){var t={};return t.text_color=Sao.config.calendar_colors[0],this.attributes.color&&(t.text_color=e.field_get(this.attributes.color)),t.background_color=Sao.config.calendar_colors[1],this.attributes.background_color&&(t.background_color=e.field_get(this.attributes.background_color)),t},display:function(){this.el.fullCalendar("render"),i(this.el),this.processing||this.el.fullCalendar("refetchEvents")},insert_event:function(e){var t,i=jQuery.extend([],this.fields),n=i.shift(),n=this.screen.model.fields[n].get_client(e),o=e.model.fields[this.attributes.dtstart],s=o.get_client(e),a=(o.set_state(e),null),r=(this.attributes.dtend&&(a=(t=e.model.fields[this.attributes.dtend]).get_client(e),t.set_state(e)),Sao.common.MODELACCESS.get(this.screen.model_name)),r=parseInt(this.attributes.editable||1,10)&&r.write,l=[];for(const c of i)l.push(this.screen.model.fields[c].get_client(e));l=l.join("\n"),s&&((i=s.isDate&&(!a||a.isDate))&&a&&!a.isSame(s)&&"calendar"==this.screen.current_view.view_type&&a.add(1,"day"),a&&a<s||(s={title:n,start:s,end:a,allDay:i,editable:r&&!o.get_state_attrs(e).readonly&&(!a||!t.get_state_attrs(e).readonly),color:(n=this.get_colors(e)).background_color,textColor:n.text_color,record:e,description:l},this.events.push(s)))},get_events:function(e,t,i,n){this.processing=!0,this.start=Sao.DateTime(e.utc()),this.end=Sao.DateTime(t.utc());var e=jQuery.when(),o=(this.screen.current_view&&"form"!=this.screen.current_view.view_type&&(t=this.screen.screen_container.get_text(),e=this.screen.search_filter(t)),this.events=[],[]);e.then(()=>(this.group.forEach(e=>{var t=[];for(const n of this.fields)t.push(e.load(n));var i=jQuery.when.apply(jQuery,t).then(()=>{this.insert_event(e)});o.push(i)}),jQuery.when.apply(jQuery,o).then(()=>{n(this.events)}).always(()=>{this.processing=!1})))},event_click:function(e,t,i){this.clicked_event||(this.clicked_event=!0,this.screen.current_record=e.record,this.screen.switch_view().always(()=>{this.clicked_event=!1}))},event_drop:function(e,t,i,n,o,s){var a=this.attributes.dtstart,r=this.attributes.dtend,l=e.record,c=(l.group,l.field_get(a)),d=c,h=(r&&(d=l.field_get(r)),e.start),e=e.end;e!=c&&e||(e=h),c.isDateTime?(e=Sao.DateTime(e.format()).utc(),h=Sao.DateTime(h.format()).utc()):c.isSame(d)||(e.subtract(1,"day"),this.el.fullCalendar("refetchEvents")),c<=h?(r&&l.field_set_client(r,e),l.field_set_client(a,h)):(l.field_set_client(a,h),r&&l.field_set_client(r,e)),l.save()},event_resize:function(e,t,i,n,o,s){var a=this.attributes.dtend,r=e.record,l=(r.group,r.field_get(a)),e=e.end;!0===l.isDateTime?e=Sao.DateTime(e.format()).utc():(e.subtract(1,"day"),this.el.fullCalendar("refetchEvents")),r.field_set_client(a,e=e!=l&&e?e:l),r.save()},event_render:function(e,t,i){this.screen.model.fields.date&&"calendar"==this.screen.view_name&&t.find(".fc-time").remove(),t.find(".fc-content").append(jQuery("<div/>",{class:"fc-description"}).text(e.description)),t.css("white-space","pre").css("overflow","hidden").css("text-overflow","ellipsis").attr("title",[e.title,e.description].filter(function(e){return e}).join("\n"))},day_click:function(e,t,i){var n=Sao.common.MODELACCESS.get(this.screen.model_name);parseInt(this.attributes.editable||1,10)&&n.create&&(this.el.fullCalendar("gotoDate",e),this.screen.current_record=null,this.screen.new_())},current_domain:function(){var e,t,i,n;return this.start||this.end?(e=Sao.DateTime(this.start),t=Sao.DateTime(this.end),[[i=this.attributes.dtstart,"!=",null],[n=this.attributes.dtend||i,"!=",null],["OR",["AND",[i,">=",e],[i,"<",t]],["AND",[n,">=",e],[n,"<",t]],["AND",[i,"<",e],[n,">",t]]]]):[["id","=",-1]]},get_displayed_period:function(){var e=[];return this.start&&this.end&&e.push(this.start,this.end),e},set_default_date:function(e,t){var i=this.attributes.dtstart,n=e.model.fields[i];n instanceof Sao.field.DateTime?t=Sao.DateTime(t):n instanceof Sao.field.Date&&(t=Sao.Date(t)),n.set(e,t),e.on_change([i]),e.on_change_with([i])},get_selected_date:function(){return this.el.fullCalendar("getDate")},get listed_records(){return this.events.map(e=>e.record)}})}(),!function(){"use strict";Sao.View.ListGroupViewForm=Sao.class_(Sao.View.Form,{get record(){return this._record},set record(e){this._record=e},button_clicked:function(e){Sao.common.compare(this.screen.selected_records,[this.record])&&Sao.View.ListGroupViewForm._super.button_clicked.call(this,e)}}),Sao.View.ListForm=Sao.class_(Sao.View,{editable:!0,creatable:!0,view_type:"list-form",init:function(e,t,i){Sao.View.ListForm._super.init.call(this,e,t,i),this.attributes.creatable&&(this.creatable=Boolean(parseInt(this.attributes.creatable,10))),this.form_xml=i,this.el=jQuery("<ul/>",{class:"list-group list-form"}),this._view_forms=[]},display:function(e){var t,i,n,o=[],s=[],a=new Set;if(!jQuery.isEmptyObject(e))for(const l of e)a.add(l[0]);for(var r=0;r<this.group.length;r++)t=this.group[r],(i=this._view_forms[r])?(n=i.el.parent(),i.record=t):(n=this._create_form(t),s.push(n),i=this._view_forms[this._view_forms.length-1]),~this.group.record_deleted.indexOf(t)||~this.group.record_removed.indexOf(t)?n.addClass("disabled"):n.removeClass("disabled"),this.record===t||a.has(t.id)?n.addClass("list-group-item-selected"):n.removeClass("list-group-item-selected"),o.push(i.display());return 0<s.length&&this.el.append(s),e=this._view_forms.splice(this.group.length),jQuery(e.map(function(e){return e.el[0]})).parent().detach(),jQuery.when.apply(jQuery,o)},get_selected_paths:function(){var e=[];for(const t of this._view_forms)t.el.parent().hasClass("list-group-item-selected")&&e.push([t.record.id]);return e},_create_form:function(e){var t=new Sao.View.ListGroupViewForm(this.view_id,this.screen,this.form_xml),e=(t.record=e,this._view_forms.push(t),jQuery("<li/>",{class:"list-group-item list-form-item"}));return e.append(t.el),e.click(this._view_forms.length-1,this._select_row.bind(this)),e},get selected_records(){var e=[];for(const t of this._view_forms)t.el.parent().hasClass("list-group-item-selected")&&e.push(t.record);return e},get listed_records(){return this.group.slice()},set_cursor:function(e,t){e&&this.el.animate({scrollTop:this.el[0].scrollHeight})},select_records:function(e,t){if(jQuery(this._view_forms.map(function(e){return e.el[0]})).parent().removeClass("list-group-item-selected"),null!==e||null!==t){var i;(t=t||0)<(e=e||0)&&(i=e,e=t,t=i);for(const n of this._view_forms.slice(e,t+1))n.el.parent().addClass("list-group-item-selected")}},_select_row:function(e){var n=e.data,o=this._view_forms[n],t=jQuery.when();this.record&&o.record!=this.record&&(this.screen.group.parent?this.screen.attributes.pre_validate&&(t=this.record.pre_validate()):t=this.record.validate(this.get_fields(),!1,!1,!1)?this.record.save():jQuery.Deferred().reject()),t.done(()=>{var t;if(e.shiftKey){let e=0;for(const i of this._view_forms){if(i.record===this.record){t=i;break}e++}this.select_records(e,n)}else e.ctrlKey||e.metaKey||this.select_records(null,null),this.record=o.record,o.el.parent().toggleClass("list-group-item-selected");t&&(this.record=t.record)})}})}(),!function(){"use strict";Sao.Action={report_blob_url:void 0},Sao.Action.exec_action=function(e,n,t){t=t?jQuery.extend({},t):{};var i=Sao.Session.current_session;function o(t,e){var i;return n.model&&n.ids&&(i=n.ids.filter(function(e){return 0<=e}).slice(0,5)).length?Sao.rpc({method:"model."+n.model+".read",params:[i,["rec_name"],e]},Sao.Session.current_session).then(function(e){e=e.map(function(e){return e.rec_name}).join(Sao.i18n.gettext(", "));return n.ids.length>i.length&&(e+=Sao.i18n.gettext(",...")),e?Sao.i18n.gettext("%1 (%2)",t,e):t}):jQuery.when(t)}n=void 0===n?{}:jQuery.extend({},n),delete t.active_id,delete t.active_ids,delete t.active_model,n.action_id=e.id;var s={icon:e["icon.rec_name"]||""};switch(e.type){case"ir.action.act_window":if(jQuery.isEmptyObject(e.views))jQuery.isEmptyObject(e.view_id)||(s.view_ids=[e.view_id[0]]);else{s.view_ids=[],s.mode=[];for(const l of e.views)s.view_ids.push(l[0]),s.mode.push(l[1])}void 0===e.pyson_domain&&(e.pyson_domain="[]");var a={active_model:n.model||null,active_id:n.id||null,active_ids:n.ids||[]},r=((a=jQuery.extend(a,i.context))._user=i.user_id,new Sao.PYSON.Decoder(a));s.context=jQuery.extend({},t,r.decode(e.pyson_context||"{}")),(a=jQuery.extend(a,s.context)).context=a,r=new Sao.PYSON.Decoder(a),s.domain=r.decode(e.pyson_domain),s.order=r.decode(e.pyson_order),s.search_value=r.decode(e.pyson_search_value||"[]"),s.tab_domain=[];for(const c of e.domains)s.tab_domain.push([c[0],r.decode(c[1]),c[2]]);return a=jQuery.when(e.name),s.model=e.res_model||n.res_model,s.res_id=e.res_id||n.res_id,s.context_model=e.context_model,s.context_domain=e.context_domain,void 0!==e.limit&&null!==e.limit&&(s.limit=e.limit),void(a=e.keyword?o(e.name,s.context):a).then(function(e){s.name=e,Sao.Tab.create(s)});case"ir.action.wizard":return s.action=e.wiz_name,s.data=n,s.context=t,s.window=e.window,a=jQuery.when(e.name),void(a="form_action"===(e.keyword||"form_action")?o(e.name,t):a).done(function(e){s.name=e,Sao.Wizard.create(s)});case"ir.action.report":return s.name=e.report_name,s.data=n,s.direct_print=e.direct_print,s.context=t,void Sao.Action.exec_report(s);case"ir.action.url":return void window.open(e.url,"_blank","noreferrer,noopener")}},Sao.Action.exec_keyword=function(e,o,s,a=!0,r=!1){var t=o.id,e={method:"model.ir.action.keyword.get_keyword",params:[e,[o.model,t],{}]};return Sao.rpc(e,Sao.Session.current_session).pipe(function(e){var t,i={};for(t in e){var n=e[t];i[n.name.split(" / ").pop()]=n}return Sao.common.selection(Sao.i18n.gettext("Select your action"),i,r).then(function(e){Sao.Action.exec_action(e,o,s)},function(){jQuery.isEmptyObject(i)&&a&&alert(Sao.i18n.gettext("No action defined."))})})},Sao.Action.exec_report=function(e){e.context||(e.context={});var t=jQuery.extend({},e.data),i=jQuery.extend({},Sao.Session.current_session.context);jQuery.extend(i,e.context),i.direct_print=e.direct_print,Sao.rpc({method:"report."+e.name+".execute",params:[t.ids||[],t,i]},Sao.Session.current_session).done(function(e){var t=e[0],i=e[1],e=(e[2],e[3]);Sao.common.download_file(i,e+"."+t)})},Sao.Action.execute=function(e,t,i,n){"number"==typeof e&&(e=Sao.rpc({method:"model.ir.action.get_action_value",params:[e,i]},Sao.Session.current_session,!1)),n&&!e.keyword&&(e.keyword={"ir.action.report":"form_report","ir.action.wizard":"form_action","ir.action.act_window":"form_relate"}[e.type]),Sao.Action.exec_action(e,t,i)},Sao.Action.evaluate=function(e,t,i){var n={};return"subject"in(n="pyson_email"in(e=jQuery.extend({},e))&&(n=i.expr_eval(e.pyson_email),jQuery.isEmptyObject(n))?{}:n)||(n.subject=e.name.replace(/_/g,"")),e.email=n,e}}(),!function(){"use strict";var n=["866","ansi_x3.4-1968","arabic","ascii","asmo-708","big5","big5-hkscs","chinese","cn-big5","cp1250","cp1251","cp1252","cp1253","cp1254","cp1255","cp1256","cp1257","cp1258","cp819","cp866","csbig5","cseuckr","cseucpkdfmtjapanese","csgb2312","csibm866","csiso2022jp","csiso2022kr","csiso58gb231280","csiso88596e","csiso88596i","csiso88598e","csiso88598i","csisolatin1","csisolatin2","csisolatin3","csisolatin4","csisolatin5","csisolatin6","csisolatin9","csisolatinarabic","csisolatincyrillic","csisolatingreek","csisolatinhebrew","cskoi8r","csksc56011987","csmacintosh","csshiftjis","cyrillic","dos-874","ecma-114","ecma-118","elot_928","euc-jp","euc-kr","gb18030","gb2312","gb_2312","gb_2312-80","gbk","greek","greek8","hebrew","hz-gb-2312","ibm819","ibm866","iso-2022-cn","iso-2022-cn-ext","iso-2022-jp","iso-2022-kr","iso-8859-1","iso-8859-10","iso-8859-11","iso-8859-13","iso-8859-14","iso-8859-15","iso-8859-16","iso-8859-2","iso-8859-3","iso-8859-4","iso-8859-5","iso-8859-6","iso-8859-6-e","iso-8859-6-i","iso-8859-7","iso-8859-8","iso-8859-8-e","iso-8859-8-i","iso-8859-9","iso-ir-100","iso-ir-101","iso-ir-109","iso-ir-110","iso-ir-126","iso-ir-127","iso-ir-138","iso-ir-144","iso-ir-148","iso-ir-149","iso-ir-157","iso-ir-58","iso8859-1","iso8859-10","iso8859-11","iso8859-13","iso8859-14","iso8859-15","iso8859-2","iso8859-3","iso8859-4","iso8859-5","iso8859-6","iso8859-7","iso8859-8","iso8859-9","iso88591","iso885910","iso885911","iso885913","iso885914","iso885915","iso88592","iso88593","iso88594","iso88595","iso88596","iso88597","iso88598","iso88599","iso_8859-1","iso_8859-15","iso_8859-1:1987","iso_8859-2","iso_8859-2:1987","iso_8859-3","iso_8859-3:1988","iso_8859-4","iso_8859-4:1988","iso_8859-5","iso_8859-5:1988","iso_8859-6","iso_8859-6:1987","iso_8859-7","iso_8859-7:1987","iso_8859-8","iso_8859-8:1988","iso_8859-9","iso_8859-9:1989","koi","koi8","koi8-r","koi8-ru","koi8-u","koi8_r","korean","ks_c_5601-1987","ks_c_5601-1989","ksc5601","ksc_5601","l1","l2","l3","l4","l5","l6","l9","latin1","latin2","latin3","latin4","latin5","latin6","logical","mac","macintosh","ms932","ms_kanji","shift-jis","shift_jis","sjis","sun_eu_greek","tis-620","unicode-1-1-utf-8","us-ascii","utf-16","utf-16be","utf-16le","utf-8","utf8","visual","windows-1250","windows-1251","windows-1252","windows-1253","windows-1254","windows-1255","windows-1256","windows-1257","windows-1258","windows-31j","windows-874","windows-949","x-cp1250","x-cp1251","x-cp1252","x-cp1253","x-cp1254","x-cp1255","x-cp1256","x-cp1257","x-cp1258","x-euc-jp","x-gbk","x-mac-cyrillic","x-mac-roman","x-mac-ukrainian","x-sjis","x-user-defined","x-x-big5"];Sao.Window={},Sao.Window.InfoBar=Sao.class_(Object,{init:function(){this.el=jQuery("<div/>",{class:"infobar"}),this.__messages=new Set},add:function(e,t,i){var n;i=i||null,e&&(n=JSON.stringify([e,t]),this.__messages.has(n)||(t=jQuery("<div/>",{class:"alert alert-dismissible alert-"+(t||"error"),role:"alert"}).append(jQuery("<button/>",{type:"button",class:"close","aria-label":Sao.i18n.gettext("Close"),title:Sao.i18n.gettext("Close"),"data-dismiss":"alert"}).append(jQuery("<span/>",{"aria-hidden":!0}).append("×"))).append(jQuery("<span/>").css("white-space","pre-wrap").text(e)).on("close.bs.alert",null,n,this.__response.bind(this)),this.el.append(t),t.data("kind",i)))},__response:function(e){this.__messages.add(e.data)},refresh:function(i){i=i||null,this.el.children().each((e,t)=>{(t=jQuery(t)).data("kind")===i&&t.remove()})},clear:function(){var e=this.el.children().each((e,t)=>jQuery(t).data("kind"));new Set(e).forEach(e=>{this.refresh(e)}),this.__messages.clear()}}),Sao.Window.Form=Sao.class_(Object,{init:function(o,t,i){i=i||{},this.screen=o,this.callback=t,this.many=i.many||0,this.domain=i.domain||null,this.context=i.context||null,this.save_current=i.save_current;var n,e,s=jQuery.when(i.title||"").then(e=>{o.breadcrumb.length?(n=jQuery.extend([],o.breadcrumb),e&&n.push(e),this.title=n.slice(-3,-1).map(function(e){return Sao.common.ellipsize(e,30)}).concat(n.slice(-1)).join(" › "),3<n.length&&(this.title="... › "+this.title)):(e=e||Sao.common.MODELNAME.get(this.screen.model_name),this.title=e);var t,i,n=this.screen.context._datetime;return n&&Sao.common.MODELHISTORY.contains(this.screen.model_name)?(t=Sao.common.date_format(this.screen.context.date_format),t=" @ "+Sao.common.format_datetime(t+" %H:%M:%S.%f",n),i=Sao.common.ellipsize(this.title,80-t.length)+t,e=this.title+t):i=Sao.common.ellipsize(this.title,80),i}),a=(this.prev_view=o.current_view,this.screen.screen_container.alternate_view=!0,this.info_bar=new Sao.Window.InfoBar,i.view_type||"form"),r=(this.switch_prm=this.screen.switch_view(a).done(()=>{i.new_&&this.screen.current_view.view_type==a&&this.screen.new_(void 0,i.defaults)}),new Sao.Dialog("","window-form","lg",!1)),t=(this.dialog=r,this.el=r.modal,this.el.on("keydown",e=>{e.which==Sao.common.ESC_KEYCODE&&(e.preventDefault(),this.response("RESPONSE_CANCEL"))}),this.screen.group.readonly);if(this.but_ok=null,this.but_new=null,this._initial_value=null,"form"==(this.view_type=a)&&!t){let e;i.new_?e=Sao.i18n.gettext("Delete"):(e=Sao.i18n.gettext("Discard changes"),n=this.screen.current_record,this._initial_value=n.get_on_change_value(),n.group.parent&&n.model.fields[n.group.parent_name]&&(l=n.model.fields[n.group.parent_name],this._initial_value[n.group.parent_name]=l.get_eval(n))),r.footer.append(jQuery("<button/>",{class:"btn btn-link",type:"button",title:e}).text(e).click(()=>{this.response("RESPONSE_CANCEL")}))}if(i.new_&&this.many){let e;e=this.save_current&&!t?Sao.i18n.gettext("Save and New"):Sao.i18n.gettext("Add and New"),r.footer.append(jQuery("<button/>",{class:"btn btn-default",type:"button",title:e}).text(e).click(()=>{this.response("RESPONSE_ACCEPT")}))}if(this.save_current&&!t){var l=Sao.i18n.gettext("Save");this.but_ok=jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:l}).text(l).appendTo(r.footer)}else{let e;e=t||"tree"==a?Sao.i18n.gettext("Close"):i.new_?Sao.i18n.gettext("Add"):Sao.i18n.gettext("Apply changes"),this.but_ok=jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:e}).text(e).appendTo(r.footer)}r.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),"tree"==a&&(n=jQuery("<div/>",{class:"window-form-toolbar"}).appendTo(r.body),l=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(n),this.wid_text=jQuery("<input/>",{type:"input"}).appendTo(n),this.wid_text.hide(),n=jQuery("<div/>",{class:"input-group-btn"}).appendTo(l),l=Sao.common.MODELACCESS.get(this.screen.model_name),e=function(i){return function(e){var t=jQuery(e.target);t.prop("disabled",!0),(i(e)||jQuery.when()).always(function(){t.prop("disabled",!1)})}},this.but_switch=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Switch"),title:Sao.i18n.gettext("Switch")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-switch")).appendTo(n),this.but_switch.click(e(this.switch_.bind(this))),this.but_previous=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Previous"),title:Sao.i18n.gettext("Previous")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-back")).appendTo(n),this.but_previous.click(e(this.previous.bind(this))),this.label=jQuery("<span/>",{class:"badge"}).appendTo(jQuery("<span/>",{class:"btn hidden-xs"}).appendTo(n)),this.but_next=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Next"),title:Sao.i18n.gettext("Next")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-forward")).appendTo(n),this.but_next.click(e(this.next.bind(this))),this.domain&&(this.wid_text.show(),this.but_add=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Add"),title:Sao.i18n.gettext("Add")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).appendTo(n),this.but_add.click(e(this.add.bind(this))),this.but_add.prop("disabled",!l.read||t),this.but_remove=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Remove"),title:Sao.i18n.gettext("Remove")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).appendTo(n),this.but_remove.click(e(this.remove.bind(this))),this.but_remove.prop("disabled",!l.read||t)),this.but_new=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("New"),title:Sao.i18n.gettext("New")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-create")).appendTo(n),this.but_new.click(e(this.new_.bind(this))),this.but_new.prop("disabled",!l.create||t),this.but_del=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Delete"),title:Sao.i18n.gettext("Delete")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-delete")).appendTo(n),this.but_del.click(e(this.delete_.bind(this))),this.but_del.prop("disabled",!l.delete||t),this.but_undel=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Undelete"),title:Sao.i18n.gettext("Undelete")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-undo")).appendTo(n),this.but_undel.click(e(this.undelete.bind(this))),this.but_undel.prop("disabled",!l.delete||t));var c=jQuery("<div/>").appendTo(r.body);r.body.append(this.info_bar.el),this.screen.windows.push(this),this.switch_prm.done(()=>{this.screen.current_view.view_type!=a?this.destroy():(s.done(r.add_title.bind(r)),c.append(this.screen.screen_container.alternate_viewport),this.el.modal("show"))}),this.el.on("shown.bs.modal",e=>{this.screen.display().done(()=>{this.screen.set_cursor()})}),this.el.on("hidden.bs.modal",function(e){jQuery(this).remove()})},record_message:function(e,t){var i,n,o,s;"tree"==this.view_type&&(i="_",n=Sao.common.MODELACCESS.get(this.screen.model_name),o=this.screen.deletable,s=this.screen.group.readonly,1<=e?(i=e,this.domain&&this.but_remove.prop("disabled",!1),this.but_next.prop("disabled",t<=e),this.but_previous.prop("disabled",e<=1),this.but_del.prop("disabled",s||!n.delete||!o),this.but_undel.prop("disabled",s)):(this.but_del.prop("disabled",!0),this.but_undel.prop("disabled",!0),this.but_next.prop("disabled",!0),this.but_previous.prop("disabled",!0),this.domain&&this.but_remove.prop("disabled",!0)),this.label.text(e=i+"/"+t).attr("title",e))},record_modified:function(){this.info_bar.refresh()},add:function(){var e=jQuery.extend([],this.domain),t=this.screen.model_name,i=this.wid_text.val(),n=new Sao.common.DomainParser;new Sao.Window.Search(t,e=>{var t=jQuery.when();if(!jQuery.isEmptyObject(e)){var i=[];for(const n of e)i.push(n[0]);this.screen.group.load(i,!0),t=this.screen.display()}t.done(()=>{this.screen.set_cursor()}),this.entry.val("")},{sel_multi:!0,context:this.context,domain:e,search_filter:n.quote(i)})},remove:function(){this.screen.remove(!1,!0,!1)},new_:function(){this.screen.new_(),this._initial_value=null,--this.many,0==this.many&&this.but_new.addClass("disabled")},delete_:function(){this.screen.remove(!1,!1,!1)},undelete:function(){this.screen.unremove()},previous:function(){return this.screen.display_previous()},next:function(){return this.screen.display_next()},switch_:function(){return this.screen.switch_view()},response:function(a){this.screen.current_view.set_value();var e,r,t,i,n=this.screen.group.readonly;~["RESPONSE_OK","RESPONSE_ACCEPT"].indexOf(a)&&!n&&this.screen.current_record?this.screen.current_record.validate().then(e=>e&&this.screen.attributes.pre_validate?this.screen.current_record.pre_validate().then(()=>!0,()=>!1):e).then(e=>{var t=jQuery.Deferred();if(e&&this.save_current)this.screen.save_current().then(t.resolve,t.reject);else if(e&&"form"==this.screen.current_view.view_type){var i,n=this.screen.current_view,o=[];for(i in n.widgets){var s=n.widgets[i];s.screen&&s.screen.attributes.pre_validate&&(s=s.screen.current_record)&&o.push(s.pre_validate())}jQuery.when.apply(jQuery,o).then(t.resolve,t.reject)}else e?(this.info_bar.clear(),t.resolve()):(this.info_bar.add(this.screen.invalid_message(),"danger"),t.reject());t.fail(()=>{this.screen.display().done(()=>{this.screen.set_cursor()})}),t.done(()=>{"RESPONSE_ACCEPT"==a?(this.screen.new_(),this.screen.current_view.display().done(()=>{this.screen.set_cursor()}),--this.many,0===this.many&&this.but_new.prop("disabled",!0)):(r=!0,this.callback&&this.callback(r),this.destroy())})}):(e=null,"RESPONSE_CANCEL"==a&&!n&&this.screen.current_record?(r=!1,i=(t=this.screen.current_record).modified_fields.id,t.id<0||this.save_current?e=this.screen.cancel_current(this._initial_value):t.modified&&(t.cancel(),e=t.reload().then(()=>{this.screen.display()})),i&&(t.modified_fields.id=i)):r="RESPONSE_CANCEL"!=a&&!n,(e||jQuery.when()).then(()=>{this.callback&&this.callback(r),this.destroy()}))},destroy:function(){this.screen.windows.splice(this.screen.windows.indexOf(this),1),this.screen.screen_container.alternate_view=!1,this.screen.screen_container.alternate_viewport.children().detach(),this.prev_view&&this.screen.switch_view(this.prev_view.view_type),this.el.modal("hide")}}),Sao.Window.Attachment=Sao.class_(Sao.Window.Form,{init:function(e,t){this.resource=e.model.name+","+e.id,this.attachment_callback=t;var t=jQuery.extend({},e.get_context()),i=new Sao.Screen("ir.attachment",{domain:[["resource","=",this.resource]],mode:["tree","form"],context:t}),t=e.rec_name().then(function(e){return Sao.i18n.gettext("Attachments (%1)",e)});Sao.Window.Attachment._super.init.call(this,i,this.callback,{view_type:"tree",title:t}),this.switch_prm=this.switch_prm.then(function(){return i.search_filter()})},callback:function(e){var t=jQuery.when();e&&(t=this.screen.save_current()),this.attachment_callback&&t.always(this.attachment_callback.bind(this))},add_data:function(i,n){var o=this.screen;this.switch_prm.then(function(){o.new_().then(function(e){var t=e.model.fields.data;e.field_set_client(t.description.filename,n),e.field_set_client("data",i),o.display()})})},add_uri:function(t){var i=this.screen;this.switch_prm.then(function(){i.current_record=null,i.switch_view("form").then(function(){i.new_().then(function(e){e.field_set_client("link",t),e.field_set_client("type","link"),i.display()})})})},add_text:function(t){var i=this.screen;this.switch_prm.then(function(){i.current_record=null,i.switch_view("form").then(function(){i.new_().then(function(e){e.field_set_client("description",t),i.display()})})})}}),Sao.Window.Attachment.get_attachments=function(r){var l,e;e=r&&0<=r.id?(l=r.get_context(),Sao.rpc({method:"model.ir.attachment.search_read",params:[[["resource","=",r.model.name+","+r.id]],0,20,null,["rec_name","name","type","link"],l]},r.model.session)):jQuery.when([]);return e.then(function(e){return e.map(function(e){var t,i,n,o,s,a=e.rec_name;return"link"==e.type?[a,e.link]:(t=Sao.Window.Attachment["open_"+e.type],[a,(i=t,n=e,o=l,s=r.model.session,function(){return i(n,o,s)})])})})},Sao.Window.Attachment.open_data=function(t,e,i){Sao.rpc({method:"model.ir.attachment.read",params:[[t.id],["data"],e]},i).then(function(e){Sao.common.download_file(e[0].data,t.name)})},Sao.Window.Note=Sao.class_(Sao.Window.Form,{init:function(e,t){this.resource=e.model.name+","+e.id,this.note_callback=t;var t=jQuery.extend({},e.get_context()),i=new Sao.Screen("ir.note",{domain:[["resource","=",this.resource]],mode:["tree","form"],context:t}),t=e.rec_name().then(function(e){return Sao.i18n.gettext("Notes (%1)",e)});Sao.Window.Note._super.init.call(this,i,this.callback,{view_type:"tree",title:t}),this.switch_prm=this.switch_prm.then(function(){return i.search_filter()})},callback:function(e){var t=jQuery.when();if(e){var i=this.screen.group.model.fields.unread;for(const n of this.screen.group)!(n.get_loaded()||n.id<0)||n.modified_fields.unread||i.set_client(n,!1);t=this.screen.save_current()}this.note_callback&&t.always(this.note_callback.bind(this))}}),Sao.Window.Log=Sao.class_(Sao.Window.Form,{init:function(e){this.resource=e.model.name+","+e.id;var t=e.rec_name().then(function(e){return Sao.i18n.gettext("Logs (%1)",e)}),i=jQuery.extend({},e.get_context()),n=jQuery("<div/>",{class:"form"}),o=jQuery("<table/>",{class:"form-container responsive responsive-noheader"}).appendTo(n),c=jQuery("<tbody/>").appendTo(o),s=(e.model.execute("read",[[e.id],["create_uid.rec_name","create_date","write_uid.rec_name","write_date"]],i).then(([o])=>{var s,a=jQuery("<tr/>").appendTo(c),r=jQuery("<td/>").css("text-align","end").appendTo(a),l=jQuery("<label/>",{class:"form-label",text:Sao.i18n.gettext("Model:")}).appendTo(r);l.uniqueId(),r=jQuery("<td/>").appendTo(a),(s=jQuery("<input/>",{readonly:!0,class:"form-control input-sm","aria-labelledby":l.attr("id")}).val(e.model.name).appendTo(r)).uniqueId(),r=jQuery("<td/>").css("text-align","end").appendTo(a),(l=jQuery("<label/>",{class:"form-label",text:Sao.i18n.gettext("ID:")}).appendTo(r)).uniqueId(),r=jQuery("<td/>").appendTo(a),(s=jQuery("<input/>",{type:"integer",readonly:!0,class:"form-control input-sm","aria-labelledby":l.attr("id")}).val(e.id).appendTo(r)).css("text-align","end"),s.uniqueId(),[["create_uid.",Sao.i18n.gettext("Created by:"),"create_date",Sao.i18n.gettext("Created at:")],["write_uid.",Sao.i18n.gettext("Last Modified by:"),"write_date",Sao.i18n.gettext("Last Modified at:")]].forEach(([e,t,i,n])=>{a=jQuery("<tr/>").appendTo(c),r=jQuery("<td/>").css("text-align","end").appendTo(a),(l=jQuery("<label/>",{class:"form-label",text:t}).appendTo(r)).uniqueId(),r=jQuery("<td/>").appendTo(a),e=(e=o[e])&&e.rec_name,(s=jQuery("<input/>",{readonly:!0,class:"form-control input-sm","aria-labelledby":l.attr("id")}).val(e||"").appendTo(r)).css("width","50ch"),s.uniqueId(),r=jQuery("<td/>").css("text-align","end").appendTo(a),(l=jQuery("<label/>",{class:"form-label",text:n}).appendTo(r)).uniqueId(),r=jQuery("<td/>").appendTo(a),i=(i=o[i])&&Sao.common.format_datetime(Sao.common.date_format()+" %H:%M:%S",i),(s=jQuery("<input/>",{readonly:!0,class:"form-control input-sm","aria-labelledby":l.attr("id")}).val(i||"").appendTo(r)).css("width",i.length+"ch"),s.uniqueId()})}),new Sao.Screen("ir.model.log",{domain:[["resource","=",this.resource]],mode:["tree","form"],context:i}));Sao.Window.Log._super.init.call(this,s,null,{view_type:"tree",title:t}),this.switch_prm=this.switch_prm.then(function(){return s.search_filter()}),this.dialog.body.prepend(n)}}),Sao.Window.Search=Sao.class_(Object,{init:function(e,t,i){var n=(i=i||{}).views_preload||{};this.model_name=e,this.domain=i.domain||[],this.context=i.context||{},this.order=i.order||null,this.view_ids=i.view_ids,this.views_preload=n,this.sel_multi=i.sel_multi,this.callback=t;var t=(t=i.title)||Sao.common.MODELNAME.get(e),o=(this.title=t,this.exclude_field=i.exclude_field||null,new Sao.Dialog(Sao.i18n.gettext("Search %1",this.title),"","lg",!1));this.el=o.modal,this.el.on("keydown",e=>{e.which==Sao.common.ESC_KEYCODE&&(e.preventDefault(),this.response("RESPONSE_CANCEL"))}),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(o.footer),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("Find")}).text(Sao.i18n.gettext("Find")).click(()=>{this.response("RESPONSE_APPLY")}).appendTo(o.footer),i.new_&&Sao.common.MODELACCESS.get(e).create&&jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("New")}).text(Sao.i18n.gettext("New")).click(()=>{this.response("RESPONSE_ACCEPT")}).appendTo(o.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).appendTo(o.footer),o.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),this.screen=new Sao.Screen(e,{mode:["tree"],context:this.context,domain:this.domain,order:this.order,view_ids:i.view_ids,views_preload:n,row_activate:this.activate.bind(this),readonly:!0,breadcrumb:[this.title]}),this.screen.load_next_view().done(()=>{this.screen.switch_view().done(()=>{this.sel_multi?this.screen.current_view.selection_mode=Sao.common.SELECTION_MULTIPLE:this.screen.current_view.selection_mode=Sao.common.SELECTION_SINGLE,o.body.append(this.screen.screen_container.el),this.el.modal("show"),this.screen.display(),void 0!==i.search_filter&&this.screen.search_filter(i.search_filter)})}),this.el.on("hidden.bs.modal",function(e){jQuery(this).remove()})},activate:function(){this.response("RESPONSE_OK")},response:function(e){var t,i,n,o,s=[];if("RESPONSE_OK"==e)t=this.screen.current_view.selected_records;else{if("RESPONSE_APPLY"==e)return void this.screen.search_filter(this.screen.screen_container.get_text());if("RESPONSE_ACCEPT"==e)return e=jQuery.extend([],this.view_ids),jQuery.isEmptyObject(e)||e.shift(),i=new Sao.Screen(this.model_name,{domain:this.domain,context:this.context,order:this.order,mode:["form"],view_ids:e,views_preload:this.views_preload,exclude_field:this.exclude_field}),this.el.modal("hide"),void new Sao.Window.Form(i,function(e){e?(e=i.current_record,this.callback([[e.id,e._values.rec_name||""]])):this.callback(null)}.bind(this),{new_:!0,save_current:!0})}if(t)for(n in t)o=t[n],s.push([o.id,o._values.rec_name||""]);this.callback(s),this.el.modal("hide")}}),Sao.Window.Preferences=Sao.class_(Object,{init:function(t){var i=new Sao.Dialog("Preferences","","lg");this.el=i.modal,jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).appendTo(i.footer),i.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),this.screen=new Sao.Screen("res.user",{mode:[]}),this.screen.attributes.readonly=!1,this.screen.group.readonly=!1,this.screen.group.skip_model_access=!0;const n=e=>{this.screen.current_record.cancel(),this.screen.current_record.set(e),this.screen.current_record.id=this.screen.model.session.user_id,this.screen.current_record.validate(null,!0).then(()=>{this.screen.display(!0)}),i.body.append(this.screen.screen_container.el),this.el.modal("show")};this.el.on("hidden.bs.modal",function(e){t(),jQuery(this).remove()}),this.screen.model.execute("get_preferences_fields_view",[],{}).then(e=>{this.screen.add_view(e),this.screen.switch_view().done(()=>{this.screen.new_(!1),this.screen.model.execute("get_preferences",[!1],{}).then(n,this.destroy)})},this.destroy)},response:function(e){var t=jQuery.when();(t="RESPONSE_OK"==e?this.screen.current_record.validate().then(e=>{if(e)return e=jQuery.extend({},this.screen.get()),this.screen.model.execute("set_preferences",[e],{})}):t).done(()=>{this.destroy()})},destroy:function(){this.el.modal("hide")}}),Sao.Window.Revision=Sao.class_(Object,{init:function(e,t,i){this.callback=i;var n,i=new Sao.Dialog(Sao.i18n.gettext("Revision"),"","lg"),i=(this.el=i.modal,jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).appendTo(i.footer),i.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),jQuery("<div/>",{class:"form-group"}).appendTo(i.body)),o=(jQuery("<label/>",{for:"revision",text:"Revision"}).appendTo(i),this.select=jQuery("<select/>",{class:"form-control",id:"revision",placeholder:Sao.i18n.gettext("Revision")}).appendTo(i),Sao.common.date_format());this.select.append(jQuery("<option/>",{value:null,text:""}));for(n of e){var s=n[2];n=n[0],this.select.append(jQuery("<option/>",{value:n.valueOf(),text:Sao.common.format_datetime(o+" %H:%M:%S.%f",n)+" "+s}))}t&&this.select.val(t.valueOf()),this.el.modal("show"),this.el.on("hidden.bs.modal",function(e){jQuery(this).remove()})},response:function(e){var t=null;"RESPONSE_OK"==e&&(t=(t=this.select.val())&&Sao.DateTime(parseInt(t,10))),this.el.modal("hide"),this.callback(t)}}),Sao.Window.CSV=Sao.class_(Object,{init:function(e){this.dialog=new Sao.Dialog(e,"csv","lg"),this.el=this.dialog.modal,this.fields={},this.fields_model={},jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(this.dialog.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(e=>{e.preventDefault(),this.response("RESPONSE_OK")}).appendTo(this.dialog.footer);var e=jQuery("<div/>",{class:"row"}).appendTo(this.dialog.body),t=jQuery("<div/>",{class:"col-md-5"}).append(jQuery("<div/>",{class:"panel panel-default"}).append(jQuery("<div/>",{class:"panel-heading"}).append(jQuery("<h3/>",{class:"panel-title",text:Sao.i18n.gettext("All Fields")})))).appendTo(e),t=(this.fields_all=jQuery("<ul/>",{class:"list-unstyled column-fields panel-body"}).css("cursor","pointer").appendTo(t.find(".panel")),this.model_populate(this._get_fields(this.screen.model_name)),this.view_populate(this.fields_model,this.fields_all),this.column_buttons=jQuery("<div/>",{class:"col-md-2"}).appendTo(e),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Add")}).text(" "+Sao.i18n.gettext("Add")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).click(()=>{this.fields_all.find(".bg-primary").each((e,t)=>{this.sig_sel_add(t)})}).appendTo(this.column_buttons),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Remove")}).text(" "+Sao.i18n.gettext("Remove")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).click(()=>{this.fields_selected.children("li.bg-primary").remove()}).appendTo(this.column_buttons),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Clear")}).text(" "+Sao.i18n.gettext("Clear")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-clear")).click(()=>{this.fields_selected.empty()}).appendTo(this.column_buttons),jQuery("<hr>").appendTo(this.column_buttons),jQuery("<div/>",{class:"col-md-5"}).append(jQuery("<div/>",{class:"panel panel-default"}).append(jQuery("<div/>",{class:"panel-heading"}).append(jQuery("<h3/>",{class:"panel-title",text:Sao.i18n.gettext("Fields Selected")})))).appendTo(e)),e=(this.fields_selected=jQuery("<ul/>",{class:"list-unstyled column-fields panel-body"}).css("cursor","pointer").appendTo(t.find(".panel")),this.chooser_form=jQuery("<div/>",{class:"form-inline"}).appendTo(this.dialog.body),jQuery("<div/>",{}).appendTo(this.dialog.body)),t=(jQuery("<label/>",{text:Sao.i18n.gettext("CSV Parameters")}).append(jQuery("<span/>",{class:"caret"}).html(" ")).css("cursor","pointer").on("click",()=>{this.expander_csv.collapse("toggle")}).appendTo(e),this.expander_csv=jQuery("<div/>",{id:"expander_csv",class:"collapse form-inline"}).appendTo(e),jQuery("<label/>",{text:Sao.i18n.gettext("Delimiter:"),class:"control-label",for:"input-delimiter"})),e=",",e=(navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(e=";"),this.el_csv_delimiter=jQuery("<input/>",{type:"text",class:"form-control",id:"input-delimiter",size:"1",maxlength:"1",value:e}),jQuery("<div/>",{class:"form-group"}).append(t).append(this.el_csv_delimiter).appendTo(this.expander_csv),this.expander_csv.append(" "),jQuery("<label/>",{text:Sao.i18n.gettext("Quote Char:"),class:"control-label",for:"input-quotechar"}));this.el_csv_quotechar=jQuery("<input/>",{type:"text",class:"form-control",id:"input-quotechar",size:"1",maxlength:"1",value:'"'}),jQuery("<div/>",{class:"form-group"}).append(e).append(this.el_csv_quotechar).appendTo(this.expander_csv),this.expander_csv.append(" "),this.el.modal("show"),this.el.on("hidden.bs.modal",function(){jQuery(this).remove()})},_get_fields:function(e){return Sao.rpc({method:"model."+e+".fields_get"},this.session,!1)},on_row_expanded:function(e){var t=jQuery("<ul/>").css("list-style","none").insertAfter(e.view);this.children_expand(e),this.view_populate(e.children,t)},destroy:function(){this.el.modal("hide")}}),Sao.Window.Import=Sao.class_(Sao.Window.CSV,{init:function(e,t){this.name=e,this.screen=t,this.session=Sao.Session.current_session,this.fields_data={},this.fields_invert={},Sao.Window.Import._super.init.call(this,Sao.i18n.gettext("CSV Import: %1",e)),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Auto-Detect")}).text(" "+Sao.i18n.gettext("Auto-Detect")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-search")).click(()=>{this.autodetect()}).appendTo(this.column_buttons);t=jQuery("<label/>",{text:Sao.i18n.gettext("File to Import"),class:"col-sm-6 control-label",for:"input-csv-file"}),this.file_input=jQuery("<input/>",{type:"file",id:"input-csv-file"}),jQuery("<div/>",{class:"form-group"}).append(t).append(jQuery("<div/>",{class:"col-sm-6"}).append(this.file_input)).appendTo(this.chooser_form),e=jQuery("<label/>",{text:Sao.i18n.gettext("Encoding:"),class:"control-label",for:"input-encoding"});this.el_csv_encoding=jQuery("<select/>",{class:"form-control",id:"input-encoding"});for(const i of n)jQuery("<option/>",{val:i}).append(i).appendTo(this.el_csv_encoding);t="utf-8",navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(t="cp1252"),this.el_csv_encoding.children('option[value="'+t+'"]').attr("selected","selected"),jQuery("<div/>",{class:"form-group"}).append(e).append(this.el_csv_encoding).appendTo(this.expander_csv),this.expander_csv.append(" "),t=jQuery("<label/>",{text:Sao.i18n.gettext("Lines to Skip:"),class:"control-label",for:"input-skip"});this.el_csv_skip=jQuery("<input/>",{type:"number",class:"form-control",id:"input-skip",value:"0"}),jQuery("<div/>",{class:"form-group"}).append(t).append(this.el_csv_skip).appendTo(this.expander_csv),this.expander_csv.append(" "),Sortable.create(this.fields_selected.get(0),{handle:".draggable-handle",ghostClass:"dragged-row"})},sig_sel_add:function(e){e=jQuery(e),this._add_node(e.attr("field"),e.attr("name"))},_add_node:function(e,t){jQuery("<li/>",{field:e,class:"draggable-handle"}).text(t).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-drag")).click(function(e){var t=jQuery(e.target);e.ctrlKey||e.metaKey?t.toggleClass("bg-primary"):(t.addClass("bg-primary"),t.siblings().removeClass("bg-primary"))}).appendTo(this.fields_selected)},view_populate:function(s,t){Object.keys(s).sort(function(e,t){return s[t].string<s[e].string?-1:1}).reverse().forEach(i=>{var e=s[i].string||i,n=jQuery("<li/>",{field:s[i].field,name:s[i].name}).text(e).click(e=>{e.ctrlKey||e.metaKey?n.toggleClass("bg-primary"):(this.fields_all.find("li").removeClass("bg-primary"),n.addClass("bg-primary"))}).appendTo(t),o=(s[i].view=n,Sao.common.ICONFACTORY.get_icon_img("tryton-arrow-right").data("expanded",!1).click(e=>{e.stopPropagation();var t,e=o.data("expanded");o.data("expanded",!e),e?(t="tryton-arrow-right",n.next("ul").remove()):(t="tryton-arrow-down",this.on_row_expanded(s[i])),Sao.common.ICONFACTORY.get_icon_url(t).then(function(e){o.attr("src",e)})}).prependTo(n));o.css("visibility",s[i].relation?"visible":"hidden")})},model_populate:function(e,t,i,n){t=t||this.fields_model,i=i||"",n=n||"";for(const r of Object.keys(e)){var o,s,a;e[r].readonly&&"id"!=r||(o=n+(o=e[r].string||r),s="one2many"==e[r].type?e[r].relation:null,a={name:o,field:i+r,relation:s,string:e[r].string},t[r]=a,this.fields[i+r]=a,this.fields_invert[o]=i+r,s&&(a.children={}))}},children_expand:function(e){jQuery.isEmptyObject(e.children)&&e.relation&&this.model_populate(this._get_fields(e.relation),e.children,e.field+"/",e.name+"/")},autodetect:function(){this.file_input.val()?(this.fields_selected.empty(),this.el_csv_skip.val(1),Papa.parse(this.file_input[0].files[0],{delimiter:this.el_csv_delimiter.val(),quoteChar:this.el_csv_quotechar.val(),preview:1,encoding:this.el_csv_encoding.val(),error:(e,t,i,n)=>{Sao.common.warning.run(n,Sao.i18n.gettext("Detection failed"))},complete:e=>{e.data[0].every(e=>{var t,i;return e in this.fields_invert||e in this.fields||(t=this.fields_model,i=e.split("/").slice(0,-1),this._traverse(t,"",i,0)),this._auto_select(e)})}})):Sao.common.message.run(Sao.i18n.gettext("You must select an import file first."))},_auto_select:function(e){var t,i;if(e in this.fields_invert)i=this.fields_invert[t=e];else{if(!(e in this.fields))return Sao.common.warning.run(Sao.i18n.gettext('Unknown column header "%1"',e),Sao.i18n.gettext("Error")),!1;t=this.fields[e].name,i=[e]}return this._add_node(i,t),!0},_traverse:function(e,t,i,n){for(var o,s=Object.keys(e),a=0;a<s.length;a++)if((o=e[s[a]]).name==t+i[n]||o.field==t+i[n]){this.children_expand(o),t+=i[n]+"/",o.children&&this._traverse(o.children,t,i,++n);break}},response:function(e){var i;"RESPONSE_OK"==e&&(i=[],this.fields_selected.children("li").each((e,t)=>{i.push(t.getAttribute("field"))}),e=this.file_input.val())?this.import_csv(e,i).then(()=>{this.destroy()}):this.destroy()},import_csv:function(e,t){var i=this.el_csv_skip.val(),n=this.el_csv_encoding.val(),o=jQuery.Deferred();return Papa.parse(this.file_input[0].files[0],{delimiter:this.el_csv_delimiter.val(),quoteChar:this.el_csv_quotechar.val(),encoding:n,error:(e,t,i,n)=>{Sao.common.warning.run(n,Sao.i18n.gettext("Import failed")).always(o.reject)},complete:e=>{e=e.data.slice(i,e.data.length-1);Sao.rpc({method:"model."+this.screen.model_name+".import_data",params:[t,e,{}]},this.session).then(e=>Sao.common.message.run(Sao.i18n.ngettext("%1 record imported","%1 records imported",e))).then(o.resolve,o.reject)}}),o.promise()}}),Sao.Window.Export=Sao.class_(Sao.Window.CSV,{init:function(e,t,i){this.name=e,this.screen=t,this.session=Sao.Session.current_session,Sao.Window.Export._super.init.call(this,Sao.i18n.gettext("CSV Export: %1",e));var n=this.screen.model.fields;for(const e of i){var o=n[e].description.type;"selection"==o?this.sel_field(e+".translated"):"reference"==o?(this.sel_field(e+".translated"),this.sel_field(e+"/rec_name")):this.sel_field(e)}this.predef_exports={},this.fill_predefwin(),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Save Export")}).text(" "+Sao.i18n.gettext("Save Export")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-save")).click(()=>{this.addreplace_predef()}).appendTo(this.column_buttons),this.button_url=jQuery("<a/>",{class:"btn btn-default btn-block",target:"_blank",rel:"noreferrer noopener",title:Sao.i18n.gettext("URL Export")}).text(" "+Sao.i18n.gettext("URL Export")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-public")).appendTo(this.column_buttons),this.dialog.body.on("change click",this.set_url.bind(this)),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Delete Export")}).text(" "+Sao.i18n.gettext("Delete Export")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-delete")).click(()=>{this.remove_predef()}).appendTo(this.column_buttons);t=jQuery("<div/>",{class:"panel panel-default"}).append(jQuery("<div/>",{class:"panel-heading"}).append(jQuery("<h3/>",{class:"panel-title",text:Sao.i18n.gettext("Predefined Exports")}))).appendTo(this.column_buttons);this.predef_exports_list=jQuery("<ul/>",{class:"list-unstyled predef-exports panel-body"}).css("cursor","pointer").appendTo(t),this.selected_records=jQuery("<select/>",{class:"form-control",id:"input-records"}).append(jQuery("<option/>",{val:!0,selected:!this.screen_is_tree}).text(Sao.i18n.gettext("Selected Records"))).append(jQuery("<option/>",{val:!1,selected:!!this.screen_is_tree}).text(Sao.i18n.gettext("Listed Records"))),this.ignore_search_limit=jQuery("<input/>",{type:"checkbox"}),this.selected_records.change(()=>{this.ignore_search_limit.parents(".form-group").first().toggle(!JSON.parse(this.selected_records.val())&&!this.screen_is_tree)}),jQuery("<div/>",{class:"form-group"}).appendTo(this.chooser_form).append(jQuery("<label/>",{text:Sao.i18n.gettext("Export:"),class:"control-label",for:"input-records"})).append(this.selected_records),jQuery("<div/>",{class:"form-group"}).appendTo(this.chooser_form).append(jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>",{text:" "+Sao.i18n.gettext("Ignore search limit")}).prepend(this.ignore_search_limit))).hide(),this.el_csv_locale=jQuery("<input/>",{type:"checkbox",checked:"checked"}),jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>",{text:" "+Sao.i18n.gettext("Use locale format")}).prepend(this.el_csv_locale)).appendTo(this.expander_csv),this.expander_csv.append(" "),this.el_add_field_names=jQuery("<input/>",{type:"checkbox",checked:"checked"}),jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>",{text:" "+Sao.i18n.gettext("Add Field Names")}).prepend(this.el_add_field_names)).appendTo(this.expander_csv),this.expander_csv.append(" "),this.set_url(),Sortable.create(this.fields_selected.get(0),{handle:".draggable-handle",ghostClass:"dragged-row"})},get context(){return this.screen.context},get screen_is_tree(){return Boolean(this.screen.current_view&&"tree"==this.screen.current_view.view_type&&this.screen.current_view.children_field)},view_populate:function(s,t){Object.keys(s).sort(function(e,t){return s[t].string<s[e].string?-1:1}).reverse().forEach(i=>{var e=s[i].path,n=jQuery("<li/>",{path:e}).text(s[i].string).click(e=>{e.ctrlKey||e.metaKey?n.toggleClass("bg-primary"):(this.fields_all.find("li").removeClass("bg-primary"),n.addClass("bg-primary"))}).appendTo(t),o=(s[i].view=n,Sao.common.ICONFACTORY.get_icon_img("tryton-arrow-right").data("expanded",!1).click(e=>{e.stopPropagation();var t,e=o.data("expanded");o.data("expanded",!e),e?(t="tryton-arrow-right",n.next("ul").remove()):(t="tryton-arrow-down",this.on_row_expanded(s[i])),Sao.common.ICONFACTORY.get_icon_url(t).then(function(e){o.attr("src",e)})}).prependTo(n));o.css("visibility",s[i].children?"visible":"hidden")})},model_populate:function(e,t,i,n){t=t||this.fields_model,i=i||"",n=n||"";for(const c of Object.keys(e)){var o=e[c],s=o.string||c,a=[{name:c,field:o,string:s}];"selection"==o.type?a.push({name:c+".translated",field:o,string:Sao.i18n.gettext("%1 (string)",s)}):"reference"==o.type&&(a.push({name:c+".translated",field:o,string:Sao.i18n.gettext("%1 (model name)",s)}),a.push({name:c+"/rec_name",field:o,string:Sao.i18n.gettext("%1/Record Name",s)}));for(const d of a){var r=i+d.name,l=n+d.string,l={path:r,string:d.string,long_string:l,relation:d.field.relation};t[d.name]=l,this.fields[r]=l,-1==d.name.indexOf(".")&&d.field.relation&&(l.children={})}}},children_expand:function(e){jQuery.isEmptyObject(e.children)&&e.relation&&this.model_populate(this._get_fields(e.relation),e.children,e.path+"/",e.long_string+"/")},sig_sel_add:function(e){e=(e=jQuery(e)).attr("path");this.sel_field(e)},fill_predefwin:function(){Sao.rpc({method:"model.ir.export.get",params:[this.screen.model_name,["name","header","records","export_fields.name"],this.context]},this.session).done(e=>{for(const t of e)this.predef_exports[t.id]={fields:t["export_fields."].map(e=>e.name),values:t},this.add_to_predef(t.id,t.name),this.predef_exports_list.children("li").first().focus()})},add_to_predef:function(e,t){var i=jQuery("<li/>",{text:t,export_id:e,tabindex:0}).on("keypress",function(e){e=e.keyCode||e.which;13!=e&&32!=e||i.click()}).click(e=>{i.toggleClass("bg-primary").siblings().removeClass("bg-primary"),i.hasClass("bg-primary")&&this.sel_predef(i.attr("export_id"))});this.predef_exports_list.append(i)},addreplace_predef:function(){var n,e,o,s=[];for(const t of this.fields_selected.children("li"))s.push(t.getAttribute("path"));0!==s.length&&(e=t=>{var i={header:this.el_add_field_names.is(":checked"),records:JSON.parse(this.selected_records.val())?"selected":"listed"},e=n?Sao.rpc({method:"model.ir.export.update",params:[n,i,s,this.context]},this.session).then(()=>n):(i.name=t,i.resource=this.screen.model_name,i.export_fields=s.map(e=>({name:e})),Sao.rpc({method:"model.ir.export.set",params:[i,this.context]},this.session));return e.then(e=>{this.session.cache.clear("model."+this.screen.model_name+".view_toolbar_get"),this.predef_exports[e]={fields:s,values:i},0===o.length&&this.add_to_predef(e,t)})},(0===(o=this.predef_exports_list.children("li.bg-primary")).length?(n=null,Sao.common.ask.run(Sao.i18n.gettext("What is the name of this export?"),"export")):(n=o.attr("export_id"),Sao.common.sur.run(Sao.i18n.gettext("Override %1 definition?",o.text())))).then(e))},remove_predef:function(){var e,t=this.predef_exports_list.children("li.bg-primary");0!==t.length&&(e=jQuery(t).attr("export_id"),Sao.rpc({method:"model.ir.export.unset",params:[e,this.context]},this.session).then(()=>{this.session.cache.clear("model."+this.screen.model_name+".view_toolbar_get"),delete this.predef_exports[e],t.remove()}))},sel_predef:function(e){this.fields_selected.empty();var t,i,e=this.predef_exports[e];for(const n of e.fields){if(n in this.fields||(t=this.fields_model,i=n.split("/").slice(0,-1),this._traverse(t,"",i,0)),!(n in this.fields))return;this.sel_field(n)}this.el_add_field_names.prop("checked",e.values.header),this.selected_records.val(JSON.stringify("selected"==e.values.records))},_traverse:function(e,t,i,n){for(var o,s=Object.keys(e),a=0;a<s.length;a++)if((o=e[s[a]]).path==t+i[n]){this.children_expand(o),t+=i[n]+"/",o.children&&this._traverse(o.children,t,i,++n);break}},sel_field:function(e){var t=this.fields[e].long_string,i=(this.fields[e].relation&&(e+="/rec_name"),jQuery("<li/>",{path:e,class:"draggable-handle"}).text(t).click(function(e){e.ctrlKey||e.metaKey?i.toggleClass("bg-primary"):jQuery(e.target).addClass("bg-primary").siblings().removeClass("bg-primary")}).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-drag")).appendTo(this.fields_selected))},response:function(e){var i,t,n,o,s;"RESPONSE_OK"==e?(i=[],this.fields_selected.children("li").each(function(e,t){i.push(t.getAttribute("path"))}),t=this.el_add_field_names.is(":checked"),(JSON.parse(this.selected_records.val())?(s=this.screen.selected_records.map(function(e){return e.id}),n=this.screen.selected_paths,Sao.rpc({method:"model."+this.screen.model_name+".export_data",params:[s,i,t,this.context]},this.session)):this.screen_is_tree?(s=this.screen.listed_records.map(function(e){return e.id}),n=this.screen.listed_paths,Sao.rpc({method:"model."+this.screen.model_name+".export_data",params:[s,i,t,this.context]},this.session)):(e=this.screen.search_domain(this.screen.screen_container.get_text()),s=this.ignore_search_limit.prop("checked")?(o=0,null):(o=this.screen.offset,this.screen.limit),Sao.rpc({method:"model."+this.screen.model_name+".export_data_domain",params:[e,i,o,s,this.screen.order,t,this.context]},this.session))).then(e=>{this.export_csv(e,n,t).then(()=>{this.destroy()})})):this.destroy()},export_csv:function(e,i,t=!1){var n=this.el_csv_locale.prop("checked"),o={},o=(o.data=e.map(function(e,t){t=i&&i[t]?i[t].length-1:0;return Sao.Window.Export.format_row(e,t,n)}),Papa.unparse(o,{quoteChar:this.el_csv_quotechar.val(),delimiter:this.el_csv_delimiter.val()})),o=(navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(o=Sao.BOM_UTF8+o),Sao.common.download_file(o,this.name+".csv",{type:"text/csv;charset=utf-8"}),e.length);return t&&--o,Sao.common.message.run(Sao.i18n.ngettext("%1 record saved","%1 records saved",o))},set_url:function(){var e,t=[this.session.database,"data",this.screen.model_name],i=[];if(JSON.parse(this.selected_records.val()))e=this.screen.current_view.selected_records.map(function(e){return e.id});else if(e=this.screen.search_domain(this.screen.screen_container.get_text()),this.ignore_search_limit.prop("checked")||null===this.screen.limit||(i.push(["s",this.screen.limit.toString()]),i.push(["p",Math.floor(this.screen.offset/this.screen.limit).toString()])),this.screen.order)for(const n of this.screen.order)i.push(["o",n.map(function(e){return e}).join(",")]);i.splice(0,0,["d",JSON.stringify(Sao.rpc.prepareObject(e))]),jQuery.isEmptyObject(this.screen.local_context)||i.push(["c",JSON.stringify(Sao.rpc.prepareObject(this.screen.local_context))]),this.fields_selected.children("li").each(function(e,t){i.push(["f",t.getAttribute("path")])}),i.push(["dl",this.el_csv_delimiter.val()]),i.push(["qc",this.el_csv_quotechar.val()]),this.el_add_field_names.is(":checked")||i.push(["h","0"]),this.el_csv_locale.prop("checked")&&i.push(["loc","1"]),i=i.map(function(e){return e.map(encodeURIComponent).join("=")}).join("&"),this.button_url.attr("href","/"+t.join("/")+"?"+i)}}),Sao.Window.Export.format_row=function(e,i=0,n=!0){var o=[];return e.forEach(function(e,t){n?e.isDateTime?e=e.local().format(Sao.common.date_format()+" "+Sao.common.moment_format("%X")):e.isDate?e=e.format(Sao.common.date_format()):e.isTimeDelta?e=Sao.common.timedelta.format(e,{s:1,m:60,h:3600}):isNaN(Number(e))||(e=e.toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),{minimumFractionDigits:0,maximumFractionDigits:20})):e.isDateTime?e=e.utc():e.isTimeDelta?e=e.asSeconds():"boolean"==typeof e&&(e+=0),(e=0===t&&i&&"string"==typeof e?" ".repeat(i)+e:e)instanceof Uint8Array&&(e=Sao.common.btoa(e)),o.push(e)}),o},Sao.Window.EmailEntry=Sao.class_(Sao.common.InputCompletion,{init:function(e,t){this.session=t,Sao.Window.EmailEntry._super.init.call(this,e,this._email_source,this._email_match_selected,this._email_format)},_email_match_selected:function(e){this.input.val(e[2])},_email_source:function(e){return this.input[0].selectionStart<this.input.val().length?jQuery.when([]):Sao.rpc({method:"model.ir.email.complete",params:[e,Sao.config.limit,{}]},this.session).fail(function(){Sao.Logger.warn("Unable to complete email entry")})},_email_format:function(e){return e[1]}}),Sao.Window.Email=Sao.class_(Object,{init:function(e,t,i,n){this.record=t,this.dialog=new Sao.Dialog(Sao.i18n.gettext("E-mail %1",e),"email","lg"),this.el=this.dialog.modal,this.dialog.content.addClass("form-horizontal");var o=this.dialog.body;function s(e,t,i){var n=jQuery("<div/>",{class:"form-group"}).appendTo(o),t=(jQuery("<label/>",{class:"control-label col-sm-1",text:t,for:"email-"+e}).appendTo(n),jQuery("<input/>",{type:"text",class:"form-control input-sm",id:"email-"+e}).appendTo(jQuery("<div/>",{class:"col-sm-11"}).appendTo(n)));return i&&t.attr("required",!0),t}this.to=s("to",Sao.i18n.gettext("To:"),!0),this.cc=s("cc",Sao.i18n.gettext("Cc:")),this.bcc=s("bcc",Sao.i18n.gettext("Bcc:"));for(const l of[this.to,this.cc,this.bcc])new Sao.Window.EmailEntry(l,this.record.model.session);this.subject=s("subject",Sao.i18n.gettext("Subject:"),!0);var e=jQuery("<div/>",{class:"panel panel-default"}).appendTo(o).append(jQuery("<div/>",{class:"panel-heading"}).append(Sao.common.richtext_toolbar())),a=(this.body=jQuery("<div>",{class:"email-richtext form-control input-sm mousetrap",contenteditable:!0,spellcheck:!0,id:"email-body"}).appendTo(jQuery("<div/>",{class:"panel-body"}).appendTo(e)),jQuery("<div/>",{class:"col-md-4"}).appendTo(o));jQuery("<label/>",{text:Sao.i18n.gettext("Reports")}).appendTo(a),this.print_actions={};for(const c of i){var r=jQuery("<input/>",{type:"checkbox"});jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>").text(Sao.i18n.gettext(c.name)).prepend(r)).appendTo(a),this.print_actions[c.id]=r}e=jQuery("<div/>",{class:"col-md-4"}).appendTo(o);jQuery("<label/>",{text:Sao.i18n.gettext("Attachments")}).appendTo(e),this.attachments=jQuery("<select/>",{class:"form-control input-sm",name:"attachments",multiple:!0}).appendTo(e),Sao.rpc({method:"model.ir.attachment.search_read",params:[[["resource","=",t.model.name+","+t.id],["OR",["data","!=",null],["file_id","!=",null]]],0,null,null,["rec_name"],t.get_context()]},t.model.session).then(e=>{for(const t of e)this.attachments.append(jQuery("<option/>",{value:JSON.stringify(t.id),text:t.rec_name}))}).fail(function(){Sao.Logger.error("Could not fetch attachment for",t)}),this.files=jQuery("<div/>",{class:"col-md-4"}).appendTo(o),jQuery("<label/>",{text:Sao.i18n.gettext("Files")}).appendTo(this.files),this._add_file_button(),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(" "+Sao.i18n.gettext("Cancel")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(this.dialog.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("Send")}).text(" "+Sao.i18n.gettext("Send")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-send")).appendTo(this.dialog.footer),this.dialog.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),this._fill_with(n),this.el.modal("show"),this.el.on("hidden.bs.modal",function(){jQuery(this).remove()})},_add_file_button:function(){var e=jQuery("<div/>").appendTo(this.files),t=jQuery("<input/>",{type:"file"}).appendTo(e),i=jQuery("<a/>",{class:"close",title:Sao.i18n.gettext("Remove File")}).append(jQuery("<span/>",{"aria-hidden":!0,text:"x"})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Remove")));i.hide(),i.appendTo(e),t.on("change",()=>{i.show(),this._add_file_button()}),i.click(function(){e.remove()})},get_files:function(){var n=[],o=[];return this.files.find("input[type=file]").each(function(e,t){var i;t.files.length&&(i=jQuery.Deferred(),n.push(i),Sao.common.get_file_data(t.files[0],function(e,t){o.push([t,e]),i.resolve()}))}),jQuery.when.apply(jQuery,n).then(function(){return o})},get_attachments:function(){var e=this.attachments.val();return e?e.map(function(e){return JSON.parse(e)}):[]},_fill_with:function(e){e=e?Sao.rpc({method:"model.ir.email.template.get",params:[e,this.record.id,{}]},this.record.model.session):Sao.rpc({method:"model.ir.email.template.get_default",params:[this.record.model.name,this.record.id,{}]},this.record.model.session);e.then(e=>{this.to.val((e.to||[]).join(", ")),this.cc.val((e.cc||[]).join(", ")),this.bcc.val((e.bcc||[]).join(", ")),this.subject.val(e.subject||""),this.body.html(Sao.HtmlSanitizer.sanitize(e.body||""));var t,i=e.reports||[];for(t in this.print_actions)this.print_actions[t].prop("checked",~i.indexOf(parseInt(t,10)))})},response:function(e){if("RESPONSE_OK"==e){var t,i=this.to.val(),n=this.cc.val(),o=this.bcc.val(),s=this.subject.val(),a=Sao.common.richtext_normalize(this.body.html()),r=[];for(t in this.print_actions)this.print_actions[t].prop("checked")&&r.push(t);var l=this.get_attachments(),c=this.record;this.get_files().then(function(e){return Sao.rpc({method:"model.ir.email.send",params:[i,n,o,s,a,e,[c.model.name,c.id],r,l,{}]},c.model.session)}).then(()=>{this.destroy()})}else this.destroy()},destroy:function(){this.el.modal("hide")}}),Sao.Window.CodeScanner=Sao.class_(Object,{init:function(e,t=!1){this.callback=e,this.loop=t,this.submitting=!1,this.dialog=new Sao.Dialog(Sao.i18n.gettext("Code Scanner"),"code-scanner","md"),this.el=this.dialog.modal,this.input=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap","aria-label":Sao.i18n.gettext("Code"),placeholder:Sao.i18n.gettext("Code")}).appendTo(jQuery("<div/>",{class:"col-sm-12"}).appendTo(this.dialog.body));function i(e){var t=e?(n.addClass("active"),n.attr("aria-pressed",e),Sao.common.ICONFACTORY.get_icon_url("tryton-sound-on").done(e=>{o.attr("src",e)})):(n.removeClass("active"),n.attr("aria-pressed",e),Sao.common.ICONFACTORY.get_icon_url("tryton-sound-off").done(e=>{o.attr("src",e)}));return localStorage.setItem("sao_code_scanner_sound",e),t}var n=jQuery("<button/>",{class:"btn btn-default pull-right",type:"button",title:Sao.i18n.gettext("Toggle Sound")}).prependTo(this.dialog.header),o=jQuery("<img/>",{class:"icon"}).appendTo(n),e=JSON.parse(localStorage.getItem("sao_code_scanner_sound")),t=i(e=null===e?!0:e);n.click(()=>i(!n.hasClass("active"))),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Close")}).text(" "+Sao.i18n.gettext("Close")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-close")).click(()=>{this.response("RESPONSE_CLOSE")}).appendTo(this.dialog.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(" "+Sao.i18n.gettext("OK")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-ok")).appendTo(this.dialog.footer),this.dialog.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),this.el.on("shown.bs.modal",()=>{this.input.on("blur",this._keep_focus),this.input.focus()}),this.el.on("hidden.bs.modal",function(){jQuery(this).remove()}),t.then(()=>this.el.modal("show"))},_play_sound:function(e){JSON.parse(localStorage.getItem("sao_code_scanner_sound"))&&Sao.common.play_sound(e)},_keep_focus:function(){setTimeout(()=>this.focus(),1)},response:function(e){if(!this.submitting){if("RESPONSE_OK"==e){var t=this.input.val();if(this.input.val(""),t)return this.submitting=!0,this.input.off("blur"),this.callback(t).always(()=>this.submitting=!1).then(e=>{this._play_sound("success"),this.loop&&e||this.destroy(),this.input.on("blur",this._keep_focus),this.input.focus()},e=>{this._play_sound("danger"),"UserError"==e[0]?Sao.common.warning.run(e[1][1],e[1][0]):Sao.common.error.run(e[0],e[1]),this.destroy()})}this.loop&&"RESPONSE_OK"==e||this.destroy()}},destroy:function(){this.el.modal("hide")}})}(),!function(){"use strict";Sao.Wizard=Sao.class_(Object,{init:function(e){this.widget=jQuery("<div/>",{class:"wizard"}),this.name=e||Sao.i18n.gettext("Wizard"),this.action_id=null,this.id=null,this.ids=null,this.action=null,this.context=null,this.states={},this.session_id=null,this.start_state=null,this.end_state=null,this.screen=null,this.screen_state=null,this.state=null,this.session=Sao.Session.current_session,this.__processing=!1,this.__waiting_response=!1,this.info_bar=new Sao.Window.InfoBar},run:function(e){this.action=e.action,this.action_id=e.data.action_id,this.id=e.data.id,this.ids=e.data.ids,this.model=e.data.model,this.context=jQuery.extend({},e.context),this.context.active_id=this.id,this.context.active_ids=this.ids,this.context.active_model=this.model,this.context.action_id=this.action_id,Sao.rpc({method:"wizard."+this.action+".create",params:[this.session.context]},this.session).then(e=>{this.session_id=e[0],this.start_state=this.state=e[1],this.end_state=e[2],this.process()},()=>{this.destroy()})},process:function(){this.__processing||this.__waiting_response||function(){var e,t;this.state==this.end_state?this.end():(e=jQuery.extend({},this.context),t={},this.screen&&(t[this.screen_state]=this.screen.get_on_change_value()),Sao.rpc({method:"wizard."+this.action+".execute",params:[this.session_id,t,this.state,e]},this.session).then(i=>{i.view?(this.clean(),e=i.view,this.update(e.fields_view,e.buttons),this.screen.new_(!1).then(()=>{this.screen.current_record.set_default(e.defaults||{}).then(()=>{this.screen.current_record.set(e.values||{}),this.update_buttons(),this.screen.set_cursor()})}),this.screen_state=e.state,this.__waiting_response=!0):this.state=this.end_state;var e,t=()=>{if(i.actions)for(const t of i.actions){var e=jQuery.extend({},this.context);delete e.active_id,delete e.active_ids,delete e.active_model,delete e.action_id,Sao.Action.execute(t[0],t[1],e)}};this.state==this.end_state?this.end().then(t):t(),this.__processing=!1},e=>{this.__processing=!1}))}.call(this)},destroy:function(e){},end:function(){return Sao.rpc({method:"wizard."+this.action+".delete",params:[this.session_id,this.session.context]},this.session).then(e=>{this.destroy(e)}).fail(()=>{Sao.Logger.warn("Unable to delete session %s of wizard %s",this.session_id,this.action)})},clean:function(){this.widget.empty(),this.states={}},response:function(e){this.__waiting_response=!1,this.screen.current_view.set_value(),e.validate&&!this.screen.current_record.validate(null,null,null,!0)?(this.screen.display(!0),this.info_bar.add(this.screen.invalid_message(),"danger")):(this.info_bar.clear(),this.state=e.state,this.process())},_get_button:function(e){var t="btn-default",t=(e.default?t="btn-primary":e.state==this.end_state&&(t="btn-link"),new Sao.common.Button(e,void 0,void 0,t));return this.states[e.state]=t},record_modified:function(){this.update_buttons(),this.info_bar.refresh()},update_buttons:function(){var e,t=this.screen.current_record;for(e in this.states)this.states[e].set_state(t)},update:function(e,t){for(const i of t)this._get_button(i);this.screen&&this.screen.windows.splice(this.screen.windows.indexOf(this),1),this.screen=new Sao.Screen(e.model,{mode:[],context:this.context}),this.screen.add_view(e),this.screen.switch_view(),this.screen.windows.push(this),this.header.append(jQuery("<h4/>",{class:"model-title",title:this.name}).text(Sao.common.ellipsize(this.name,80))),this.widget.append(this.screen.screen_container.el)}}),Sao.Wizard.create=function(e){var t,i;e.window?(t=new Sao.Wizard.Form(e.name),i=new Sao.Tab.Wizard(t),Sao.Tab.add(i)):t=new Sao.Wizard.Dialog(e.name),t.run(e)},Sao.Wizard.Form=Sao.class_(Sao.Wizard,{init:function(e){Sao.Wizard.Form._super.init.call(this,e),this.tab=null,this.header=jQuery("<div/>",{class:"modal-header"}),this.form=jQuery("<div/>",{class:"wizard-form"}).append(this.header).append(this.widget),this.footer=jQuery("<div/>",{class:"modal-footer"}).appendTo(this.form)},clean:function(){Sao.Wizard.Form._super.clean.call(this),this.header.empty(),this.footer.empty()},_get_button:function(e){var t=Sao.Wizard.Form._super._get_button.call(this,e);return this.footer.append(t.el),t.el.click(()=>{this.response(e)}),t},destroy:function(e){switch(Sao.Wizard.Form._super.destroy.call(this,e),e){case"reload menu":Sao.Session.current_session.reload_context().then(function(){Sao.menu()});break;case"reload context":Sao.Session.current_session.reload_context()}},end:function(){return Sao.Wizard.Form._super.end.call(this).always(()=>this.tab.close())}}),Sao.Wizard.Dialog=Sao.class_(Sao.Wizard,{init:function(e){Sao.Wizard.Dialog._super.init.call(this,e);e=new Sao.Dialog(e,"wizard-dialog","md",!1);this.dialog=e.modal,this.header=e.header,this.content=e.content,this.footer=e.footer,this.dialog.on("keydown",e=>{e.which==Sao.common.ESC_KEYCODE&&(e.preventDefault(),this.end_state in this.states)&&this.response(this.states[this.end_state].attributes)}),e.body.append(this.widget).append(this.info_bar.el)},clean:function(){Sao.Wizard.Dialog._super.clean.call(this),this.header.empty(),this.footer.empty()},_get_button:function(t){var e=Sao.Wizard.Dialog._super._get_button.call(this,t);return this.footer.append(e.el),t.default?(this.content.unbind("submit"),this.content.submit(e=>{this.response(t),e.preventDefault()}),e.el.attr("type","submit")):e.el.click(()=>{this.response(t)}),e},update:function(e,t){this.content.unbind("submit"),Sao.Wizard.Dialog._super.update.call(this,e,t),this.show()},destroy:function(n){Sao.Wizard.Dialog._super.destroy.call(this,n);var e=()=>{this.dialog.remove();var e=jQuery(".wizard-dialog").filter(":visible")[0],t=!1,i=!(e=e||Sao.Tab.tabs.get_current())||!this.model||Sao.main_menu_screen&&Sao.main_menu_screen.model_name==this.model?(t=!0,Sao.main_menu_screen):e.screen;i&&(e=jQuery.when(),i.current_record&&!t&&(t=i.model_name==this.model?this.ids:[i.current_record.id],e=i.reload(t,!0)),n)&&e.then(function(){i.client_action(n)})};(this.dialog.data("bs.modal")||{}).isShown?(this.dialog.on("hidden.bs.modal",e),this.dialog.modal("hide")):e()},show:function(){var e=this.screen.current_view;if("form"==e.view_type){var t=!1;for(const i of e.get_fields()){for(const n of e.widgets[i])if(n.expand){t=!0;break}if(t)break}}else t=!0;t?this.dialog.find(".modal-dialog").removeClass("modal-md modal-sm").addClass("modal-lg"):this.dialog.find(".modal-dialog").removeClass("modal-lg modal-sm").addClass("modal-md"),this.dialog.modal("show")},hide:function(){this.dialog.modal("hide")},state_changed:function(){this.process()}})}(),!function(){"use strict";Sao.View.BoardXMLViewParser=Sao.class_(Sao.View.FormXMLViewParser,{_parse_board:function(e,t){var i=new Sao.View.Form.Container(Number(e.getAttribute("col")||4));if(this.view.containers.push(i),this.view.el.append(i.el),this.parse_child(e,i),0<this._containers.length)throw"AssertionError"},_parse_action:function(e,t){var i;void 0===t.yexpand&&(t.yexpand=!0),void 0===t.yfill&&(t.yfill=!0),i=new Sao.View.Board.Action(this.view,t),this.view.actions.push(i),this.container.add(i,t)}}),Sao.View.Board=Sao.class_(Object,{xml_parser:Sao.View.BoardXMLViewParser,init:function(e,t){var i;this.context=t,this.actions=[],this.containers=[],this.state_widgets=[],this.el=jQuery("<div/>",{class:"board"}),new this.xml_parser(this,null,{}).parse(e.children()[0]),i=[];for(const n of this.actions)i.push(n.action_prm);this.actions_prms=jQuery.when.apply(jQuery,i)},reload:function(){for(var e=0;e<this.actions.length;e++)this.actions[e].display();var t,i=[];for(t of this.state_widgets.toReversed()){var n=t.set_state(null);n&&i.push(n)}for(const o of this.containers)o.set_grid_template();jQuery.when.apply(jQuery,i).done(()=>{for(const e of this.containers)e.set_grid_template()})},active_changed:function(e){for(const t of this.actions)t!==e&&t.update_domain(this.actions)}}),Sao.View.Board.Action=Sao.class_(Object,{init:function(e,a){var r=Sao.Session.current_session,e=(this.name=a.name,this.view=e,this.el=jQuery("<div/>",{class:"board-action panel panel-default"}),this.title=jQuery("<div/>",{class:"panel-heading"}),this.el.append(this.title),this.body=jQuery("<div/>",{class:"panel-body"}),this.el.append(this.body),new Sao.Model("ir.action.act_window"));this.action_prm=e.execute("get",[this.name],{}),this.action_prm.done(e=>{var t={};if(this.action=e,t.view_ids=[],t.mode=null,jQuery.isEmptyObject(e.views))jQuery.isEmptyObject(e.view_id)||(t.view_ids=[e.view_id[0]]);else{t.view_ids=[],t.mode=[];for(const o of e.views)t.view_ids.push(o[0]),t.mode.push(o[1])}"pyson_domain"in this.action||(this.action.pyson_domain="[]");var i={},n=((i=jQuery.extend(i,r.context))._user=r.user_id,new Sao.PYSON.Decoder(i));t.context=jQuery.extend({},this.view.context,n.decode(e.pyson_context||"{}")),(i=jQuery.extend(i,t.context)).context=i,n=new Sao.PYSON.Decoder(i),t.order=n.decode(e.pyson_order),t.search_value=n.decode(e.pyson_search_value||"[]"),t.tab_domain=[];for(const s of e.domains)t.tab_domain.push([s[0],n.decode(s[1]),s[2]]);t.context_model=e.context_model,t.context_domain=e.context_domain,null!==e.limit?t.limit=e.limit:t.limit=Sao.config.limit,this.context=i,this.domain=[],this.update_domain([]),t.row_activate=this.row_activate.bind(this),this.screen=new Sao.Screen(this.action.res_model,t),a.string?this.title.text(a.string):this.title.text(this.action.name),this.screen.switch_view().done(()=>{this.body.append(this.screen.screen_container.el),this.screen.search_filter()})})},row_activate:function(){var e;this.screen.current_record&&("tree"==this.screen.current_view.view_type&&1==this.screen.current_view.attributes.keyword_open?(e=this.screen.current_view.selected_records.map(function(e){return e.id}),Sao.Action.exec_keyword("tree_open",{model:this.screen.model_name,id:this.screen.current_record.id,ids:e},jQuery.extend({},this.screen.group._context),!1)):new Sao.Window.Form(this.screen,e=>{e?this.screen.current_record.save():this.screen.current_record.cancel()},{title:this.title.text()}))},display:function(){this.screen.search_filter(this.screen.screen_container.get_text())},record_message:function(){this.view.active_changed(this)},get active(){return this.screen&&this.screen.current_record?{active_id:this.screen.current_record.id,active_ids:this.screen.selected_records.map(function(e){return e.id})}:{active_id:null,active_ids:[]}},update_domain:function(e){var t,i,n,o=jQuery.extend({},this.context);for(o._actions={},t=0,i=e.length;t<i;t++)o._actions[e[t].name]=e[t].active;n=new Sao.PYSON.Decoder(o).decode(this.action.pyson_domain),Sao.common.compare(this.domain,n)||(this.domain.splice(0,this.domain.length),jQuery.extend(this.domain,n),this.screen&&this.display())}})}(),!function(){"use strict";Sao.Bus={},Sao.Bus.id=Sao.common.uuid4(),Sao.Bus.channels=["client:"+Sao.Bus.id],Sao.Bus.listen=function(n,o){o=o||1;var e,s=Sao.Session.current_session;s&&((e=jQuery.ajax({headers:{Authorization:"Session "+s.get_auth()},contentType:"application/json",data:JSON.stringify({last_message:n,channels:Sao.Bus.channels}),dataType:"json",url:"/"+s.database+"/bus",type:"POST",timeout:Sao.config.bus_timeout})).done(function(e){Sao.Session.current_session==s&&(e.message&&(n=e.message.message_id,Sao.Logger.info("poll channels %s with last message",Sao.Bus.channels,n),Sao.Bus.handle(e.message)),Sao.Bus.listen(n,1))}),e.fail(function(e,t,i){Sao.Session.current_session==s&&("timeout"===i?Sao.Bus.listen(n,1):501==e.status?Sao.Logger.info("Bus not supported"):(Sao.Logger.error("An exception occured while connection to the bus. Sleeping for %s seconds",o,i),window.setTimeout(Sao.Bus.listen,Math.min(1e3*o,Sao.config.bus_timeout),n,2*o)))}))},Sao.Bus.handle=function(e){if("notification"===e.type){try{if("granted"!=Notification.permission)return void!void 0}catch(e){return void!Sao.Logger.error(e.message,e.stack)}new Notification(e.title,{body:e.body||""})}}}(),!function(){"use strict";var i={translate_view:function(e){e=e.model;Sao.Tab.create({model:"ir.translation",domain:[["model","=",e]],mode:["tree","form"],name:Sao.i18n.gettext("Translate view")})},get_plugins:function(e){var t=Sao.common.MODELACCESS.get("ir.translation");return t.read&&t.write?[[Sao.i18n.gettext("Translate view"),i.translate_view]]:[]}};Sao.Plugins.push(i)}(),!function(){"use strict";var r={B:!0,BODY:!0,BR:!0,DIV:!0,FONT:!0,I:!0,U:!0},l={align:!0,color:!0,face:!0,size:!0};Sao.HtmlSanitizer={},Sao.HtmlSanitizer.sanitize=function(e){if(""==(e=e.trim()))return"";if("<br>"==e)return"";var t=document.createElement("iframe");if(void 0===t.sandbox)return Sao.Logger.warn("Your browser do not support sandboxed iframes, unable to sanitize HTML."),e;t.sandbox="allow-same-origin",t.style.display="none",document.body.appendChild(t);var a=t.contentDocument||t.contentWindow.document;null==a.body&&a.write("<body></body>"),a.body.innerHTML=e;e=function e(t){if(t.nodeType==Node.TEXT_NODE)i=t.cloneNode(!0);else if(t.nodeType==Node.ELEMENT_NODE&&r[t.tagName]){if("BR"!=t.tagName&&""==t.innerHTML.trim())return document.createDocumentFragment();for(var i=a.createElement(t.tagName),n=0;n<t.attributes.length;n++){var o=t.attributes[n];l[o.name]&&i.setAttribute(o.name,o.value)}for(n=0;n<t.childNodes.length;n++){var s=e(t.childNodes[n]);i.appendChild(s,!1)}}else i=document.createDocumentFragment(),"SCRIPT"!=t.tagName&&(i.textContent=t.textContent);return i}(a.body);return document.body.removeChild(t),e.innerHTML.replace(/<br[^>]*>(\S)/g,"<br>\n$1").replace(/div><div/g,"div>\n<div")}}();
|
|
4
|
+
var Sao={__version__:"7.0.23"};function eval_pyson(value){with(Sao.PYSON.eval)return eval("("+value+")")}!function(){"use strict";"contains"in String.prototype||(String.prototype.contains=function(e,t){return-1!==String.prototype.indexOf.call(this,e,t)}),String.prototype.startsWith||Object.defineProperty(String.prototype,"startsWith",{enumerable:!1,configurable:!1,writable:!1,value:function(e,t){return this.indexOf(e,t=t||0)===t}}),String.prototype.endsWith||Object.defineProperty(String.prototype,"endsWith",{enumerable:!1,configurable:!1,writable:!1,value:function(e,t){t=t||this.length,t-=e.length;e=this.lastIndexOf(e);return-1!==e&&e===t}}),String.prototype.padEnd||(String.prototype.padEnd=function(e,t){return e>>=0,t=String(void 0!==t?t:" "),this.length>e?String(this):((e-=this.length)>t.length&&(t+=t.repeat(e/t.length)),String(this)+t.slice(0,e))}),String.prototype.padStart||(String.prototype.padStart=function(e,t){return e>>=0,t=String(void 0!==t?t:" "),this.length>e?String(this):((e-=this.length)>t.length&&(t+=t.repeat(e/t.length)),t.slice(0,e)+String(this))}),Array.prototype.some||(Array.prototype.some=function(e){if(null===this)throw new TypeError;var t,i,n=Object(this),o=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(t=arguments[1],i=0;i<o;i++)if(i in n&&e.call(t,n[i],i,n))return!0;return!1}),Array.from||(Array.from=function(e){var t=[];for(const i of e)t.push(i);return t}),Sao.setdefault=function(e,t,i){return e.hasOwnProperty(t)||(e[t]=i),e[t]};try{document.execCommand("styleWithCSS",!1,!1)}catch(e){}try{document.execCommand("useCSS",!1,!0)}catch(e){}jQuery.fn.extend({uniqueId:(e=0,function(){return this.each(function(){this.id||(this.id="ui-id-"+ ++e)})})}),window.onbeforeunload=function(e){var t;if(Sao.main_menu_screen&&Sao.main_menu_screen.save_tree_state(!0),Sao.Tab.tabs.length)return t=Sao.i18n.gettext("Are your sure to leave?"),e.returnValue=t},Sao.class_=function(e,t){function i(){if(!(this instanceof i))throw new Error("Constructor function requires new operator");this.Class=i,this.init&&this.init.apply(this,arguments)}if(i.prototype=Object.create(e.prototype),i._super=e.prototype,t)for(var n in t)Object.defineProperty(i.prototype,n,Object.getOwnPropertyDescriptor(t,n));function o(e){return i.apply(this,e)}return o.prototype=i.prototype,i.new_=function(e){return new o(e)},i},Sao.Logging=Sao.class_(Object,{init:function(){this.level=Sao.Logging.ERROR},set_level:function(e){this.level=e},_log:function(e,t,i){this.level<=e&&t.apply(console,i)},debug:function(){this._log(Sao.Logging.DEBUG,console.log,arguments)},info:function(){this._log(Sao.Logging.INFO,console.info,arguments)},warn:function(){this._log(Sao.Logging.WARNING,console.warn,arguments)},error:function(){this._log(Sao.Logging.ERROR,console.error,arguments)},critical:function(){this._log(Sao.Logging.CRITICAL,console.error,arguments)},assert:function(){this.level<=Sao.Logging.DEBUG&&console.assert.apply(console,arguments)}}),Sao.Logging.CRITICAL=50,Sao.Logging.ERROR=40,Sao.Logging.WARNING=30,Sao.Logging.INFO=20,Sao.Logging.DEBUG=10,Sao.Logging.NOTSET=0,Sao.Logger=new Sao.Logging,Sao.Decimal=Number;var e,t=moment.prototype.toString,i=(moment.prototype.toString=function(){return this.isDate?this.format("YYYY-MM-DD"):this.isDateTime?this.milliseconds()?this.format("YYYY-MM-DD HH:mm:ss.SSSSSS"):this.format("YYYY-MM-DD HH:mm:ss"):this.isTime?this.milliseconds()?this.format("HH:mm:ss.SSSSSS"):this.format("HH:mm:ss"):t.call(this)},Sao.Date=function(e,t,i){var n;return void 0===t?(n=moment(e),e=void 0):n=moment(),n.year(e),n.month(t),n.date(i),n.set({hour:0,minute:0,second:0,millisecond:0}),n.isDate=!0,n},Sao.Date.min=moment(new Date(864e5*(1-1e8))),Sao.Date.min.set({hour:0,minute:0,second:0,millisecond:0}),Sao.Date.min.isDate=!0,Sao.Date.max=moment(new Date(864e13)),Sao.Date.max.set({hour:0,minute:0,second:0,millisecond:0}),Sao.Date.max.isDate=!0,Sao.DateTime=function(e,t,i,n=0,o=0,s=0,a=0,r=!1){var l;return void 0===t?(l=moment(e),e=void 0):l=moment(),r&&l.utc(),l.year(e),l.month(t),l.date(i),void 0!==t&&(l.hour(n),l.minute(o),l.second(s),l.milliseconds(a)),l.isDateTime=!0,l.local(),l.todate=function(){return Sao.Date(this.year(),this.month(),this.date())},l.totime=function(){return Sao.Time(this.hour(),this.minute(),this.second(),this.millisecond())},l},Sao.DateTime.combine=function(e,t){return Sao.DateTime(e.year(),e.month(),e.date(),t.hour(),t.minute(),t.second(),t.millisecond())},Sao.DateTime.min=moment(new Date(-864e13)).local(),Sao.DateTime.min.isDateTime=!0,Sao.DateTime.max=moment(new Date(864e13)).local(),Sao.DateTime.max.isDateTime=!0,Sao.Time=function(e,t,i,n){e=moment({hour:e,minute:t,second:i,millisecond:n||0});return e.isTime=!0,e},Sao.TimeDelta=function(e,t,i,n,o,s){e=moment.duration({days:e,seconds:t,milliseconds:i,minutes:n,hours:o,weeks:s});return e.isTimeDelta=!0,e},Sao.config={},Sao.config.limit=1e3,Sao.config.display_size=20,Sao.__version__.split(".").slice(0,2)),i=parseInt(i[1],10)%2?"latest":i.join("."),s=(Sao.config.doc_url="https://docs.tryton.org/"+i,Sao.config.bug_url="https://bugs.tryton.org/",Sao.config.title="Tryton",Sao.config.icon_colors="#267f82,#3e4950,#e78e42".split(","),Sao.config.calendar_colors="#fff,#267f82".split(","),Sao.config.graph_color="#267f82",Sao.config.bus_timeout=6e5,Sao.config.image_max_size=Math.pow(10,6),Sao.i18n=i18n(),Sao.i18n.setlang=function(i){return i=i||(navigator.language||navigator.browserLanguage||navigator.userLanguage||"en").replace("-","_"),jQuery("html").attr("lang",i),Sao.i18n.setLocale(i),moment.locale(i.slice(0,2)),jQuery.getJSON("locale/"+i+".json").then(function(e){for(var t in e[""].language||(e[""].language=i),e[""]["plural-forms"]||(e[""]["plural-forms"]="nplurals=2; plural=(n!=1);"),e)""!==t&&(e[t]=2==e[t].length?e[t][1]:e[t].slice(1));Sao.i18n.loadJSON(e)},function(){if(~i.indexOf("_"))return Sao.i18n.setlang(i.split("_").slice(0,-1).join("_"))})},Sao.i18n.getlang=function(){return Sao.i18n.getLocale()},Sao.i18n.BC47=function(e){return e.replace("_","-")},Sao.i18n.set_direction=function(e){Sao.i18n.rtl="rtl"===e,jQuery("html").attr("dir",e),jQuery(".row-offcanvas").removeClass("row-offcanvas-left row-offcanvas-right").addClass(Sao.i18n.rtl?"row-offcanvas-right":"row-offcanvas-left")},Sao.i18n.locale={},Sao.BOM_UTF8="\ufeff",Sao.get_preferences=function(){var e=Sao.Session.current_session;return e.reload_context().then(function(){return Sao.rpc({method:"model.res.user.get_preferences",params:[!1,{}]},e).then(function(n){var e=[];return e.push(Sao.common.MODELACCESS.load_models()),e.push(Sao.common.ICONFACTORY.load_icons()),e.push(Sao.common.MODELHISTORY.load_history()),e.push(Sao.common.MODELNOTIFICATION.load_names()),e.push(Sao.common.VIEW_SEARCH.load_searches()),jQuery.when.apply(jQuery,e).then(function(){for(const i of n.actions||[])Sao.Action.execute(i,{},null,{});Sao.set_title();var e=n.language!=Sao.i18n.getLocale(),t=jQuery.Deferred();return Sao.i18n.setlang(n.language).always(function(){e&&Sao.user_menu(n),t.resolve(n)}),Sao.i18n.set_direction(n.language_direction),Sao.i18n.locale=n.locale,Sao.common.MODELNAME.clear(),t})})})},Sao.set_title=function(e){e=[e,Sao.config.title];document.title=e.filter(function(e){return e}).join(" - "),jQuery("#title").text(Sao.config.title)},Sao.set_url=function(e,t){var i=Sao.Session.current_session;i&&(i="#"+i.database,e&&(i+="/"+e),window.location=i),Sao.set_title(t)},window.onhashchange=function(){var e=Sao.Session.current_session;if(e){var t,i,e="#"+e.database;if(window.location.hash==e)t="";else{if(!window.location.hash.startsWith(e+"/"))return;t=window.location.hash.substr(e.length+1)}if(t){t=decodeURIComponent(t);for(const i of Sao.Tab.tabs)if(decodeURIComponent(i.get_url())==t)return void i.show();Sao.open_url()}else(i=Sao.Tab.tabs.get_current())&&Sao.set_url(i.get_url(),i.name)}},Sao.open_url=function(e){function i(e){return Sao.rpc.convertJSONObject(jQuery.parseJSON(e))}var t,n,o=(e=void 0===e?window.location.hash.substr(1):e).indexOf(";"),s={};if(0<=o){n=e.substring(0,o);for(const a of e.substring(o+1).split("&"))a&&(t=a.split("=").map(decodeURIComponent),s[t[0]]=t[1])}else n=e;switch((n=n.split("/").slice(1)).shift()){case"model":!function(e){var t={};if(t.model=e.shift(),t.model){try{t.view_ids=i(s.views||"[]"),void 0!==s.limit&&(t.limit=i(s.limit||"null")),t.name=i(s.name||'""'),t.search_value=i(s.search_value||"[]"),t.domain=i(s.domain||"[]"),t.context=i(s.context||"{}"),t.context_model=s.context_model,t.tab_domain=i(s.tab_domain||"[]")}catch(e){return}e=e.shift();if(e){if(e=Number(e),isNaN(e))return;t.res_id=e,t.mode=["form","tree"]}try{Sao.Tab.create(t)}catch(e){}}}(n);break;case"wizard":!function(e){var t={};if(t.action=e[0],t.action){try{t.data=i(s.data||"{}"),t.direct_print=i(s.direct_print||"false"),t.name=i(s.name||'""'),t.window=i(s.window||"false"),t.context=i(s.context||"{}")}catch(e){return}try{Sao.Wizard.create(t)}catch(e){}}}(n);break;case"report":!function(e){var t={};if(t.name=e[0],t.name){try{t.data=i(s.data||"{}"),t.direct_print=i(s.direct_print||"false"),t.context=i(s.context||"{}")}catch(e){return}try{Sao.Action.exec_report(t)}catch(e){}}}(n);break;case"url":!function(){var e;try{e=i(s.url||"false")}catch(e){return}e&&window.open(e,"_blank","noreferrer,noopener")}()}},Sao.login=function(){Sao.set_title(),Sao.i18n.setlang().always(function(){Sao.Session.server_version().then(function(e){JSON.stringify(e.split(".").slice(0,2))!==JSON.stringify(Sao.__version__.split(".").slice(0,2))?Sao.common.warning.run(Sao.i18n.gettext("Incompatible version of the server."),Sao.i18n.gettext("Version mismatch")):Sao.Session.get_credentials().then(function(e){return(Sao.Session.current_session=e).reload_context()}).then(Sao.get_preferences).then(function(e){Sao.menu(e),Sao.user_menu(e),Sao.open_url(),Sao.Bus.listen()})},function(){Sao.common.warning.run(Sao.i18n.gettext("Could not connect to the server."),Sao.i18n.gettext("Connection error"))})})},Sao.logout=function(){var e=Sao.Session.current_session;e&&e.session||(Sao.main_menu_screen=null),Sao.Tab.tabs.close(!0).done(function(){jQuery("#user-preferences").empty(),jQuery("#global-search").empty(),jQuery("#menu").empty(),e.do_logout().always(Sao.login),Sao.set_title()})},Sao.preferences=function(){return Sao.Tab.tabs.close(!0).then(function(){jQuery("#user-preferences").empty(),jQuery("#global-search").empty(),jQuery("#menu").empty(),new Sao.Window.Preferences(function(){Sao.Session.current_session.reset_context(),Sao.get_preferences().then(function(e){Sao.menu(e),Sao.user_menu(e)})})})},Sao.favorites_menu=function(){var e,t,s;jQuery(window).click(function(){Sao.favorites_menu_clear()}),jQuery("#user-favorites").children(".dropdown-menu").length||(t=Sao.main_menu_screen.model_name+".favorite",e=Sao.Session.current_session,t={method:"model."+t+".get"},s=jQuery("<ul/>",{class:"dropdown-menu","aria-expanded":"false","aria-labelledby":"user-favorites"}),jQuery("#user-favorites").append(s),Sao.rpc(t,e).then(function(e){e.forEach(function(e){var t=jQuery("<a/>",{href:"#"}),i=e[0],n=jQuery("<li/>",{role:"presentation"}),o=Sao.common.ICONFACTORY.get_icon_img(e[2],{class:"favorite-icon"});t.append(o),n.append(t),t.append(e[1]),t.click(function(e){e.preventDefault(),Sao.favorites_menu_clear(),Sao.Action.exec_keyword("tree_open",{model:Sao.main_menu_screen.model_name,id:i})}),s.append(n)}),s.append(jQuery("<li/>",{class:"divider"})),jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{href:"#"}).click(function(e){e.preventDefault(),Sao.favorites_menu_clear(),Sao.Tab.create({model:Sao.main_menu_screen.model_name+".favorite",mode:["tree","form"],name:Sao.i18n.gettext("Favorites")})}).text(Sao.i18n.gettext("Manage..."))).appendTo(s)}))},Sao.favorites_menu_clear=function(){jQuery("#user-favorites").children(".dropdown-menu").remove()},Sao.user_menu=function(e){jQuery("#user-preferences").empty();var t=jQuery("<a/>",{href:"#",title:e.status_bar}).click(function(e){e.preventDefault(),t.prop("disabled",!0),Sao.preferences().then(()=>t.prop("disabled",!1))}).text(e.status_bar),e=(jQuery("#user-preferences").append(t),e.avatar_badge_url&&t.prepend(jQuery("<img/>",{src:e.avatar_badge_url+"?s=15",class:"img-circle img-badge"})),e.avatar_url&&t.prepend(jQuery("<img/>",{src:e.avatar_url+"?s=30",class:"img-circle"})),Sao.i18n.gettext("Logout"));jQuery("#user-logout > a").attr("title",e).attr("aria-label",e).off().click(Sao.logout).find("span:not(.icon)").text(e)},Sao.main_menu_row_activate=function(){var e=Sao.main_menu_screen;e.get_id()&&Sao.Action.exec_keyword("tree_open",{model:e.model_name,id:e.get_id()},null,!1)},Sao.menu=function(e){var t,i,n,o;e?(e=(n=new Sao.PYSON.Decoder).decode(e.pyson_menu),t=!1,jQuery.isEmptyObject(e.views)?e.view_id&&(t=[e.view_id[0]]):t=e.views.map(function(e){return e[0]}),i=(n=new Sao.PYSON.Decoder(Sao.Session.current_session.context)).decode(e.pyson_context||"{}"),n=n.decode(e.pyson_domain),o=new Sao.Tab.Form(e.res_model,{mode:["tree"],view_ids:t,domain:n,context:i,selection_mode:Sao.common.SELECTION_NONE,limit:null,row_activate:Sao.main_menu_row_activate}),Sao.main_menu_screen=o.screen,Sao.main_menu_screen.switch_callback=null,Sao.Tab.tabs.splice(Sao.Tab.tabs.indexOf(o),1),o.view_prm.done(function(){var e=o.screen.current_view,e=(e.table.removeClass("table table-bordered"),e.table.addClass("no-responsive"),e.table.find("thead").hide(),e.table.find("colgroup > col.tree-menu").css("width",0),new Sao.GlobalSearch),e=(jQuery("#global-search").empty(),jQuery("#global-search").append(e.el),jQuery("#menu").empty(),jQuery("#menu").append(o.screen.screen_container.content_box.detach()),new s(o.screen.model.fields.favorite));o.screen.views[0].table.find("> colgroup").append(e.col),o.screen.views[0].table.find("> thead > tr").append(e.header),o.screen.views[0].columns.push(e)})):(e=Sao.Session.current_session,Sao.rpc({method:"model.res.user.get_preferences",params:[!1,{}]},e).then(Sao.menu))},Sao.main_menu_screen=null,Sao.class_(Object,{init:function(e){this.field=e,this.col=jQuery("<col/>",{class:"favorite"}),this.header=jQuery("<th/>"),this.footers=[],this.attributes=jQuery.extend({},this.field.description),this.attributes.name=this.field.name},get_cell:function(){return jQuery("<img/>",{class:"column-affix",tabindex:0})},render:function(t,i){return i=i||this.get_cell(),t.load(this.field.name).done(()=>{var e;null!==t._values.favorite&&(e="tryton-star",t._values.favorite||(e+="-border"),i.data("star",Boolean(t._values.favorite)),Sao.common.ICONFACTORY.get_icon_url(e).then(e=>{i.attr("src",e)}),i.click({record:t,button:i},this.favorite_click))}),i},set_visible:function(){},get_visible:function(){return!0},favorite_click:function(e){e.stopImmediatePropagation();var t=e.data.button,i=t.data("star"),n=i?(o="tryton-star-border","unset"):(o="tryton-star","set"),i=(t.data("star",!i),Sao.common.ICONFACTORY.get_icon_url(o).then(function(e){t.attr("src",e)}),Sao.main_menu_screen.model_name+".favorite"),o=Sao.Session.current_session,i={method:"model."+i+"."+n,params:[e.data.record.id,o.context]};Sao.rpc(i,o),Sao.favorites_menu_clear()}}));function l(){return[{shortcut:"alt+n",label:Sao.i18n.gettext("New"),id:"new_"},{shortcut:"ctrl+s",label:Sao.i18n.gettext("Save"),id:"save"},{shortcut:"ctrl+l",label:Sao.i18n.gettext("Switch"),id:"switch_"},{shortcut:"ctrl+r",label:Sao.i18n.gettext("Reload/Undo"),id:"reload"},{shortcut:"ctrl+shift+d",label:Sao.i18n.gettext("Duplicate"),id:"copy"},{shortcut:"ctrl+d",label:Sao.i18n.gettext("Delete"),id:"delete_"},{shortcut:"ctrl+up",label:Sao.i18n.gettext("Previous"),id:"previous"},{shortcut:"ctrl+down",label:Sao.i18n.gettext("Next"),id:"next"},{shortcut:"ctrl+f",label:Sao.i18n.gettext("Search"),id:"search"},{shortcut:"alt+w",label:Sao.i18n.gettext("Close Tab"),id:"close"},{shortcut:"ctrl+shift+t",label:Sao.i18n.gettext("Attachment"),id:"attach"},{shortcut:"ctrl+shift+o",label:Sao.i18n.gettext("Note"),id:"note"},{shortcut:"ctrl+e",label:Sao.i18n.gettext("Action"),id:"action"},{shortcut:"ctrl+shift+r",label:Sao.i18n.gettext("Relate"),id:"relate"},{shortcut:"ctrl+p",label:Sao.i18n.gettext("Print"),id:"print"},{shortcut:"ctrl+shift+e",label:Sao.i18n.gettext("E-Mail"),id:"email"},{shortcut:"alt+shift+tab",label:Sao.i18n.gettext("Previous tab"),callback:function(){Sao.Tab.previous_tab()}},{shortcut:"alt+tab",label:Sao.i18n.gettext("Next tab"),callback:function(){Sao.Tab.next_tab()}},{shortcut:"ctrl+k",label:Sao.i18n.gettext("Global search"),callback:function(){jQuery("#main_navbar:hidden").collapse("show"),jQuery("#global-search-entry").focus()}},{shortcut:"f1",label:Sao.i18n.gettext("Show this help"),callback:function(){var e,t=new Sao.Dialog(Sao.i18n.gettext("Help"),"help-dialog","md",!0,Sao.__version__),i=(jQuery("<button>",{class:"close","data-dismiss":"modal","aria-label":Sao.i18n.gettext("Close")}).append(jQuery("<span>",{"aria-hidden":!0}).append("×")).prependTo(t.header),jQuery("<a/>",{class:"btn btn-link",href:Sao.config.doc_url,target:"_blank"}).text(Sao.i18n.gettext("Documentation...")).appendTo(t.footer),jQuery("<h4/>").text(Sao.i18n.gettext("Keyboard shortcuts")).appendTo(t.body),jQuery("<div/>",{class:"row"}).appendTo(t.body)),n=jQuery("<dl/>",{class:"dl-horizontal col-md-6"}).append(jQuery("<h5/>").text(Sao.i18n.gettext("Global shortcuts"))).appendTo(i),o=jQuery("<dl/>",{class:"dl-horizontal col-md-6"}).append(jQuery("<h5/>").text(Sao.i18n.gettext("Tab shortcuts"))).appendTo(i);for(const r of l()){var s=jQuery("<dt/>").text(r.label),a=jQuery("<dd/>").append(jQuery("<kbd>").text(r.shortcut));e=r.id?o:n,s.appendTo(e),a.appendTo(e)}t.modal.on("hidden.bs.modal",function(){jQuery(this).remove()}),t.modal.modal("show")}},{shortcut:"ctrl+f1",label:Sao.i18n.gettext("Show/Hide access keys"),callback:function(){jQuery("html").toggleClass("accesskey")}}]}function n(){var i=1040;jQuery(".modal.in").each(function(e){var t=jQuery(this);i++,t.css("zIndex",i),t.next(".modal-backdrop.in").addClass("hidden").css("zIndex",i-1)}),jQuery(".modal.in:visible:last").focus().next(".modal-backdrop.in").removeClass("hidden")}Sao.Dialog=Sao.class_(Object,{init:function(e,t,i="sm",n=!0,o=null){this.modal=jQuery("<div/>",{class:t+" modal fade",role:"dialog","data-backdrop":"static","data-keyboard":n}),this.content=jQuery("<form/>",{class:"modal-content"}).appendTo(jQuery("<div/>",{class:"modal-dialog modal-"+i}).appendTo(this.modal)),this.header=jQuery("<div/>",{class:"modal-header"}).appendTo(this.content),e&&this.add_title(e,o),this.body=jQuery("<div/>",{class:"modal-body"}).appendTo(this.content),this.footer=jQuery("<div/>",{class:"modal-footer"}).appendTo(this.content),this.modal.on("shown.bs.modal",function(){0<jQuery(document.activeElement).closest(this.el)||jQuery(this).find(':input:visible:not([readonly]):not([tabindex^="-"]):first').focus()})},add_title:function(e,t=null){e=jQuery("<h4/>",{class:"modal-title",title:e}).text(Sao.common.ellipsize(e,120)+(t?" ":""));t&&e.append(jQuery("<small/>").text(t)),this.header.append(e)}}),Sao.GlobalSearch=Sao.class_(Object,{init:function(){this.el=jQuery("<div/>",{class:"global-search-container"});var e=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el),t=(jQuery("<div/>",{id:"user-favorites",class:"input-group-btn"}).append(jQuery("<button/>",{class:"btn btn-default dropdown-toggle","data-toggle":"dropdown","aria-haspopup":!0,"aria-expanded":!1,title:Sao.i18n.gettext("Favorites"),"aria-label":Sao.i18n.gettext("Favorites")}).click(Sao.favorites_menu).append(Sao.common.ICONFACTORY.get_icon_img("tryton-bookmarks"))).appendTo(e),this.search_entry=jQuery("<input>",{id:"global-search-entry",class:"form-control mousetrap",placeholder:Sao.i18n.gettext("Action")}).appendTo(e),new Sao.common.InputCompletion(this.el,this.update.bind(this),this.match_selected.bind(this),this.format.bind(this)));t.input.keydown(function(e){e.which!=Sao.common.RETURN_KEYCODE||t.dropdown.hasClass("open")||(e.preventDefault(),t.menu.dropdown("toggle"))})},format:function(e){var t=jQuery("<div/>");return Sao.common.ICONFACTORY.get_icon_img(e.icon,{class:"global_search-icon"}).appendTo(t),jQuery("<span/>",{class:"global-search-text"}).text(e.record_name).appendTo(t),t},update:function(e){var t=new Sao.Model("ir.model");return e?t.execute("global_search",[e,Sao.config.limit,Sao.main_menu_screen.model_name],Sao.main_menu_screen.context).then(e=>{var t=[];for(const i of e)t.push({model:i[1],model_name:i[2],record_id:i[3],record_name:i[4],icon:i[5]});return t}):jQuery.when([])},match_selected:function(e){e.model==Sao.main_menu_screen.model_name?Sao.Action.exec_keyword("tree_open",{model:e.model,id:e.record_id}):(e={model:e.model,res_id:e.record_id,mode:["form","tree"],name:e.model_name},Sao.Tab.create(e)),this.search_entry.val("")}}),jQuery(document).ready(function(){var e=new URL(window.location);if(e.searchParams.has("session")){var t=e.searchParams.get("database"),i={login_service:e.searchParams.get("login_service"),login:e.searchParams.get("login"),user_id:parseInt(e.searchParams.get("user_id"),10),session:e.searchParams.get("session")};if(e.searchParams.has("renew")){e=parseInt(e.searchParams.get("renew"),10);if(i.user_id!==e)return void window.close()}i=JSON.stringify(i),localStorage.setItem("sao_session_"+t,i),window.close()}else{"undefined"!=typeof Mousetrap&&l().forEach(function(i){Mousetrap.bind(i.shortcut,function(){var e,t;return i.id?(e=Sao.Tab.tabs.get_current())&&((t=jQuery(":focus")).blur(),e.el.find('a[id="'+i.id+'"]').click(),t.focus()):i.callback&&jQuery.when().then(i.callback),!1})});try{Notification.requestPermission()}catch(e){Sao.Logger.error(e.message,e.stack)}Sao.login()}}),Sao.Plugins=[],jQuery(document).on("show.bs.modal",".modal",function(e){jQuery(this).appendTo(jQuery("body"))}).on("shown.bs.modal",".modal.in",function(e){n()}).on("hidden.bs.modal",".modal",function(e){n(),jQuery(".modal:visible").length&&jQuery(document.body).addClass("modal-open")}),jQuery(document).on("keydown","textarea",function(e){var t;"PageUp"!==e.key&&"PageDown"!==e.key||(e.preventDefault(),t="PageUp"===e.key?0:e.target.textLength,e.target.setSelectionRange(t,t))})}(),!function(){"use strict";Sao.rpc=function(l,c=null,d=!0,h=!0){var u,_=jQuery.Deferred(),m=(c=c||new Sao.Session,jQuery.extend([],l.params));if(m.push(jQuery.extend({},c.context,m.pop())),c.cache&&c.cache.cached(l.method)&&void 0!==(u=c.cache.get(l.method,JSON.stringify(Sao.rpc.prepareObject(m)))))return d?jQuery.when(u):u;var e=Sao.common.processing.show();if(jQuery.ajax({async:d,headers:{Authorization:"Session "+c.get_auth()},contentType:"application/json",data:JSON.stringify(Sao.rpc.prepareObject({id:Sao.rpc.id++,method:l.method,params:m})),dataType:"json",url:"/"+(c.database||"")+"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}],success:function(e,t,i){var n,o,s,a,r;null===e?Sao.common.warning.run("",Sao.i18n.gettext("Unable to reach the server.")).always(_.reject):e.error&&!h?(console.debug(`RPC error calling ${l}: ${e.error[0]}: ${e.error[1]}.`),_.reject(e.error)):e.error&&h?"UserWarning"==e.error[0]?(n=e.error[1][0],o=e.error[1][1],s=e.error[1][2],Sao.common.userwarning.run(s,o).then(function(e){~["always","ok"].indexOf(e)?Sao.rpc({method:"model.res.user.warning.skip",params:[n,"always"==e,{}]},c).done(function(){d?Sao.rpc(l,c).then(_.resolve,_.reject):_.resolve()}):_.reject()},_.reject)):"UserError"==e.error[0]?(o=e.error[1][0],s=e.error[1][1],r=e.error[1][2],jQuery.isEmptyObject(r)||(a=r[1],r=r[0],(a=new Sao.common.DomainParser(a)).stringable(r)&&(s+="\n"+a.string(r))),Sao.common.warning.run(s,o).always(_.reject)):"ConcurrencyException"==e.error[0]?d&&l.method.startsWith("model.")&&(l.method.endsWith(".write")||l.method.endsWith(".delete"))&&1==l.params[0].length?(a=l.method.split(".").slice(1,-1).join("."),Sao.common.concurrency.run(a,l.params[0][0],l.params.slice(-1)[0]).then(function(){delete l.params.slice(-1)[0]._timestamp,Sao.rpc(l,c).then(_.resolve,_.reject)},_.reject)):Sao.common.message.run("Concurrency Exception","tryton-warning").always(_.reject):Sao.common.error.run(e.error[0],e.error[1]).always(_.reject):(u=e.result,c.cache&&(r=i.getResponseHeader("X-Tryton-Cache"))&&(r=parseInt(r,10),c.cache.set(l.method,JSON.stringify(Sao.rpc.prepareObject(m)),r,u)),_.resolve(u))},error:function(e,t,i){401==e.status?Sao.Session.renew(c).then(function(){d?Sao.rpc(l,c,d,h).then(_.resolve,_.reject):_.resolve()},_.reject):(429==e.status?Sao.common.message.run(Sao.i18n.gettext("Too many requests. Try again later."),"tryton-error"):Sao.common.error.run(t,i)).always(_.reject)}}),d)return _.promise();if(void 0===u)throw _;return u},Sao.rpc.id=0,Sao.rpc.convertJSONObject=function(e,t,i){if(e instanceof Array)for(var n=0,o=e.length;n<o;n++)Sao.rpc.convertJSONObject(e[n],n,e);else if("string"!=typeof e&&"number"!=typeof e&&null!==e)if(e&&e.__class__){switch(e.__class__){case"datetime":e=Sao.DateTime(e.year,e.month-1,e.day,e.hour,e.minute,e.second,Math.ceil(e.microsecond/1e3),!0);break;case"date":e=Sao.Date(e.year,e.month-1,e.day);break;case"time":e=Sao.Time(e.hour,e.minute,e.second,Math.ceil(e.microsecond/1e3));break;case"timedelta":e=Sao.TimeDelta(null,e.seconds);break;case"bytes":e=Sao.common.atob(e);break;case"Decimal":e=new Sao.Decimal(e.decimal)}i&&(i[t]=e)}else for(var s in e)Sao.rpc.convertJSONObject(e[s],s,e);return i||e},Sao.rpc.prepareObject=function(e,t,i){if(e instanceof Array)for(var n=0,o=(e=jQuery.extend([],e)).length;n<o;n++)Sao.rpc.prepareObject(e[n],n,e);else if("string"!=typeof e&&"number"!=typeof e&&"boolean"!=typeof e&&null!=e)if(e.isDate)e={__class__:"date",year:e.year(),month:e.month()+1,day:e.date()};else if(e.isDateTime)e={__class__:"datetime",year:(e=e.clone()).utc().year(),month:e.utc().month()+1,day:e.utc().date(),hour:e.utc().hour(),minute:e.utc().minute(),second:e.utc().second(),microsecond:1e3*e.utc().millisecond()};else if(e.isTime)e={__class__:"time",hour:e.hour(),minute:e.minute(),second:e.second(),microsecond:1e3*e.millisecond()};else if(e.isTimeDelta)e={__class__:"timedelta",seconds:e.asSeconds()};else if(e instanceof Sao.Decimal)e={__class__:"Decimal",decimal:e.toString()};else if(e instanceof Uint8Array)e={__class__:"bytes",base64:Sao.common.btoa(e)};else for(var s in e=jQuery.extend({},e))Sao.rpc.prepareObject(e[s],s,e);return i&&(i[t]=e),i||e},jQuery.ajaxSetup({converters:{"text json":function(e){return Sao.rpc.convertJSONObject(jQuery.parseJSON(e))}}})}(),!function(){"use strict";Sao.PYSON={},Sao.PYSON.eval={True:!0,False:!1},Sao.PYSON.toString=function(t){return t instanceof Sao.PYSON.PYSON?t.toString():t instanceof Array?"["+t.map(Sao.PYSON.toString).join(", ")+"]":t instanceof Object?"{"+Object.keys(t).map(e=>Sao.PYSON.toString(e)+": "+Sao.PYSON.toString(t[e])).join(", ")+"}":JSON.stringify(t)},Sao.PYSON.PYSON=Sao.class_(Object,{init:function(){},pyson:function(){throw"NotImplementedError"},types:function(){throw"NotImplementedError"},get:function(e,t=""){return new Sao.PYSON.Get(this,e,t)},in_:function(e){return new Sao.PYSON.In(this,e)},contains:function(e){return new Sao.PYSON.In(e,this)},toString:function(){return this.pyson().__class__+"("+this.__string_params__().map(Sao.PYSON.toString).join(", ")+")"},__string_params__:function(){throw"NotImplementedError"}}),Sao.PYSON.PYSON.eval_=function(e,t){throw"NotImplementedError"},Sao.PYSON.PYSON.init_from_object=function(e){throw"NotImplementedError"},Sao.PYSON.Encoder=Sao.class_(Object,{prepare:function(e,t,i){if(null!=e)if(e instanceof Array)for(var n=0,o=(e=jQuery.extend([],e)).length;n<o;n++)this.prepare(e[n],n,e);else if(moment.isMoment(e))e=(e.isDate?new Sao.PYSON.Date(e.year(),e.month()+1,e.date()):new Sao.PYSON.DateTime(e.year(),e.month()+1,e.date(),e.hours(),e.minutes(),e.seconds(),1e3*e.milliseconds())).pyson();else if(moment.isDuration(e))e=new Sao.PYSON.TimeDelta(Math.round(e.asDays()),e.seconds(),1e3*e.milliseconds()).pyson();else if(e instanceof Sao.Decimal)e=e.valueOf();else if(e instanceof Object&&!(e instanceof Sao.PYSON.PYSON))for(var s in e=jQuery.extend({},e))this.prepare(e[s],s,e);return i&&(i[t]=e),i||e},encode:function(e){return e=this.prepare(e),JSON.stringify(e,(e,t)=>t instanceof Sao.PYSON.PYSON?this.prepare(t.pyson()):null==t?null:t)}}),Sao.PYSON.Decoder=Sao.class_(Object,{init:function(e,t){this.__context=e||{},this.noeval=t||!1},decode:function(e){return JSON.parse(e,(e,t)=>{if("object"==typeof t&&null!==t){var i,n=Sao.PYSON[t.__class__];if(n)return this.noeval?(delete(i=jQuery.extend({},t)).__class__,Sao.PYSON[t.__class__].init_from_object(i)):n.eval_(t,this.__context)}return t})}}),Sao.PYSON.eval.Eval=function(e,t){return new Sao.PYSON.Eval(e,t)},Sao.PYSON.Eval=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t=""){Sao.PYSON.Eval._super.init.call(this),this._value=e,this._default=t},pyson:function(){return{__class__:"Eval",v:this._value,d:this._default}},types:function(){return this._default instanceof Sao.PYSON.PYSON?this._default.types():[typeof this._default]},__string_params__:function(){return[this._value,this._default]},get basename(){var e=this._value,t=(e=e.startsWith("_parent_")?e.slice("_parent_".length):e).indexOf(".");return e=0<=t?e.substring(0,t):e}}),Sao.PYSON.Eval.eval_=function(e,t){var i=e.v.indexOf(".");return 0<=i&&!(e.v in t)?Sao.PYSON.Eval.eval_({v:e.v.substring(i+1),d:e.d},t[e.v.substring(0,i)]||{}):e.v in t&&void 0!==t[e.v]?t[e.v]:e.d},Sao.PYSON.Eval.init_from_object=function(e){return new Sao.PYSON.Eval(e.v,e.d)},Sao.PYSON.eval.Not=function(e){return new Sao.PYSON.Not(e)},Sao.PYSON.Not=Sao.class_(Sao.PYSON.PYSON,{init:function(e){Sao.PYSON.Not._super.init.call(this),e instanceof Sao.PYSON.PYSON?(jQuery(e.types()).not(["boolean","object"]).length||jQuery(["boolean"]).not(e.types()).length)&&(e=new Sao.PYSON.Bool(e)):"boolean"!=typeof e&&(e=new Sao.PYSON.Bool(e)),this._value=e},pyson:function(){return{__class__:"Not",v:this._value}},types:function(){return["boolean"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Not.eval_=function(e,t){return!Sao.PYSON.Bool.eval_(e,t)},Sao.PYSON.Not.init_from_object=function(e){return new Sao.PYSON.Not(e.v)},Sao.PYSON.eval.Bool=function(e){return new Sao.PYSON.Bool(e)},Sao.PYSON.Bool=Sao.class_(Sao.PYSON.PYSON,{init:function(e){Sao.PYSON.Bool._super.init.call(this),this._value=e},pyson:function(){return{__class__:"Bool",v:this._value}},types:function(){return["boolean"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Bool.eval_=function(e,t){return moment.isMoment(e.v)&&e.v.isTime?Boolean(e.v.hour()||e.v.minute()||e.v.second()||e.v.millisecond()):moment.isDuration(e.v)||e.v instanceof Number?Boolean(e.v.valueOf()):e.v instanceof Object?!jQuery.isEmptyObject(e.v):Boolean(e.v)},Sao.PYSON.Bool.init_from_object=function(e){return new Sao.PYSON.Bool(e.v)},Sao.PYSON.eval.And=function(){return Sao.PYSON.And.new_(arguments)},Sao.PYSON.And=Sao.class_(Sao.PYSON.PYSON,{init:function(){var e=jQuery.extend([],arguments);Sao.PYSON.And._super.init.call(this);for(var t=0,i=e.length;t<i;t++){var n=e[t];n instanceof Sao.PYSON.PYSON?(jQuery(n.types()).not(["boolean"]).length||jQuery(["boolean"]).not(n.types()).length)&&(e[t]=new Sao.PYSON.Bool(n)):"boolean"!=typeof n&&(e[t]=new Sao.PYSON.Bool(n))}if(e.length<2)throw"must have at least 2 statements";this._statements=e},pyson:function(){return{__class__:"And",s:this._statements}},types:function(){return["boolean"]},__string_params__:function(){return this._statements}}),Sao.PYSON.And.eval_=function(e,t){var i=!0;for(const n of e.s)i=i&&n;return i},Sao.PYSON.And.init_from_object=function(e){return Sao.PYSON.And.new_(e.s)},Sao.PYSON.eval.Or=function(){return Sao.PYSON.Or.new_(arguments)},Sao.PYSON.Or=Sao.class_(Sao.PYSON.And,{pyson:function(){var e=Sao.PYSON.Or._super.pyson.call(this);return e.__class__="Or",e}}),Sao.PYSON.Or.eval_=function(e,t){var i=!1;for(const n of e.s)i=i||n;return i},Sao.PYSON.Or.init_from_object=function(e){return new Sao.PYSON.Or.new_(e.s)},Sao.PYSON.eval.Equal=function(e,t){return new Sao.PYSON.Equal(e,t)},Sao.PYSON.Equal=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t){var i,n;if(Sao.PYSON.Equal._super.init.call(this),i=e instanceof Sao.PYSON.PYSON?e.types():[typeof e],n=t instanceof Sao.PYSON.PYSON?t.types():[typeof t],jQuery(i).not(n).length||jQuery(n).not(i).length)throw"statements must have the same type";this._statement1=e,this._statement2=t},pyson:function(){return{__class__:"Equal",s1:this._statement1,s2:this._statement2}},types:function(){return["boolean"]},__string_params__:function(){return[this._statement1,this._statement2]}}),Sao.PYSON.Equal.eval_=function(e,t){return e.s1 instanceof Array&&e.s2 instanceof Array?Sao.common.compare(e.s1,e.s2):moment.isMoment(e.s1)&&moment.isMoment(e.s2)?e.s1.isDate==e.s2.isDate&&e.s1.isDateTime==e.s2.isDateTime&&e.s1.valueOf()==e.s2.valueOf():moment.isDuration(e.s1)&&moment.isDuration(e.s2)?e.s1.valueOf()==e.s2.value():e.s1==e.s2},Sao.PYSON.Equal.init_from_object=function(e){return new Sao.PYSON.Equal(e.s1,e.s2)},Sao.PYSON.eval.Greater=function(e,t,i){return new Sao.PYSON.Greater(e,t,i)},Sao.PYSON.Greater=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t,i=!1){Sao.PYSON.Greater._super.init.call(this);for(var n=[e,t],o=0;o<2;o++){var s=n[o];if(s instanceof Sao.PYSON.PYSON){if(!(s instanceof Sao.PYSON.DateTime||s instanceof Sao.PYSON.Date||s instanceof Sao.PYSON.TimeDelta)&&jQuery(s.types()).not(["number","object"]).length)throw"statement must be an integer, float, date, datetime or timedelta"}else if(!~["number","object"].indexOf(typeof s))throw"statement must be an integer, float, date, datetime or timedelta"}i instanceof Sao.PYSON.PYSON?(jQuery(i.types()).not(["boolean"]).length||jQuery(["boolean"]).not(i.types()).length)&&(i=new Sao.PYSON.Bool(i)):"boolean"!=typeof i&&(i=new Sao.PYSON.Bool(i)),this._statement1=e,this._statement2=t,this._equal=i},pyson:function(){return{__class__:"Greater",s1:this._statement1,s2:this._statement2,e:this._equal}},types:function(){return["boolean"]},__string_params__:function(){return[this._statement1,this._statement2,this._equal]}}),Sao.PYSON.Greater._convert=function(e){for(var t=[(e=jQuery.extend({},e)).s1,e.s2],i=0;i<2;i++)moment.isMoment(t[i])||moment.isDuration(t[i])?t[i]=t[i].valueOf():t[i]=Number(t[i]);return e.s1=t[0],e.s2=t[1],e},Sao.PYSON.Greater.eval_=function(e,t){return null!=e.s1&&null!=e.s2&&((e=Sao.PYSON.Greater._convert(e)).e?e.s1>=e.s2:e.s1>e.s2)},Sao.PYSON.Greater.init_from_object=function(e){return new Sao.PYSON.Greater(e.s1,e.s2,e.e)},Sao.PYSON.eval.Less=function(e,t,i){return new Sao.PYSON.Less(e,t,i)},Sao.PYSON.Less=Sao.class_(Sao.PYSON.Greater,{pyson:function(){var e=Sao.PYSON.Less._super.pyson.call(this);return e.__class__="Less",e}}),Sao.PYSON.Less._convert=Sao.PYSON.Greater._convert,Sao.PYSON.Less.eval_=function(e,t){return null!=e.s1&&null!=e.s2&&((e=Sao.PYSON.Less._convert(e)).e?e.s1<=e.s2:e.s1<e.s2)},Sao.PYSON.Less.init_from_object=function(e){return new Sao.PYSON.Less(e.s1,e.s2,e.e)},Sao.PYSON.eval.If=function(e,t,i){return new Sao.PYSON.If(e,t,i)},Sao.PYSON.If=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t,i=null){Sao.PYSON.If._super.init.call(this),e instanceof Sao.PYSON.PYSON?(jQuery(e.types()).not(["boolean"]).length||jQuery(["boolean"]).not(e.types()).length)&&(e=new Sao.PYSON.Bool(e)):"boolean"!=typeof e&&(e=new Sao.PYSON.Bool(e)),t instanceof Sao.PYSON.PYSON&&t.types(),i instanceof Sao.PYSON.PYSON&&i.types(),this._condition=e,this._then_statement=t,this._else_statement=i},pyson:function(){return{__class__:"If",c:this._condition,t:this._then_statement,e:this._else_statement}},types:function(){var e=this._then_statement instanceof Sao.PYSON.PYSON?this._then_statement.types():[typeof this._then_statement];if(this._else_statement instanceof Sao.PYSON.PYSON)for(const i of this._else_statement.types())~e.indexOf(i)||e.push(i);else{var t=typeof this._else_statement;~e.indexOf(t)||e.push(t)}return e},__string_params__:function(){return[this._condition,this._then_statement,this._else_statement]}}),Sao.PYSON.If.eval_=function(e,t){return e.c?e.t:e.e},Sao.PYSON.If.init_from_object=function(e){return new Sao.PYSON.If(e.c,e.t,e.e)},Sao.PYSON.eval.Get=function(e,t,i){return new Sao.PYSON.Get(e,t,i)},Sao.PYSON.Get=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t,i=null){if(Sao.PYSON.Get._super.init.call(this),e instanceof Sao.PYSON.PYSON){if(jQuery(e.types()).not(["object"]).length||jQuery(["object"]).not(e.types()).length)throw"obj must be a dict"}else if(!(e instanceof Object))throw"obj must be a dict";if(this._obj=e,t instanceof Sao.PYSON.PYSON){if(jQuery(t.types()).not(["string"]).length||jQuery(["string"]).not(t.types()).length)throw"key must be a string"}else if("string"!=typeof t)throw"key must be a string";this._key=t,this._default=i},pyson:function(){return{__class__:"Get",v:this._obj,k:this._key,d:this._default}},types:function(){return this._default instanceof Sao.PYSON.PYSON?this._default.types():[typeof this._default]},__string_params__:function(){return[this._obj,this._key,this._default]}}),Sao.PYSON.Get.eval_=function(e,t){return e.k in e.v?e.v[e.k]:e.d},Sao.PYSON.Get.init_from_object=function(e){return new Sao.PYSON.Get(e.v,e.k,e.d)},Sao.PYSON.eval.In=function(e,t){return new Sao.PYSON.In(e,t)},Sao.PYSON.In=Sao.class_(Sao.PYSON.PYSON,{init:function(e,t){if(Sao.PYSON.In._super.init.call(this),e instanceof Sao.PYSON.PYSON){if(jQuery(e.types()).not(["string","number"]).length)throw"key must be a string or a number"}else if(!~["string","number"].indexOf(typeof e))throw"key must be a string or a number";if(t instanceof Sao.PYSON.PYSON){if(jQuery(t.types()).not(["object"]).length||jQuery(["object"]).not(t.types()).length)throw"obj must be a dict or a list"}else if(!(t instanceof Object))throw"obj must be a dict or a list";this._key=e,this._obj=t},pyson:function(){return{__class__:"In",k:this._key,v:this._obj}},types:function(){return["boolean"]},__string_params__:function(){return[this._key,this._obj]}}),Sao.PYSON.In.eval_=function(e,t){return!!e.v&&(e.v.indexOf?Boolean(~e.v.indexOf(e.k)):!!e.v[e.k])},Sao.PYSON.In.init_from_object=function(e){return new Sao.PYSON.In(e.k,e.v)},Sao.PYSON.eval.Date=function(e,t,i,n,o,s){return new Sao.PYSON.Date(e,t,i,n,o,s)},Sao.PYSON.Date=Sao.class_(Sao.PYSON.PYSON,{init:function(e=null,t=null,i=null,n=0,o=0,s=0,a=null){Sao.PYSON.Date._super.init.call(this),this._test(e,"year"),this._test(t,"month"),this._test(i,"day"),this._test(n,"delta_years"),this._test(s,"delta_days"),this._test(o,"delta_months"),this._year=e,this._month=t,this._day=i,this._delta_years=n,this._delta_months=o,this._delta_days=s,this._start=a},pyson:function(){return{__class__:"Date",y:this._year,M:this._month,d:this._day,dy:this._delta_years,dM:this._delta_months,dd:this._delta_days,start:this._start}},types:function(){return["object"]},_test:function(e,t){if(e instanceof Sao.PYSON.PYSON){if(jQuery(e.types()).not(["number","object"]).length)throw t+" must be an integer or None"}else if("number"!=typeof e&&null!==e)throw t+" must be an integer or None"},__string_params__:function(){return[this._year,this._month,this._day,this._delta_years,this._delta_months,this._delta_days,this._start]}}),Sao.PYSON.Date.eval_=function(e,t){var i=e.start;return(i=i&&i.isDateTime?Sao.Date(i.year(),i.month(),i.date()):i)&&i.isDate||(i=Sao.Date()),e.y&&i.year(e.y),e.M&&i.month(e.M-1),e.d&&i.date(e.d),e.dy&&i.add(e.dy,"y"),e.dM&&i.add(e.dM,"M"),e.dd&&i.add(e.dd,"d"),i},Sao.PYSON.Date.init_from_object=function(e){return new Sao.PYSON.Date(e.y,e.M,e.d,e.dy,e.dM,e.dd,e.start)},Sao.PYSON.eval.DateTime=function(e,t,i,n,o,s,a,r,l,c,d,h,u,_){return new Sao.PYSON.DateTime(e,t,i,n,o,s,a,r,l,c,d,h,u,_)},Sao.PYSON.DateTime=Sao.class_(Sao.PYSON.Date,{init:function(e=null,t=null,i=null,n=null,o=null,s=null,a=null,r=0,l=0,c=0,d=0,h=0,u=0,_=0,m=null){Sao.PYSON.DateTime._super.init.call(this,e,t,i,r,l,c,m),this._test(n,"hour"),this._test(o,"minute"),this._test(s,"second"),this._test(a,"microsecond"),this._test(d,"delta_hours"),this._test(h,"delta_minutes"),this._test(u,"delta_seconds"),this._test(_,"delta_microseconds"),this._hour=n,this._minute=o,this._second=s,this._microsecond=a,this._delta_hours=d,this._delta_minutes=h,this._delta_seconds=u,this._delta_microseconds=_},pyson:function(){var e=Sao.PYSON.DateTime._super.pyson.call(this);return e.__class__="DateTime",e.h=this._hour,e.m=this._minute,e.s=this._second,e.ms=this._microsecond,e.dh=this._delta_hours,e.dm=this._delta_minutes,e.ds=this._delta_seconds,e.dms=this._delta_microseconds,e},__string_params__:function(){var e=Sao.PYSON.DateTime._super.__string_params__.call(this);return[e[0],e[1],e[2],this._hour,this._minute,this._second,this._microsecond,e[3],e[4],e[5],this._delta_hours,this._delta_minutes,this._delta_seconds,this._delta_microseconds,e[6]]}}),Sao.PYSON.DateTime.eval_=function(e,t){var i=e.start;return(i=i&&i.isDate?Sao.DateTime.combine(i,Sao.Time()):i)&&i.isDateTime||(i=Sao.DateTime()).utc(),e.y&&i.year(e.y),e.M&&i.month(e.M-1),e.d&&i.date(e.d),null!==e.h&&i.hour(e.h),null!==e.m&&i.minute(e.m),null!==e.s&&i.second(e.s),null!==e.ms&&i.milliseconds(e.ms/1e3),e.dy&&i.add(e.dy,"y"),e.dM&&i.add(e.dM,"M"),e.dd&&i.add(e.dd,"d"),e.dh&&i.add(e.dh,"h"),e.dm&&i.add(e.dm,"m"),e.ds&&i.add(e.ds,"s"),e.dms&&i.add(e.dms/1e3,"ms"),i},Sao.PYSON.DateTime.init_from_object=function(e){return new Sao.PYSON.DateTime(e.y,e.M,e.d,e.h,e.m,e.s,e.ms,e.dy,e.dM,e.dd,e.dh,e.dm,e.ds,e.dms)},Sao.PYSON.eval.TimeDelta=function(e,t,i){return new Sao.PYSON.TimeDelta(e,t,i)},Sao.PYSON.TimeDelta=Sao.class_(Sao.PYSON.PYSON,{init:function(e=0,t=0,i=0){function n(e,t){if(e instanceof Sao.PYSON.TimeDelta){if(jQuery(e.types()).not(["number"]).length)throw t+" must be an integer"}else if("number"!=typeof e)throw t+" must be an integer";return e}Sao.PYSON.TimeDelta._super.init.call(this),this._days=n(e,"days"),this._seconds=n(t,"seconds"),this._microseconds=n(i,"microseconds")},pyson:function(){return{__class__:"TimeDelta",d:this._days,s:this._seconds,m:this._microseconds}},types:function(){return["object"]},__string_params__:function(){return[this._days,this._seconds,this._microseconds]}}),Sao.PYSON.TimeDelta.eval_=function(e,t){return Sao.TimeDelta(e.d,e.s,e.m/1e3)},Sao.PYSON.TimeDelta.init_from_object=function(e){return new Sao.PYSON.TimeDelta(e.d,e.s,e.microseconds)},Sao.PYSON.eval.Len=function(e){return new Sao.PYSON.Len(e)},Sao.PYSON.Len=Sao.class_(Sao.PYSON.PYSON,{init:function(e){if(Sao.PYSON.Len._super.init.call(this),e instanceof Sao.PYSON.PYSON){if(jQuery(e.types()).not(["object","string"]).length||jQuery(["object","string"]).not(e.types()).length)throw"value must be an object or a string"}else if("object"!=typeof e&&"string"!=typeof e)throw"value must be an object or a string";this._value=e},pyson:function(){return{__class__:"Len",v:this._value}},types:function(){return["integer"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Len.eval_=function(e,t){return("object"==typeof e.v?Object.keys(e.v):e.v).length},Sao.PYSON.Len.init_from_object=function(e){return new Sao.PYSON.Len(e.v)}}(),!function(){"use strict";Sao.Session=Sao.class_(Object,{init:function(e,t){this.login_service=null,this.user_id=null,this.session=null,this.cache=new i,this.prm=jQuery.when(),this.database=e,this.login=t,this.restore(),this.context={},this.restore_context(),Sao.Session.current_session||(Sao.Session.current_session=this)},get_auth:function(){return e=this.login+":"+this.user_id+":"+this.session,window.btoa(unescape(encodeURIComponent(e)));var e},do_login:function(e){var t=jQuery.Deferred(),i=this.login,n=JSON.parse(localStorage.getItem("sao_device_cookies")),o=null;n&&n[this.database]&&(o=n[this.database][this.login]);return new Sao.Login(function(e){return e.device_cookie=o,{method:"common.db.login",params:[i,e,Sao.i18n.getlang()]}},this).run().then(e=>{this.login=i,this.user_id=e[0],this.session=e[1],this.store(),this.renew_device_cookie(),t.resolve()},()=>{this.user_id=null,this.session=null,this.store(),t.reject()}),t.promise()},do_logout:function(){var e;return this.user_id&&this.session?(e=jQuery.ajax({headers:{Authorization:"Session "+this.get_auth()},contentType:"application/json",data:JSON.stringify({id:0,method:"common.db.logout",params:[]}),dataType:"json",url:"/"+this.database+"/",type:"post"}),this.unstore(),this.database=null,this.login=null,this.user_id=null,this.session=null,Sao.Session.current_session===this&&(Sao.Session.current_session=null),e):jQuery.when()},reload_context:function(){var e={method:"model.res.user.get_preferences",params:[!0,this.context]};return this.reset_context(),Sao.rpc(e,this).then(e=>{jQuery.extend(this.context,e),this.store_context()})},reset_context:function(){this.context={client:Sao.Bus.id}},restore_context:function(){this.reset_context();var e=sessionStorage.getItem("sao_context_"+this.database);null!==e&&jQuery.extend(this.context,Sao.rpc.convertJSONObject(JSON.parse(e)))},store_context:function(){var e=jQuery.extend({},this.context);delete e.client,e=JSON.stringify(Sao.rpc.prepareObject(e)),sessionStorage.setItem("sao_context_"+this.database,e)},restore:function(){var e;this.database&&!this.session&&null!==(e=localStorage.getItem("sao_session_"+this.database))&&(e=JSON.parse(e),this.login&&this.login!=e.login||(this.login_service=e.login_service,this.login=e.login,this.user_id=e.user_id,this.session=e.session))},store:function(){var e={login:this.login,user_id:this.user_id,session:this.session},e=JSON.stringify(e);localStorage.setItem("sao_session_"+this.database,e)},unstore:function(){localStorage.removeItem("sao_session_"+this.database)},renew_device_cookie:function(){var t=JSON.parse(localStorage.getItem("sao_device_cookies")),e=t&&this.database in t?t[this.database][this.login]:null,e=Sao.rpc({method:"model.res.user.device.renew",params:[e,{}]},this);e.done(e=>{t=(t=JSON.parse(localStorage.getItem("sao_device_cookies")))||{},this.database in t||(t[this.database]={}),t[this.database][this.login]=e,localStorage.setItem("sao_device_cookies",JSON.stringify(t))}),e.fail(()=>{Sao.Logger.error("Cannot renew device cookie")})}}),Sao.Session.server_version=function(){var e=Sao.common.processing.show();return jQuery.ajax({contentType:"application/json",data:JSON.stringify({id:0,method:"common.server.version",params:[]}),dataType:"json",url:"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}).then(function(e){return e.result})},Sao.Session.login_dialog=function(){var e=new Sao.Dialog(Sao.i18n.gettext("Login"),"login-dialog","md",!0,Sao.__version__);return e.database_select=jQuery("<select/>",{class:"form-control",id:"database",name:"database"}).hide(),e.database_input=jQuery("<input/>",{class:"form-control",id:"database",name:"database"}).hide(),e.login_input=jQuery("<input/>",{class:"form-control",id:"login",name:"login"}),e.button=jQuery("<button/>",{class:"btn btn-primary btn-block",type:"submit",title:Sao.i18n.gettext("Login")}).text(" "+Sao.i18n.gettext("Login")),e.body.append(jQuery("<div/>",{class:"form-group"}).append(jQuery("<label/>",{class:"control-label",for:"database"}).text(Sao.i18n.gettext("Database"))).append(e.database_select).append(e.database_input)).append(jQuery("<div/>",{class:"panel panel-default"}).append(jQuery("<div/>",{class:"panel-body"}).append(jQuery("<div/>",{class:"form-group"}).append(jQuery("<label/>",{class:"control-label",for:"login"}).text(Sao.i18n.gettext("User name"))).append(e.login_input)).append(e.button))),e},Sao.Session.get_credentials=function(){function a(){return window.location.hash.replace(/^(#(!|))/,"").split("/",1)[0]||null}var r,l,c,o,d=jQuery.Deferred(),i=a(),h=new Sao.Session(i,null);return h.session?(d.resolve(h),d):(r=Sao.Session.login_dialog(),l=function(){return r.modal.find("input,select").filter(":visible:not([readonly])").filter(function(){return!jQuery(this).val()})},r.modal.modal({backdrop:!(o=function(e){var t=r.database_select.val()||r.database_input.val();if(r.modal.find(".has-error").removeClass("has-error"),t){c();var i=window.location.protocol+"//"+window.location.host,n=new URL(i+"/"),i=(n.searchParams.append("login_service",e.data),new URL(i+"/"+t+e.data)),o=(i.searchParams.append("next",n.href),window.open(i.href,"_blank","popup=1"));const s=window.setInterval(()=>{o.closed&&(window.clearInterval(s),h.database=t,h.restore(),h.session?(d.resolve(h),r.modal.remove(),a()!=t&&(window.location="#"+t)):(c(!1),l().first().focus()))},500)}else r.database_select.closest(".form-group").addClass("has-error")}),keyboard:!(c=function(e=!0){r.body.find("input,select,button").prop("disabled",e)})}),r.modal.find("form").unbind().submit(function(e){var t;e.preventDefault(),e=r.login_input.val(),t=r.database_select.val()||r.database_input.val(),r.modal.find(".has-error").removeClass("has-error"),e&&t?(r.button.focus(),c(),h.database=t,h.login=e,h.restore(),(h.session?jQuery.when():h.do_login()).then(function(){r.modal.modal("hide"),d.resolve(h),r.modal.remove(),a()!=t&&(window.location="#"+t)},function(){c(!1),l().closest(".form-group").addClass("has-error"),l().first().focus()})):l().closest(".form-group").addClass("has-error")}),r.modal.on("shown.bs.modal",function(){l().first().focus()}),jQuery.when(Sao.DB.list()).then(function(e){var t;if(1==(e=e||[]).length)i=e[0],t=r.database_input;else{t=r.database_select;for(const i of e)t.append(jQuery("<option/>",{value:i,text:i}))}t.prop("readonly",1==e.length),t.show(),t.val(i||"")},function(){r.database_input.show()}),jQuery.when(Sao.Authentication.services()).then(function(e){if(e.length){var t,i,n=jQuery("<div/>",{class:"panel-body"}).append(jQuery("<p/>").text(Sao.i18n.gettext("Login with")));r.body.append(jQuery("<div/>",{class:"panel panel-default"}).append(n));for([t,i]of e)n.append(jQuery("<button/>",{class:"btn btn-block btn-default",type:"button"}).text(t).click(i,o))}}),d.promise())},Sao.Session.renew=function(e){if("pending"!=e.prm.state()){var t=jQuery.Deferred();if(e.session=null,e.prm=t.promise(),e.login_service){e.unstore();var i=window.location.protocol+"//"+window.location.host,n=new URL(i+"/"),i=(n.searchParams.append("login_service",e.login_service),n.searchParams.append("renew",e.user_id),new URL(i+"/"+e.database+e.login_service)),o=(i.searchParams.append("next",n.href),window.open(i.href,"_blank","popup=1"));const s=window.setInterval(()=>{o.closed&&(window.clearInterval(s),e.restore(),e.session?t.resolve():(Sao.logout(),t.reject()))},500)}else e.do_login().then(t.resolve,function(){Sao.logout(),t.reject()});t.done(function(){Sao.Bus.listen()})}return e.prm},Sao.Session.current_session=null,Sao.Login=Sao.class_(Object,{init:function(e,t){this.func=e,this.session=t||Sao.Session.current_session},run:function(o={}){var s=jQuery.Deferred(),e=Sao.common.processing.show(),t=this.func(o),t=(t.id=0,{contentType:"application/json",data:JSON.stringify(t),dataType:"json",url:"/"+this.session.database+"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}),t=(this.session.user_id&&this.session.session&&(t.headers={Authorization:"Session "+this.session.get_auth()}),jQuery.ajax(t));return t.done(function(e){if(null===e)Sao.common.warning.run("",Sao.i18n.gettext("Unable to reach the server.")),s.reject();else if(e.error){if(e.error[0].startsWith("401"))return this.run({}).then(s.resolve,s.reject);var t,i,n;e.error[0].startsWith("429")?Sao.common.message.run(Sao.i18n.gettext("Too many requests. Try again later."),"tryton-error").always(s.resolve):e.error[0].startsWith("404")?Sao.common.message.run(Sao.i18n.gettext("Not found."),"tryton-error").always(s.reject):"LoginException"!=e.error[0]?Sao.common.error.run(e.error[0],e.error[1]).always(s.reject):(t=e.error[1],i=t[0],n=t[1],this["get_"+t[2]](n,i).then(e=>(o[i]=e,this.run(o).then(s.resolve,s.reject)),s.reject))}else s.resolve(e.result)}.bind(this)),t.fail(function(e,t,i){401==e.status?this.run({}).then(s.resolve,s.reject):429==e.status?Sao.common.message.run(Sao.i18n.gettext("Too many requests. Try again later."),"tryton-error").always(s.resolve):(404==e.status?Sao.common.message.run(Sao.i18n.gettext("Not found."),"tryton-error"):Sao.common.error.run(t,i)).always(s.reject)}.bind(this)),s.promise()},get_char:function(e,t){return Sao.common.ask.run(e,t)},get_password:function(e,t){return Sao.common.ask.run(e,t,!1)}});var i=Sao.class_(Object,{init:function(){this.store={}},cached:function(e){return e in this.store},set:function(e,t,i,n){i=new Date((new Date).getTime()+1e3*i),Sao.setdefault(this.store,e,{})[t]={expire:i,value:JSON.stringify(Sao.rpc.prepareObject(n))}},get:function(e,t){var i=new Date,n=Sao.setdefault(this.store,e,{})[t];if(n){if(!(n.expire<i))return Sao.Logger.info("(cached)",e,t),Sao.rpc.convertJSONObject(jQuery.parseJSON(n.value));delete this.store[e][t]}},clear:function(e){e?this.store[e]={}:this.store={}}});Sao.DB={},Sao.DB.list=function(){var e=Sao.common.processing.show();return jQuery.ajax({contentType:"application/json",data:JSON.stringify({id:0,method:"common.db.list",params:[]}),dataType:"json",url:"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}).then(function(e){return e.result})},Sao.Authentication={},Sao.Authentication.services=function(){var e=Sao.common.processing.show();return jQuery.ajax({contentType:"application/json",data:JSON.stringify({id:0,method:"common.authentication.services",params:[]}),dataType:"json",url:"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}).then(function(e){return Sao.Authentication.services=function(){return e.result},e.result})}}(),!function(){"use strict";Sao.common={},Sao.common.BACKSPACE_KEYCODE=8,Sao.common.TAB_KEYCODE=9,Sao.common.RETURN_KEYCODE=13,Sao.common.ESC_KEYCODE=27,Sao.common.UP_KEYCODE=38,Sao.common.DOWN_KEYCODE=40,Sao.common.DELETE_KEYCODE=46,Sao.common.F2_KEYCODE=113,Sao.common.F3_KEYCODE=114,Sao.common.SELECTION_NONE=1,Sao.common.SELECTION_SINGLE=2,Sao.common.SELECTION_MULTIPLE=3,Sao.common.compare=function(e,t){if(e.length!=t.length)return!1;for(var i=0;i<e.length;i++){var n=e[i],o=t[i];if(n instanceof Array&&o instanceof Array){if(!Sao.common.compare(n,o))return!1}else if(moment.isMoment(n)&&moment.isMoment(o)){if(n.isDate!=o.isDate&&n.isDateTime!=o.isDateTime&&n.valueOf()!=o.valueOf())return!1}else if(moment.isDuration(n)&&moment.isDuration(o)){if(n.valueOf()!=o.valueOf())return!1}else if(n instanceof Number||o instanceof Number){if(Number(n)!==Number(o))return!1}else if(n!=o)return!1}return!0},Sao.common.contains=function(e,t){for(var i=0;i<e.length;i++)if(Sao.common.compare(e[i],t))return!0;return!1},Sao.common.intersect=function(e,t){for(var i=0,n=0,o=[];i<e.length&&n<t.length;)e[i]<t[n]?i++:(e[i]>t[n]||(o.push(e[i]),i++),n++);return o},Sao.common.scrollIntoViewIfNeeded=function(e){var t;(e=e[0])&&((t=e.getBoundingClientRect()).bottom>window.innerHeight&&e.scrollIntoView(!1),t.top<0)&&e.scrollIntoView()},Sao.common.click_press=function(i,n){return function e(t){if("keypress"!=t.type||t.which==Sao.common.RETURN_KEYCODE)return n&&jQuery(this).off("click keypress",null,e),i(t)}},Sao.common.product=function(e,t){t=t||1;for(var i=[],n=0;n<t;)i=i.concat(e),n++;var o=[[]];for(const a of i){var s=[];for(const r of o)for(const l of a)s.push(r.concat([l]));o=s}return o},Sao.common.selection=function(e,t,i=!1){var n,o,s=jQuery.Deferred();return jQuery.isEmptyObject(t)?s.reject():1!=(n=Object.keys(t).sort()).length||i?(o=new Sao.Dialog(e||Sao.i18n.gettext("Your selection:"),"selection-dialog"),n.forEach(function(e,t){jQuery("<div/>",{class:"radio"}).append(jQuery("<label/>").text(" "+e).prepend(jQuery("<input/>",{type:"radio",name:"selection",value:t}))).appendTo(o.body)}),o.body.find("input").first().prop("checked",!0),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(function(){o.modal.modal("hide"),s.reject()}).appendTo(o.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(function(){var e=o.body.find("input:checked").attr("value");o.modal.modal("hide"),s.resolve(t[n[e]])}).appendTo(o.footer),o.modal.on("hidden.bs.modal",function(e){jQuery(this).remove()}),o.modal.modal("show")):(i=n[0],s.resolve(t[i])),s},Sao.common.moment_format=function(e){return e.replace("%a","ddd").replace("%A","dddd").replace("%w","d").replace("%d","DD").replace("%b","MMM").replace("%B","MMMM").replace("%m","MM").replace("%y","YY").replace("%Y","YYYY").replace("%H","HH").replace("%I","hh").replace("%p","A").replace("%M","mm").replace("%S","ss").replace("%f","SSS").replace("%z","ZZ").replace("%Z","zz").replace("%j","DDDD").replace("%U","ww").replace("%W","WW").replace("%c","llll").replace("%x","L").replace("%X","LTS").replace("%","%%")},Sao.common.DATE_OPERATORS=[["S",moment.duration(-1,"seconds")],["s",moment.duration(1,"seconds")],["I",moment.duration(-1,"minutes")],["i",moment.duration(1,"minutes")],["H",moment.duration(-1,"hours")],["h",moment.duration(1,"hours")],["D",moment.duration(-1,"days")],["d",moment.duration(1,"days")],["W",moment.duration(-1,"weeks")],["w",moment.duration(1,"weeks")],["M",moment.duration(-1,"months")],["m",moment.duration(1,"months")],["Y",moment.duration(-1,"years")],["y",moment.duration(1,"years")]],Sao.common.date_format=function(e){var t;return jQuery.isEmptyObject(e)&&(e="%x",Sao.Session.current_session)&&(t=Sao.Session.current_session.context).locale&&t.locale.date&&(e=t.locale.date),Sao.common.moment_format(e)},Sao.common.format_time=function(e,t){return t?t.format(Sao.common.moment_format(e)):""},Sao.common.parse_time=function(e,t){t=moment(t,Sao.common.moment_format(e));return t=t.isValid()?Sao.Time(t.hour(),t.minute(),t.second(),t.millisecond()):null},Sao.common.format_date=function(e,t){return t?t.format(Sao.common.moment_format(e)):""},Sao.common.parse_date=function(e,t){t=moment(t,Sao.common.moment_format(e));return t=t.isValid()?Sao.Date(t.year(),t.month(),t.date()):null},Sao.common.format_datetime=function(e,t){return t?t.format(Sao.common.moment_format(e)):""},Sao.common.parse_datetime=function(e,t){t=moment(t,Sao.common.moment_format(e));return t=t.isValid()?Sao.DateTime(t.year(),t.month(),t.date(),t.hour(),t.minute(),t.second(),t.millisecond()):null},Sao.common.timedelta={},Sao.common.timedelta.DEFAULT_CONVERTER={s:1},Sao.common.timedelta.DEFAULT_CONVERTER.m=60*Sao.common.timedelta.DEFAULT_CONVERTER.s,Sao.common.timedelta.DEFAULT_CONVERTER.h=60*Sao.common.timedelta.DEFAULT_CONVERTER.m,Sao.common.timedelta.DEFAULT_CONVERTER.d=24*Sao.common.timedelta.DEFAULT_CONVERTER.h,Sao.common.timedelta.DEFAULT_CONVERTER.w=7*Sao.common.timedelta.DEFAULT_CONVERTER.d,Sao.common.timedelta.DEFAULT_CONVERTER.M=30*Sao.common.timedelta.DEFAULT_CONVERTER.d,Sao.common.timedelta.DEFAULT_CONVERTER.Y=365*Sao.common.timedelta.DEFAULT_CONVERTER.d,Sao.common.timedelta._get_separator=function(){return{Y:Sao.i18n.gettext("Y"),M:Sao.i18n.gettext("M"),w:Sao.i18n.gettext("w"),d:Sao.i18n.gettext("d"),h:Sao.i18n.gettext("h"),m:Sao.i18n.gettext("m"),s:Sao.i18n.gettext("s")}},Sao.common.timedelta.format=function(e,t){if(!e)return"";t=t||Sao.common.timedelta.DEFAULT_CONVERTER;for(var i,n,o=[],s="",a=((e=e.asSeconds())<0&&(s="-"),e=Math.abs(e),t=Object.keys(Sao.common.timedelta._get_separator()).map(function(e){return[e,t[e]]}),[]),r=0;r<t.length;r++){var l,c,d=t[r][0];(c=t[r][1])?(e-=(l=Math.floor(e/c))*c,a.push(l)):a.push(0)}for(r=0;r<t.length-3;r++)d=t[r][0],(c=a[r])&&o.push(c+Sao.common.timedelta._get_separator()[d]);return(jQuery(a.slice(-3)).is(function(e,t){return t})||jQuery.isEmptyObject(o))&&(n=(i=a.slice(-3))[0].toString().padStart(2,"0"),n+=":"+i[1].toString().padStart(2,"0"),(i[2]||e)&&(n+=":"+i[2].toString().padStart(2,"0")),o.push(n)),o=s+o.reduce(function(e,t){return e?e+" "+t:t}),e&&(jQuery(a.slice(-3)).is(function(e,t){return t})||(o+=" "),o+=(""+e.toFixed(6)).slice(1)),o},Sao.common.timedelta.parse=function(e,t){if(!e)return null;t=t||Sao.common.timedelta.DEFAULT_CONVERTER;var i,n,o=Sao.common.timedelta._get_separator();for(n in o)i=o[n],e=e.replace(i,i+" ");for(var s=0,a=e.split(" "),r=0;r<a.length;r++){var l=a[r];if(l.contains(":"))for(var c=l.split(":"),d=[t.h,t.m,t.s],h=0;h<Math.min(c.length,d.length);h++){var u=c[h],_=d[h],m=Math.abs(parseFloat(u))*_;isNaN(m)||(s+=m)}else{var p,f=!1;for(p in o)if(i=o[p],l.endsWith(i)){l=l.slice(0,-i.length),m=Math.abs(parseFloat(l))*t[p],isNaN(m)||(s+=m),f=!0;break}f||(m=Math.abs(parseFloat(l)),isNaN(m))||(s+=m)}}return e.contains("-")&&(s*=-1),Sao.TimeDelta(null,s)},Sao.common.btoa=function(e){for(var t=[],i=0;65535*i<e.length;i++)t.push(String.fromCharCode.apply(null,e.subarray(65535*i,65535*(i+1))));return btoa(t.join(""))},Sao.common.atob=function(e){for(var t=atob(e.base64.replace(/\s/g,"")),e=new ArrayBuffer(t.length),i=new Uint8Array(e),n=0;n<t.length;n++)i[n]=t.charCodeAt(n);return i},Sao.common.ModelAccess=Sao.class_(Object,{init:function(){this.batchnum=100,this._models=[],this._access={}},load_models:function(e){e||(this._access={});try{this._models=Sao.rpc({method:"model.ir.model.list_models",params:[{}]},Sao.Session.current_session,!1)}catch(e){Sao.Logger.error("Unable to get model list.")}},get:function(t){if(void 0===this._access[t]){var i,e=this._models.indexOf(t),e=(e<0&&(this.load_models(!1),e=this._models.indexOf(t)),this._models.slice(Math.max(0,e-Math.floor(this.batchnum/2)),e+Math.floor(this.batchnum/2)));try{i=Sao.rpc({method:"model.ir.model.access.get_access",params:[e,{}]},Sao.Session.current_session,!1)}catch(e){Sao.Logger.error(`Unable to get access for ${t}.`),i={model:{read:!0,write:!1,create:!1,delete:!1}}}this._access=jQuery.extend(this._access,i)}return this._access[t]}}),Sao.common.MODELACCESS=new Sao.common.ModelAccess,Sao.common.ModelHistory=Sao.class_(Object,{init:function(){this._models=[]},load_history:function(){return this._models=[],Sao.rpc({method:"model.ir.model.list_history",params:[{}]},Sao.Session.current_session).then(e=>{this._models=e})},contains:function(e){return~this._models.indexOf(e)}}),Sao.common.MODELHISTORY=new Sao.common.ModelHistory,Sao.common.ModelName=Sao.class_(Object,{init:function(){this._names={}},load_names:function(){this._names=Sao.rpc({method:"model.ir.model.get_names",params:[{}]},Sao.Session.current_session,!1)},get:function(e){return jQuery.isEmptyObject(this._names)&&this.load_names(),this._names[e]||""},clear:function(){this._names={}}}),Sao.common.MODELNAME=new Sao.common.ModelName,Sao.common.ModelNotification=Sao.class_(Object,{init:function(){this._depends=null},load_names:function(){this._depends=Sao.rpc({method:"model.ir.model.get_notification",params:[{}]},Sao.Session.current_session,!1)},get:function(e){return this._depends||this.load_names(),this._depends[e]||[]}}),Sao.common.MODELNOTIFICATION=new Sao.common.ModelNotification,Sao.common.ViewSearch=Sao.class_(Object,{init:function(){this.encoder=new Sao.PYSON.Encoder},load_searches:function(){return this.searches={},Sao.rpc({method:"model.ir.ui.view_search.get",params:[{}]},Sao.Session.current_session).then(e=>{this.searches=e})},get:function(e){return this.searches[e]||[]},add:function(t,i,n){return Sao.rpc({method:"model.ir.ui.view_search.set",params:[i,t,this.encoder.encode(n),{}]},Sao.Session.current_session).then(e=>{void 0===this.searches[t]&&(this.searches[t]=[]),this.searches[t].push([e,i,n,!0])})},remove:function(t,i){return Sao.rpc({method:"model.ir.ui.view_search.unset",params:[i,{}]},Sao.Session.current_session).then(()=>{for(var e=0;e<this.searches[t].length;e++)if(this.searches[t][e][0]===i){this.searches[t].splice(e,1);break}})}}),Sao.common.VIEW_SEARCH=new Sao.common.ViewSearch,Sao.common.humanize=function(i,e){var n,o;if(e=e||"",0<Math.abs(i)&&Math.abs(i)<1)for(let e=0,t=(n=["","m","µ","n","p","f","a","z","y","r","q"]).length;e<t&&(o=n[e],!(.01<=Math.abs(i)));e++)e+1<t&&(i*=1e3);else for(let e=0,t=(n=["","k","M","G","T","P","E","Z","Y","R","Q"]).length;e<t&&(o=n[e],!(Math.abs(i)<=1e3));e++)e+1<t&&(i/=1e3);return(i=i.toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),{minimumFractionDigits:0,maximumFractionDigits:Math.abs(i)<.01?15:2}))+o+e},Sao.common.EvalEnvironment=function(e,t="eval"){var i;if("eval"==t)i=e.get_eval();else for(var n in i={},e.model.fields){var o=e.model.fields[n];i[n]=o.get_on_change_value(e)}return i.id=e.id,e.group.parent&&Object.defineProperty(i,"_parent_"+e.group.parent_name,{enumerable:!0,get:function(){return Sao.common.EvalEnvironment(e.group.parent,t)}}),i.get=function(e,t){return this.hasOwnProperty(e)?this[e]:t},i},Sao.common.selection_mixin={},Sao.common.selection_mixin.init=function(){this.selection=null,this.help=null,this.inactive_selection=[],this._last_domain=null,this._values2selection={},this._domain_cache={},void 0===this.nullable_widget&&(this.nullable_widget=!0)},Sao.common.selection_mixin.init_selection=function(e,t){if(!e){e={};for(const a of this.attributes.selection_change_with||[])e[a]=null}var i=JSON.stringify(e),n=this.attributes.selection||[],o=(this.attributes.help_selection,e=>{e=jQuery.extend([],e),void 0!==this.attributes.sort&&!this.attributes.sort||e.sort(function(e,t){return e[1].localeCompare(t[1])}),this.selection=jQuery.extend([],e),this.help=this.attributes.help_selection||{},t&&t(this.selection,this.help)}),s=n instanceof Array||i in this._values2selection?(o(n=i in this._values2selection?this._values2selection[i]:n),jQuery.when()):(s=(s=jQuery.isEmptyObject(this.attributes.selection_change_with)?this.model.execute(n,[]):this.model.execute(n,[e])).then(e=>this._values2selection[i]=e)).then(o);this.inactive_selection=[],this._selection_prm=s},Sao.common.selection_mixin.update_selection=function(t,i,c){this._selection_prm.done(()=>{var s,a,r,l,e;i?(s=i.get_domain(t),"relation"in this.attributes?(a=i.get_context(t),(r=JSON.stringify([s,a]))in this._domain_cache&&(this.selection=this._domain_cache[r],this._last_domain=[s,a]),null!==this._last_domain&&Sao.common.compare(s,this._last_domain[0])&&JSON.stringify(a)==JSON.stringify(this._last_domain[1])?c&&c(this.selection,this.help):(e=["rec_name"],(l=this.attributes.help_field)&&e.push(l),(e=Sao.rpc({method:"model."+this.attributes.relation+".search_read",params:[s,0,null,null,e,a]},t.model.session,!0,!1)).done(e=>{var t=[];for(const n of e)t.push([n.id,n.rec_name]);this.nullable_widget&&t.push([null,""]);var i={};if(l)for(const o of e)i[o.id]=o[l];this._last_domain=[s,a],this._domain_cache[r]=t,this.selection=jQuery.extend([],t),this.help=i,c&&c(this.selection,this.help)}),e.fail(()=>{var e=[];this.nullable_widget&&e.push([null,""]),this._last_domain=null,this.selection=e,c&&c(this.selection,this.help)}))):(e=this.attributes.selection_change_with||[],delete(e=t._get_on_change_args(e)).id,Sao.common.selection_mixin.init_selection.call(this,e,()=>{Sao.common.selection_mixin.filter_selection.call(this,s,t,i),c&&c(this.selection,this.help)}))):c&&c(this.selection,this.help)})},Sao.common.selection_mixin.filter_selection=function(i,e,t){if(!jQuery.isEmptyObject(i)){var n,o,s=new Sao.common.DomainInversion,a=e=>{var t={};return t[this.field_name]=e[0],s.eval_domain(i,t)},r=t.description.type;if("reference"==r){t=t.get_models(e);o=t,n=function(e){return~o.indexOf(e[0])||jQuery.isEmptyObject(o)}}else{if("multiselection"==r)return;n=a}this.selection=this.selection.filter(n)}},Sao.common.selection_mixin.get_inactive_selection=function(e){if(!this.attributes.relation)return jQuery.when([]);if(null===e)return jQuery.when([null,""]);for(var t=0,i=this.inactive_selection.length;t<i;t++)if(e==this.inactive_selection[t][0])return jQuery.when(this.inactive_selection[t]);return Sao.rpc({method:"model."+this.attributes.relation+".read",params:[[e],["rec_name"],{}]},Sao.Session.current_session).then(e=>(this.inactive_selection.push([e[0].id,e[0].rec_name]),[e[0].id,e[0].rec_name]))},Sao.common.Button=Sao.class_(Object,{init:function(e,t,i,n){this.attributes=e,t?this.el=t:(this.el=jQuery("<button/>",{title:e.string||"",name:e.name||""}),this.el.text(e.string||""),this.attributes.rule&&this.el.append(" ").append(jQuery("<span/>",{class:"badge"})),this.el.attr("accesskey",Sao.common.accesskey(e.string||""))),this.icon=this.el.children("img"),this.icon.length||(this.icon=jQuery("<img/>",{class:"icon"}).prependTo(this.el),this.icon.hide()),this.el.addClass(["btn","btn-horizontal",n||"btn-default",i||""].join(" ")),this.el.attr("type","button"),this.icon.attr("aria-hidden",!0),this.set_icon(e.icon)},set_icon:function(e){e?Sao.common.ICONFACTORY.get_icon_url(e).done(e=>{this.icon.attr("src",e),this.icon.show()}):(this.icon.attr("src",""),this.icon.hide())},set_state:function(e){var t=e?e.expr_eval(this.attributes.states||{}):{};if(t.invisible?this.el.hide():this.el.show(),this.el.prop("disabled",Boolean(t.readonly)),this.set_icon(t.icon||this.attributes.icon),this.attributes.rule&&(e?e.get_button_clicks(this.attributes.name):jQuery.when()).then(e=>{var t=this.el.children(".badge"),i=[],n="";if(!jQuery.isEmptyObject(e)){for(var o in e)i.push(e[o]);n=Sao.i18n.gettext("By: ")+i.join(Sao.i18n.gettext(", "))}t.text(i.length||""),t.attr("title",n)}),(void 0===this.attributes.type||"class"===this.attributes.type)&&e)for(var i=e.group.parent;i;){if(i.modified){this.el.prop("disabled",!0);break}i=i.group.parent}}}),Sao.common.udlex=Sao.class_(Object,{init:function(e){var t=Sao.class_(Object,{init:function(e){this.stream=e.split(""),this.i=0},read:function(e=1){var t;return this.i>=this.stream.length?null:(t=this.stream.slice(this.i,this.i+e).join(),this.i+=e,t)}});this.instream=new t(e),this.eof=null,this.commenters="",this.nowordchars=[":",">","<","=","!",'"',";","(",")"],this.whitespace=" \t\r\n",this.whitespace_split=!1,this.quotes='"',this.escape="\\",this.escapedquotes='"',this.state=" ",this.pushback=[],this.token=""},get_token:function(){return 0<this.pushback.length?this.pushback.shift():this.read_token()},read_token:function(){for(var e=!1,t=" ";;){var i=this.instream.read(1);if(null===this.state){this.token="";break}if(" "==this.state){if(!i){this.state=null;break}if(this.whitespace.contains(i)){if(this.token||e)break}else if(!this.commenters.contains(i))if(this.escape.contains(i))t="a",this.state=i;else if(~this.nowordchars.indexOf(i)){if(this.quotes.contains(i))this.state=i;else if(this.whitespace_split)this.token=i,this.state="a";else if(this.token=i,this.token||e)break}else this.token=i,this.state="a"}else if(this.quotes.contains(this.state)){if(e=!0,!i)throw"no closing quotation";i==this.state?this.state="a":this.escape.contains(i)&&this.escapedquotes.contains(this.state)?(t=this.state,this.state=i):this.token=this.token+i}else if(this.escape.contains(this.state)){if(!i)throw"no escaped character";this.quotes.contains(t)&&i!=this.state&&i!=t&&(this.token=this.token+this.state),this.token=this.token+i,this.state=t}else if("a"==this.state){if(!i){this.state=null;break}if(this.whitespace.contains(i)){if(this.state=" ",this.token||e)break}else if(!this.commenters.contains(i))if(this.quotes.contains(i))this.state=i;else if(this.escape.contains(i))t="a",this.state=i;else if(!~this.nowordchars.indexOf(i)||this.quotes.contains(i)||this.whitespace_split)this.token=this.token+i;else if(this.pushback.unshift(i),this.state=" ",this.token)break}}var n=this.token;return this.token="",n=e||""!==n?n:null},next:function(){var e=this.get_token();return e==this.eof?null:e}}),Sao.common.DomainParser=Sao.class_(Object,{OPERATORS:["!=","<=",">=","=","!","<",">"],init:function(e,t){this.fields={},this.strings={},this.context=t,this.update_fields(e)},update_fields:function(e,t,i){for(var n in t=t||"",i=i||"",e){var o,s=e[n];(s.searchable||void 0===s.searchable)&&"rec_name"!==n&&(s=jQuery.extend({},s),n=t?t+"."+n:n,o=i?i+"."+s.string:s.string,s.string=o,s.name=n,this.fields[n]=s,s=(this.strings[s.string.toLowerCase()]=s).relation_fields)&&this.update_fields(s,n,o)}},parse:function(t){try{for(var e=new Sao.common.udlex(t),i=[];;){var n=e.next();if(null===n)break;i.push(n)}return i=this.group_operator(i),i=this.parenthesize(i),i=this.group(i),i=this.operatorize(i,"or"),i=this.operatorize(i,"and"),i=this.parse_clause(i),this.simplify(i)}catch(e){if("no closing quotation"==e)return this.parse(t+'"');throw e}},stringable:function(e){return!e||(e=~["AND","OR"].indexOf(e[0])?e.slice(1):e).every(e=>{var t,i,n;return!(e&&!jQuery.isEmptyObject(e))||(t=function(e){return e instanceof Array},(~["AND","OR"].indexOf(e[0])||t(e[0]))&&e.slice(1).every(t)?this.stringable(e):(t=e[0],e=e[2],(t=t.endsWith(".rec_name")?t.slice(0,-9):t)in this.fields?(i=this.fields[t],~["many2one","one2one","one2many","many2many"].indexOf(i.type)?(n=function(e){return"string"==typeof e||null===e},e instanceof Array?e.every(n):n(e)):"multiselection"!=i.type||!e||jQuery.isEmptyObject(e)||e instanceof Array):"rec_name"==t))})},string:function(e){var t;return jQuery.isEmptyObject(e)?"":(t=" ","AND"!=e[0]&&"OR"!=e[0]||("OR"==e[0]&&(t=" | "),e=e.slice(1)),e.map(e=>{var t,i,n,o;return jQuery.isEmptyObject(e)?"":"string"!=typeof e[0]||~["AND","OR"].indexOf(e[0])?"("+this.string(e)+")":(n=e[0],t=e[1],i=e[2],(n=n.endsWith(".rec_name")?n.slice(0,-9):n)in this.fields?(n=this.fields[n],o=null,3<e.length&&(o=e[3]),t.contains("ilike")&&(this.is_full_text(i)?i=i.slice(1,-1):this.is_like(i)||(t="ilike"==t?"=":"!",i=this.unescape(i))),(e=this.default_operator(n))==t.trim()?(t="",~this.OPERATORS.indexOf(i)&&(t='"" ')):t.contains(e)&&(t.contains("not")||t.contains("!"))&&(t=t.replace(e,"").replace("not","!").trim()),t.endsWith("in")&&(t=i instanceof Array&&1==i.length?"not in"==t?"!=":"=":"not in"==t?"!":""),e=this.format_value(n,i,o),~this.OPERATORS.indexOf(t)&&~["char","text","selection"].indexOf(n.type)&&""===i&&(e='""'),this.quote(n.string)+": "+t+e):(this.is_full_text(i)&&(i=i.slice(1,-1)),this.quote(i)))}).join(t))},completion:function(e){var t=[],i=this.parse(e),n=0;for(u=e.length;0<u&&(")"!=e[u]&&" "!=e[u]);u--)")"==e[u]&&(n+=1);function o(e,t){return 0<t?e.substring(0,e.length-t):e}var s,a,r,l=this.ending_clause(i),c=l[0],d=l[1]-n,l=this.string(i);(l=0<d?l.substring(0,l.length-d):l)!=e&&t.push(l);if(null!==c&&0===n)for(var h=this.complete(c),u=0,_=h.length;u<_;u++)s=h[u],s=this.string(this.replace_ending_clause(i,s)),t.push(o(s,d));if(0<e.length){if(" "!=e.substr(e.length-1,1))return t;if(2<=e.length||":"==e.substr(e.length-2,1))return t}for(r in this.strings){m=this.strings[r],a="","ilike"!=(p=this.default_operator(m))&&"not ilike"!=p||(a=this.likify(a));var m=this.append_ending_clause(i,[m.name,p,a],d),p=this.string(m);t.push(o(p,d))}return t},complete:function(e){var t,i,n,o,s=[];if(1==e.length?t=e[0]:3==e.length?(t=e[0],i=e[1],n=e[2]):(t=e[0],i=e[1],n=e[2],e[3],t.endsWith(".rec_name")&&(t=t.substring(0,t.length-9))),"rec_name"==t&&("ilike"==i&&((e=n.replace(/%%/g,"__")).startsWith("%")||e.endsWith("%")?n=e.substring(1,e.length-1):~e.indexOf("%")&&(n=n.replace(/%%/g,"%")),i=null),t=n,n=""),(t=null==t?"":t).toLowerCase()in this.strings||t in this.fields)if(o=t in this.fields?this.fields[t]:this.strings[t.toLowerCase()],i)for(var a=this.complete_value(o,n),r=0,l=a.length;r<l;r++)s.push([o.name,i,a[r]]);else n="","ilike"!=(i=this.default_operator(o))&&"not ilike"!=i||(n=this.likify(n)),s.push([o.name,i,n]);else for(var c in this.strings)(o=this.strings[c]).string.toLowerCase().startsWith(t.toLowerCase())&&(n="","ilike"==(i=this.default_operator(o))&&(n=this.likify(n)),s.push([o.name,i,n]));return s},is_subdomain:function(e){return e instanceof Array&&!e.clause},ending_clause:function(e,t=0){return 0===e.length?[null,t]:(e=e[e.length-1],this.is_subdomain(e)?this.ending_clause(e,t+1):[e,t])},replace_ending_clause:function(e,t){for(var i=[],n=0,o=e.length-1;n<o;n++)i.push(e[n]);return this.is_subdomain(e[n])?i.push(this.replace_ending_clause(e[n],t)):i.push(t),i},append_ending_clause:function(e,t,i){var n;return 0===e.length?[t]:(n=e.slice(0,-1),e=e[e.length-1],this.is_subdomain(e)?n.push(this.append_ending_clause(e,t,i-1)):(n.push(e),0===i&&n.push(t)),n)},complete_value:function(s,a){function e(){for(var e,t=[],i=null!==a?a:"",i=(i=a instanceof Array?a[a.length-1]||"":i).replace(/^%*|%*$/g,""),n=0,o=s.selection.length;n<o;n++)e=s.selection[n][0],s.selection[n][1].toLowerCase().startsWith(i.toLowerCase())&&(a instanceof Array?t.push(a.slice(0,-1).concat([e])):t.push(e));return t}function t(){return[Sao.Date(),Sao.DateTime().utc()]}var i={boolean:function(){return null==a?[!0,!1]:a?[!1]:[!0]},selection:e,multiselection:e,reference:()=>{for(var e,t=[],i=null!==a?a:"",i=(i=a instanceof Array?a[a.length-1]:i).replace(/^%*|%*$/g,""),n=0,o=s.selection.length;n<o;n++)e=s.selection[n][0],s.selection[n][1].toLowerCase().startsWith(i.toLowerCase())&&(a instanceof Array?t.push(a.slice(0,-1).concat([e])):t.push(this.likify(e)));return t},datetime:t,timestamp:t,date:function(){return[Sao.Date()]},time:function(){return[Sao.Time()]}};return s.type in i?i[s.type]():[]},group_operator:function(e){var t=e[0],i=null,n=[];for(const i of e.slice(1))t="="==i&&t&&~this.OPERATORS.indexOf(t+i)?(n.push(t+i),null):(null!==t&&n.push(t),i);return null!==t&&n.push(t),n},parenthesize:function(e){var t=[],i=t,n=[];for(const o of e)void 0!==i&&("("==o?(n.push(i),i=i[i.push([])-1]):")"==o?i=n.pop():i.push(o));return t},group:function(e){var t=[];const c=e=>{function t(e){(e=[e]).clause=!0,o.push(e)}var o=[],i=e.indexOf(":");if(~i){for(var n=0;n<i;n++)if((a=e.slice(n,i).join(" ")).toLowerCase()in this.strings){jQuery.isEmptyObject(e.slice(0,n))?t(null):e.slice(0,n).forEach(t);for(var s,a=[a],r=[""].concat(this.OPERATORS),l=(i+1<e.length&&~r.indexOf(e[i+1])?(a=a.concat([e[i+1]]),i+=1):a=a.concat([null]),[]);i+2<e.length&&";"==e[i+2];)l.push(e[i+1]),i+=2;c(e.slice(i+1)).forEach(function(i,n){return function(e){var t;jQuery.isEmptyObject(i)?o.push(e):(jQuery.isEmptyObject(n)?(t=i.concat(e)).clause=!0:(null!==e[0]&&n.push(e[0]),(t=i.concat([n])).clause=!0),o.push(t),i.splice(0,i.length))}}(a,l)),jQuery.isEmptyObject(a)||(jQuery.isEmptyObject(l)?(s=a.concat([null])).clause=!0:(s=a.concat([l])).clause=!0,o.push(s));break}}else e.forEach(t);return o};var i=[];for(const n of e)if(this.is_generator(n)){for(const o of c(i))Sao.common.compare(o,[null])||t.push(o);i=[],t.push(this.group(n))}else i.push(n);for(const s of c(i))Sao.common.compare(s,[null])||t.push(s);return t},is_generator:function(e){return e instanceof Array&&void 0===e.clause},operatorize:function(e,t){for(var i=[],n=(t=t||"or",e=jQuery.extend([],e),{or:"|",and:"&"}[t]),o=function(e){return e instanceof Array?Sao.common.compare(e,[n]):e==n},s=e.shift();o(s);)s=e.shift();if(void 0!==s){this.is_generator(s)&&(s=this.operatorize(s,t));for(var a=null;!jQuery.isEmptyObject(e);)if(a=e.shift(),o(a=this.is_generator(a)&&!o(a)?this.operatorize(a,t):a)){for(a=e.shift();o(a);)a=e.shift();void 0!==(a=this.is_generator(a)?this.operatorize(a,t):a)?s=[t.toUpperCase(),s,a]:o(s)||(i.push([t.toUpperCase(),s]),s=null),a=null}else o(s)||i.push(s),s=a;jQuery.isEmptyObject(e)&&(null===a||o(a)?null===s||o(s)||i.push(s):i.push(a))}return i},_clausify:function(e){return e.clause=!0,e},parse_clause:function(e){var l=[];return e.forEach(e=>{if(this.is_generator(e))l.push(this.parse_clause(e));else if("OR"===e||"AND"===e)l.push(e);else if(1!=e.length||e[0]instanceof Array){if(3==e.length&&e[0].toLowerCase()in this.strings){e[0];var t,i,n=e[1],o=e[2],s=this.strings[e[0].toLowerCase()],a=s.name,r=null;if("reference"==s.type?(r=(i=this.split_target_value(s,o))[0],o=i[1],r&&(a+=".rec_name")):"multiselection"!=s.type||null===o||o instanceof Array||(o=[o]),n=n||this.default_operator(s),"!"==(n=o instanceof Array&&"multiselection"!=s.type?"!"==n?"not in":"in":n)&&(n=this.negate_operator(this.default_operator(s))),null===o&&n.endsWith("in")&&(n=n.startsWith("not")?"!=":"="),~["integer","float","numeric","datetime","timestamp","date","time"].indexOf(s.type))if("string"==typeof o&&o.contains(".."))return i=o.split("..",2),t=this.convert_value(s,i[0],this.context),i=this.convert_value(s,i[1],this.context),void l.push([this._clausify([a,">=",t]),this._clausify([a,"<=",i])]);o instanceof Array?(o=o.map(e=>this.convert_value(s,e,this.context)),~["many2one","one2many","many2many","one2one","many2many","one2one"].indexOf(s.type)&&(a+=".rec_name")):o=this.convert_value(s,o,this.context),n.contains("like")&&(o=this.likify(o)),l.push(r?this._clausify([a,n,o,r]):this._clausify([a,n,o]))}}else l.push(this._clausify(["rec_name","ilike",this.likify(e[0])]))}),l},likify:function(e,t){return t=t||"\\",e?(t=e.replace(t+"%","").replace(t+"_","")).contains("%")||t.contains("_")?e:"%"+e+"%":"%"},is_full_text:function(e,t){t=t||"\\";var i=e;return!(i=(i="%"==i.charAt(0)&&"%"==i.charAt(i.length-1)?i.slice(1,-1):i).replace(t+"%","").replace(t+"_","")).contains("%")&&!i.contains("_")&&e.startsWith("%")&&e.endsWith("%")},is_like:function(e,t){e=e.replace((t=t||"\\")+"%","").replace(t+"_","");return e.contains("%")||e.contains("_")},unescape:function(e,t){return e.replace((t=t||"\\")+"%","%").replace(t+"_","_")},quote:function(e,t=!1){if("string"==typeof e){if(t&&""===e)return'""';(e=e.contains("\\")?e.replace(new RegExp("\\\\","g"),"\\\\"):e).contains('"')&&(e=e.replace(new RegExp('"',"g"),'\\"'));for(var i=[":"," ","(",")"].concat(this.OPERATORS),n=0;n<i.length;n++){var o=i[n];if(e.contains(o))return'"'+e+'"'}}return e},default_operator:function(e){return~["char","text","many2one","many2many","one2many","reference","one2one"].indexOf(e.type)?"ilike":"multiselection"==e.type?"in":"="},negate_operator:function(e){switch(e){case"ilike":return"not ilike";case"=":return"!=";case"in":return"not in"}},time_format:function(e){return new Sao.PYSON.Decoder({}).decode(e.format)},split_target_value:function(e,t){var i=null;if("string"==typeof t)for(var n=0;n<e.selection.length;n++){var o=e.selection[n],s=o[0],o=o[1];if(t.toLowerCase().startsWith(o.toLowerCase()+",")){i=s,t=t.slice(o.length+1);break}}return[i,t]},convert_value:function(n,o,e){e=e||{};function t(){if("string"==typeof o)for(var e=0;e<n.selection.length;e++){var t=n.selection[e],i=t[0],t=t[1];if(o.toLowerCase()==t.toLowerCase())return i}return o}var i={boolean:function(){return"string"==typeof o?[Sao.i18n.gettext("y"),Sao.i18n.gettext("Yes"),Sao.i18n.gettext("True"),Sao.i18n.gettext("t"),"1"].some(function(e){return e.toLowerCase().startsWith(o.toLowerCase())}):null},float:function(){var e=Number(n.factor||1),t=Number(o);return isNaN(t)||""===o||null===o?null:t/e},integer:function(){var e=Number(n.factor||1,10),t=parseInt(o,10);return isNaN(t)?null:t/e},numeric:function(){var e=Number(n.factor||1),t=Number(o);return isNaN(t.valueOf())||""===o||null===o?null:new Sao.Decimal(t/e)},selection:t,multiselection:t,reference:t,datetime:()=>Sao.common.parse_datetime(Sao.common.date_format(e.date_format)+" "+this.time_format(n),o),date:function(){return Sao.common.parse_date(Sao.common.date_format(e.date_format),o)},time:()=>{try{return Sao.common.parse_time(this.time_format(n),o)}catch(e){return null}},timedelta:()=>{var e=null;return n.converter&&(e=this.context[n.converter]),Sao.common.timedelta.parse(o,e)},many2one:function(){return""===o?null:o}},i=(i.timestamp=i.datetime,i[n.type]);return i?i():o},format_value:function(o,s,t=null,i={},e=!1){function n(){var e,t,i,n;return s||0===s||s===new Sao.Decimal(0)?(e=0,t=Number(o.factor||1),(n=String(s*t)).contains("e")&&(i=n.split("e")[1],n=n.split("e")[0],e-=parseInt(i)),n.contains(".")&&(e+=n.replace(/0+$/,"").split(".")[1].length),(s*t).toFixed(e)):""}function a(){if(o.selection instanceof Array)for(var e=0;e<o.selection.length;e++)if(o.selection[e][0]==s)return o.selection[e][1];return s||""}var r={boolean:function(){return!1===s?Sao.i18n.gettext("False"):s?Sao.i18n.gettext("True"):""},integer:function(){var e=Number(o.factor||1);return s||0===s?""+parseInt(parseInt(s,10)*e,10):""},float:n,numeric:n,selection:a,multiselection:a,reference:function(){if(!t)return a();for(var e=0;e<o.selection.length;e++)if(o.selection[e][0]==t){t=o.selection[e][1];break}return t+","+s},datetime:()=>s?s.isDate||!(s.hour()||s.minute()||s.second())?Sao.common.format_date(Sao.common.date_format(i.date_format),s):Sao.common.format_datetime(Sao.common.date_format(i.date_format)+" "+this.time_format(o),s):"",date:()=>Sao.common.format_date(Sao.common.date_format(i.date_format),s),time:()=>s?Sao.common.format_time(this.time_format(o),s):"",timedelta:()=>{var e;return s&&s.valueOf()?(e=null,o.converter&&(e=this.context[o.converter]),Sao.common.timedelta.format(s,e)):""},many2one:function(){return null===s?"":s}};return r.timestamp=r.datetime,s instanceof Array?s.map(e=>this.format_value(o,e,null,i,!0)).join(";"):(r=r[o.type])?this.quote(r(s)):null===s?"":this.quote(s,e)},simplify:function(e){return this.is_subdomain(e)?1==e.length&&this.is_subdomain(e[0])?this.simplify(e[0]):2!=e.length||"AND"!=e[0]&&"OR"!=e[0]||!this.is_subdomain(e[1])?(e=3!=e.length||"AND"!=e[0]&&"OR"!=e[0]||!this.is_subdomain(e[1])||e[0]!=e[1][0]?e:this.simplify(e[1]).concat([e[2]])).map(e=>this.simplify(e)):this.simplify(e[1]):e}}),Sao.common.DomainInversion=Sao.class_(Object,{and:function(e,t){return e&&t},or:function(e,t){return e||t},OPERATORS:{"=":function(e,t){return Sao.common.DomainInversion.equals(e,t)},">":function(e,t){return t<e},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">=":function(e,t){return t<=e},"!=":function(e,t){return!Sao.common.DomainInversion.equals(e,t)},in:function(e,t){return Sao.common.DomainInversion.in_(e,t)},"not in":function(e,t){return!Sao.common.DomainInversion.in_(e,t)},like:function(e,t){return Sao.common.DomainInversion.sql_like(e,t,!1)},ilike:function(e,t){return Sao.common.DomainInversion.sql_like(e,t,!0)},"not like":function(e,t){return!Sao.common.DomainInversion.sql_like(e,t,!1)},"not ilike":function(e,t){return!Sao.common.DomainInversion.sql_like(e,t,!0)},child_of:function(){return!0},"not child_of":function(){return!0}},locale_part:function(e,t,i="id"){return e===t?i:e.contains(".")?e.split(".").slice(1).join("."):e},is_leaf:function(e){return e instanceof Array&&2<e.length&&"string"==typeof e[1]},constrained_leaf:function(e,t){void 0===t&&(t=this.and);e[0];var i=e[1];e[2];return!!("="===i&t===this.and)},eval_leaf:function(e,t,i){void 0===i&&(i=this.and);var i=e[0],n=e[1],e=e[2];return i.contains(".")?Boolean(t[i.split(".")[0]]):(t=t[i],~["=","!="].indexOf(n)||null!=t&&null!=e||~["in","not in"].indexOf(n)&&null==t&&e instanceof Array&&~e.indexOf(null)?(moment.isMoment(t)&&!e&&(e=(t.isDateTime?Sao.DateTime:Sao.Date).min),(t=moment.isMoment(e)&&!t?(e.isDateTime?Sao.DateTime:Sao.Date).min:t)instanceof Array&null===e&&(e=[]),"string"==typeof t&&e instanceof Array&&2==e.length?e=e.join(","):t instanceof Array&&"string"==typeof e&&2==t.length&&(t=t.join(",")),!((n=~["=","!="].indexOf(n)&&t instanceof Array&&"number"==typeof e?{"=":"in","!=":"not in"}[n]:n)in this.OPERATORS)||this.OPERATORS[n](t,e)):void 0)},inverse_leaf:function(e){return~["AND","OR"].indexOf(e)?e:this.is_leaf(e)?!e[1].contains("child_of")||e[0].contains(".")||3==e.length?e:[e[3]].concat(e.slice(1)):e.map(e=>this.inverse_leaf(e))},filter_leaf:function(e,t,i){return~["AND","OR"].indexOf(e)?e:this.is_leaf(e)?e[0].startsWith(t)&&3<e.length&&e[3]!==i?["id","=",null]:e:e.map(e=>this.filter_leaf(e,t,i))},eval_domain:function(e,t,i){return void 0===i&&(i=this.and),this.is_leaf(e)?this.eval_leaf(e,t,i):!(!jQuery.isEmptyObject(e)||i!=this.and)||(!jQuery.isEmptyObject(e)||i!=this.or)&&("AND"==e[0]?this.eval_domain(e.slice(1),t):"OR"==e[0]?this.eval_domain(e.slice(1),t,this.or):i(Boolean(this.eval_domain(e[0],t)),Boolean(this.eval_domain(e.slice(1),t,i))))},localize_domain:function(e,t,i){var n,o;return~["AND","OR",!0,!1].indexOf(e)?e:this.is_leaf(e)?e[1].contains("child_of")?1<e[0].split(".").length?[e[0].split(".").slice(1).join(".")].concat(e.slice(1)):3==e.length?e:[e[3]].concat(e.slice(1,-1)):(n="id","string"==typeof e[2]&&(n="rec_name"),o=i?3:4,[this.locale_part(e[0],t,n)].concat(e.slice(1,o)).concat(e.slice(4))):e.map(e=>this.localize_domain(e,t,i))},_sort_key:function(e){var t;return e.length?this.is_leaf(e)?[1,e]:~["AND","OR"].indexOf(e)?[0,e]:(t=e.map(this._sort_key.bind(this)),[Math.max(...t.map(e=>e[0]))+1,t]):[0,e]},_domain_compare:function(e,t){if(e instanceof Array&&t instanceof Array){for(var i,n=Math.min(e.length,t.length),o=0;o<n;o++)if(0!=(i=this._domain_compare(e[o],t[o])))return i;return e.length==t.length?0:e.length<t.length?-1:1}return e==t?0:e<t?-1:1},sort:function(e){return e.length?this.is_leaf(e)||~["AND","OR"].indexOf(e)?e:((e=e.map(this.sort.bind(this))).sort((e,t)=>this._domain_compare(this._sort_key(e),this._sort_key(t))),e):[]},prepare_reference_domain:function(e,t){function i(e){var t,i,n=null,o=null;return"string"==typeof e&&e.contains(",")?((i=(t=e.split(",")).splice(0,1)).push(t.join(",")),n=i[0],"%"!=(o=i[1])&&(o=parseInt(o,10),isNaN(o))&&(n=null,o=e)):o=e instanceof Array&&2==e.length&&"string"==typeof e[0]&&("number"==typeof e[1]||"%"==e[1])?(n=e[0],e[1]):e,[n,o]}var n,o,s;if(~["AND","OR"].indexOf(e))return e;if(this.is_leaf(e)){if(e[0]!=t)return e;if("="==e[1]||"!="==e[1]){if(n=(s=i(e[2]))[0],o=s[1],n)return"%"==o?"="==e[1]?[t+".id","!=",null,n]:[t,"not like",e[2]]:[t+".id",e[1],o,n]}else if("in"==e[1]||"not in"==e[1]){for(var a={},r=!1,l=0;l<e[2].length;l++){if(n=(s=i(e[2][l]))[0],o=s[1],!n){r=!0;break}n in a||(a[n]=[]),a[n].push(o)}if(!r){var c,d="in"==e[1]?["OR"]:["AND"];for(n in a)~(c=a[n]).indexOf("%")?"in"==e[1]?d.push([t+".id","!=",null,n]):d.push([t,"not like",n+",%"]):d.push([t+".id",e[1],c.map(Number),n]);return d}}return[]}return e.map(e=>this.prepare_reference_domain(e,t))},extract_reference_models:function(e,s){var a;return~["AND","OR"].indexOf(e)?[]:this.is_leaf(e)?e[0].split(".",1)[0]==s&&3<e.length?[e[3]]:[]:(a=[],e.map(e=>{for(var t=this.extract_reference_models(e,s),i=0,n=t.length;i<n;i++){var o=t[i];~a.indexOf(o)||a.push(o)}}),a)},_bool_operator:function(e){var t="AND";return t=0<e.length&&("AND"==e[0]||"OR"==e[0])?e[0]:t},simplify_nested:function(e){if(e.length){if(this.is_leaf(e))return[e];if("AND"==e||"OR"==e)return[e];if(e instanceof Array&&1==e.length)return this.simplify_nested(e[0]);var t,i=[];for(t of e){var n=this.simplify_nested(t);this._bool_operator(n)==this._bool_operator(i)||1==n.length?0<i.length&&0<n.length&&("AND"==n[0]||"OR"==n[0])?i.push(...n.slice(1)):i.push(...n):i.push(n)}return i}return[]},simplify_duplicate:function(e){var t,i=[],n=null;~["AND","OR"].indexOf(e[0])&&(n=e[0],e=e.slice(1));for(t of e){var o=this.simplify(t);if(0==o.length){if("OR"===n)return[]}else{var s,a=!1;for(s of i)if(Sao.common.compare(o,s)){a=!0;break}a||i.push(o)}}return n&&1<i.length&&i.unshift(n),i},simplify:function(e){return this.is_leaf(e)?[e]:e.length?this.simplify_nested(this.simplify_duplicate(e)):[]},simplify_AND:function(e){if(this.is_leaf(e))return e;if("OR"==e)return e;var t=[];for(const i of e)"AND"!=i&&t.push(this.simplify_AND(i));return t},canonicalize:function(e){return this.simplify_AND(this.sort(this.simplify(e)))},merge:function(e,t){var i;return jQuery.isEmptyObject(e)||~["AND","OR"].indexOf(e)?[]:(i="OR"==e[0]?"OR":"AND",this.is_leaf(e)?[e]:void 0===t?[i].concat([].concat.apply([],e.map(e=>this.merge(e,i)))):i==t?[].concat.apply([],e.map(e=>this.merge(e,i))):[this.merge(e)])},concat:function(e,t){var i=[];t&&i.push(t);for(const n of e)jQuery.isEmptyObject(n)||i.push(n);return this.simplify(this.merge(i))},unique_value:function(o,s=!0){if(o instanceof Array&&1==o.length){let[e,t,i,...n]=o[0];o=e.split(".").length-1;if(("="==t||s&&"in"==t&&1==i.length)&&(!o||1==o&&n.length&&e.endsWith(".id")))return"in"==t&&s&&(i=i[0]),n.length&&e.endsWith(".id")&&(n=n[0],i=[n,i]),[!0,e,i]}return[!1,null,null]},parse:function(e){var t=Sao.common.DomainInversion.And,i=Sao.common.DomainInversion.Or;return this.is_leaf(e)?e:jQuery.isEmptyObject(e)?new t([]):"OR"===e[0]?new i(e.slice(1)):("AND"===e[i=0]&&(i=1),new t(e.slice(i)))},domain_inversion:function(e,t,i={}){e=this.parse(e);return!~e.variables.indexOf(t)||e.inverse(t,i)}}),Sao.common.DomainInversion.equals=function(e,t){return e instanceof Array&&t instanceof Array?Sao.common.compare(e,t):moment.isMoment(e)&&moment.isMoment(t)?e.isDate==t.isDate&&e.isDateTime==t.isDateTime&&e.valueOf()==t.valueOf():e instanceof Number||t instanceof Number?Number(e)===Number(t):e===t},Sao.common.DomainInversion.in_=function(e,t){if(e instanceof Array){if(t instanceof Array){for(var i=0,n=e.length;i<n;i++)if(~t.indexOf(e[i]))return!0;return!1}return Boolean(~e.indexOf(t))}return Boolean(~t.indexOf(e))},Sao.common.DomainInversion.sql_like=function(e,t,i){for(var n,o=!1,s=[],a=t.split(/(.|\\)/),r=1,l=a.length;r<l;r+=2)n=a[r],o?("%"==n||"_"==n?s.push(n):s.push("\\",n),o=!1):"\\"==n?o=!0:s.push("_"==n?".":"%"==n?".*":n);t.startsWith("%")||s.splice(0,0,"^"),t.endsWith("%")||s.push("$");t=i?"i":"";return new RegExp(s.join(""),t).test(e)},Sao.common.DomainInversion.And=Sao.class_(Object,{init:function(e){this.domain_inversion=new Sao.common.DomainInversion,this.branches=e.map(this.domain_inversion.parse.bind(this.domain_inversion)),this.variables=[];for(var t=0,i=this.branches.length;t<i;t++){var n=this.branches[t];this.domain_inversion.is_leaf(n)?this.variables.push(this.base(n[0])):n instanceof Sao.common.DomainInversion.And&&(this.variables=this.variables.concat(n.variables))}},base:function(e){return e.contains(".")?e.split(".")[0]:e},inverse:function(e,t){for(var i=Sao.common.DomainInversion,n=[],o=0,s=this.branches.length;o<s;o++){var a=this.branches[o];if(a instanceof i.And){var r=a.inverse(e,t),l="boolean"==typeof r;if(~a.variables.indexOf(e))if(l){if(!r)return!1}else n.push(r)}else if(this.domain_inversion.is_leaf(a)&&this.base(a[0])===e)n.push(a);else{l=a[0];if(l in t&&!(l in t&&(this.domain_inversion.eval_leaf(a,t,this.domain_inversion.and)||this.domain_inversion.constrained_leaf(a,this.domain_inversion.and))))return!1;n.push(!0)}}return n=n.filter(function(e){return!0!==e}),!!jQuery.isEmptyObject(n)||this.domain_inversion.simplify(n)}}),Sao.common.DomainInversion.Or=Sao.class_(Sao.common.DomainInversion.And,{inverse:function(t,i){var e=Sao.common.DomainInversion,n=[];if(!jQuery.isEmptyObject(this.variables.filter(function(e){return!(e in i)&&e!=t})))return!0;for(var o=0,s=this.branches.length;o<s;o++){var a=this.branches[o];if(a instanceof e.And){var r=a.inverse(t,i),l="boolean"==typeof r;if(~a.variables.indexOf(t))if(l){if(r)return!0}else n.push(r);else if(l&&r)return!0}else if(this.domain_inversion.is_leaf(a)&&this.base(a[0])==t)n.push(a);else{l=a[0];if((l=this.base(l))in i&&this.domain_inversion.eval_leaf(a,i,this.domain_inversion.or)||this.domain_inversion.constrained_leaf(a,this.domain_inversion.or))return!0;l in i&&!this.domain_inversion.eval_leaf(a,i,this.domain_inversion.or)&&n.push(!1)}}return n=n.filter(function(e){return!1!==e}),!jQuery.isEmptyObject(n)&&this.domain_inversion.simplify(["OR"].concat(n))}}),Sao.common.mimetypes={csv:"text/csv",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",gif:"image/gif",html:"text/html",jpeg:"image/jpeg",jpg:"image/jpeg",mpeg:"video/mpeg",mpg:"video/mpeg",ods:"application/vnd.oasis.opendocument.spreadsheet",odt:"application/vnd.oasis.opendocument.text",ogg:"audio/ogg",pdf:"application/pdf",png:"image/png",svg:"image/svg+xml",text:"text/plain",tif:"image/tif",tiff:"image/tif",txt:"text/plain",webp:"image/webp",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml:"application/xml",xpm:"image/x-xpixmap"},Sao.common.guess_mimetype=function(e){for(var t in Sao.common.mimetypes)if(new RegExp(".*."+t+"$","i").test(e))return Sao.common.mimetypes[t];return"application/octet-binary"},Sao.common.LOCAL_ICONS=["tryton-add","tryton-archive","tryton-attach","tryton-back","tryton-bookmark-border","tryton-bookmark","tryton-bookmarks","tryton-cancel","tryton-clear","tryton-close","tryton-copy","tryton-create","tryton-date","tryton-delete","tryton-download","tryton-email","tryton-error","tryton-exit","tryton-export","tryton-filter","tryton-format-align-center","tryton-format-align-justify","tryton-format-align-left","tryton-format-align-right","tryton-format-bold","tryton-format-color-text","tryton-format-italic","tryton-format-underline","tryton-forward","tryton-history","tryton-import","tryton-info","tryton-launch","tryton-link","tryton-log","tryton-menu","tryton-note","tryton-ok","tryton-open","tryton-print","tryton-public","tryton-question","tryton-refresh","tryton-remove","tryton-save","tryton-search","tryton-send","tryton-star-border","tryton-star","tryton-switch","tryton-translate","tryton-unarchive","tryton-undo","tryton-warning"],Sao.common.IconFactory=Sao.class_(Object,{batchnum:10,name2id:{},loaded_icons:{},tryton_icons:[],register_prm:jQuery.when(),load_icons:function(s){if(!(s=s||!1))for(var e in this.loaded_icons)window.URL.revokeObjectURL(this.loaded_icons[e]);return new Sao.Model("ir.ui.icon").execute("list_icons",[],{}).then(e=>{var t,i;s||(this.name2id={},this.loaded_icons={}),this.tryton_icons=[];for(var n=0,o=e.length;n<o;n++)t=e[n][0],i=e[n][1],s&&i in this.loaded_icons||(this.tryton_icons.push([t,i]),this.name2id[i]=t)})},register_icon:function(s){var e,a;return!s||s in this.loaded_icons||~Sao.common.LOCAL_ICONS.indexOf(s)?jQuery.when():"pending"==this.register_prm.state()?this.register_prm.then(()=>this.register_icon(s)):(e=s in this.name2id?jQuery.when():this.load_icons(!0),a=new Sao.Model("ir.ui.icon"),this.register_prm=e.then(()=>{const n=e=>{for(var t=0,i=this.tryton_icons.length;t<i;t++){var n=this.tryton_icons[t];if(Sao.common.compare(n,e))break}return t};var e=n([this.name2id[s],s]),t=(t=Math.round(e-this.batchnum/2))<0?0:t,e=Math.round(e+this.batchnum/2),i=[];for(const o of this.tryton_icons.slice(t,e))i.push(o[0]);return a.execute("read",[i,["name","icon"]],{}).then(e=>{for(const i of e){var t=this._convert(i.icon);this.loaded_icons[i.name]=t,delete this.name2id[i.name],this.tryton_icons.splice(n([i.id,i.name]),1)}})}),this.register_prm)},_convert:function(e){var t=jQuery.parseXML(e),t=(jQuery(t).find("svg").attr("fill",Sao.config.icon_colors[0]),e=(new XMLSerializer).serializeToString(t),new Blob([e],{type:"image/svg+xml"}));return window.URL.createObjectURL(t)},get_icon_url:function(t){return t?this.register_icon(t).then(()=>t in this.loaded_icons?this.loaded_icons[t]:jQuery.get("images/"+t+".svg",null,null,"text").then(e=>{e=this._convert(e);return this.loaded_icons[t]=e}).fail(()=>{Sao.Logger.error("Unknown icon %s",t)})):jQuery.when("")},get_icon_img:function(e,t){(t=t||{}).class||(t.class="icon");var i=jQuery("<img/>",t);return e&&this.get_icon_url(e).then(function(e){i.attr("src",e)}),i}}),Sao.common.ICONFACTORY=new Sao.common.IconFactory,Sao.common.UniqueDialog=Sao.class_(Object,{init:function(){this.running=!1},build_dialog:function(){return new Sao.Dialog("",this.class_,void 0,!1)},run:function(){var e,t,i;return this.running?jQuery.when():(e=Array.prototype.slice.call(arguments),t=jQuery.Deferred(),e.push(t),(i=this.build_dialog.apply(this,e)).content.submit(e=>{e.preventDefault(),i.footer.find("button.btn-primary").first().click()}),this.running=!0,i.modal.modal("show"),i.modal.on("shown.bs.modal",function(){i.modal.find("input,select").filter(":visible").first().focus()}),i.modal.on("keydown",e=>{e.which==Sao.common.ESC_KEYCODE&&(this.close(i),t.reject())}),t)},close:function(e){e.modal.on("hidden.bs.modal",function(e){jQuery(this).remove()}),e.modal.modal("hide"),this.running=!1}}),Sao.common.MessageDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"message-dialog",build_dialog:function(e,t,i){var n=Sao.common.MessageDialog._super.build_dialog.call(this);return n.header.remove(),n.body.append(jQuery("<div/>",{class:"alert alert-info",role:"alert"}).append(Sao.common.ICONFACTORY.get_icon_img(t,{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Message: "))).append(jQuery("<span/>").text(e).css("white-space","pre-wrap"))),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(()=>{this.close(n),i.resolve("ok")}).appendTo(n.footer),n},run:function(e,t){return Sao.common.MessageDialog._super.run.call(this,e,t||"tryton-info")}}),Sao.common.message=new Sao.common.MessageDialog,Sao.common.WarningDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"warning-dialog",build_dialog:function(e,t,i){var n=Sao.common.WarningDialog._super.build_dialog.call(this),t=jQuery("<div/>",{class:"alert alert-warning",role:"alert"}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-warning",{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Warning: "))).append(jQuery("<h4/>").text(t).css("white-space","pre-wrap"));return e&&t.append(jQuery("<span/>").text(e).css("white-space","pre-wrap")),n.body.append(t),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(()=>{this.close(n),i.resolve("ok")}).appendTo(n.footer),n}}),Sao.common.warning=new Sao.common.WarningDialog,Sao.common.UserWarningDialog=Sao.class_(Sao.common.WarningDialog,{class_:"user-warning-dialog",build_dialog:function(e,t,i){var n=Sao.common.UserWarningDialog._super.build_dialog.call(this,e,t,i),o=jQuery("<input/>",{type:"checkbox"});return n.body.append(jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>").text(Sao.i18n.gettext("Always ignore this warning.")).prepend(o))),n.body.append(jQuery("<p/>").text(Sao.i18n.gettext("Do you want to proceed?"))),n.footer.empty(),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("No")}).text(Sao.i18n.gettext("No")).click(()=>{this.close(n),i.reject()}).appendTo(n.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("Yes")}).text(Sao.i18n.gettext("Yes")).click(()=>{this.close(n),o.prop("checked")&&i.resolve("always"),i.resolve("ok")}).appendTo(n.footer),n}}),Sao.common.userwarning=new Sao.common.UserWarningDialog,Sao.common.ConfirmationDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"confirmation-dialog",build_dialog:function(e){var t=Sao.common.ConfirmationDialog._super.build_dialog.call(this);return t.header.remove(),t.body.append(jQuery("<div/>",{class:"alert alert-info",role:"alert"}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-info",{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Confirmation: "))).append(jQuery("<span/>").text(e).css("white-space","pre-wrap"))),t}}),Sao.common.SurDialog=Sao.class_(Sao.common.ConfirmationDialog,{build_dialog:function(e,t){var i=Sao.common.SurDialog._super.build_dialog.call(this,e);return jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(i),t.reject()}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(()=>{this.close(i),t.resolve()}).appendTo(i.footer),i}}),Sao.common.sur=new Sao.common.SurDialog,Sao.common.Sur3BDialog=Sao.class_(Sao.common.ConfirmationDialog,{build_dialog:function(e,t){var i=Sao.common.SurDialog._super.build_dialog.call(this,e);return jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(i),t.resolve("cancel")}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("No")}).text(Sao.i18n.gettext("No")).click(()=>{this.close(i),t.resolve("ko")}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("Yes")}).text(Sao.i18n.gettext("Yes")).click(()=>{this.close(i),t.resolve("ok")}).appendTo(i.footer),i}}),Sao.common.sur_3b=new Sao.common.Sur3BDialog,Sao.common.AskDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"ask-dialog",run:function(){var e=Array.prototype.slice.call(arguments);return 2==e.length&&e.push(!0),Sao.common.AskDialog._super.run.apply(this,e)},build_dialog:function(e,t,i,n){var o=Sao.common.AskDialog._super.build_dialog.call(this),s=(o.header.remove(),jQuery("<input/>",{class:"form-control",type:i?"input":"password",id:"ask-dialog-entry",name:t}));return o.body.append(jQuery("<div/>",{class:"form-group"}).append(jQuery("<label/>",{for:"ask-dialog-entry"}).text(e)).append(s)),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(o),n.reject()}).appendTo(o.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(()=>{this.close(o),n.resolve(s.val())}).appendTo(o.footer),o}}),Sao.common.ask=new Sao.common.AskDialog,Sao.common.ConcurrencyDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"ask-dialog",build_dialog:function(t,i,n,o){var e=Sao.common.ConcurrencyDialog._super.build_dialog.call(this);return e.modal.find(".modal-dialog").removeClass("modal-sm").addClass("modal-lg"),e.add_title(Sao.i18n.gettext("Concurrency Exception")),e.body.append(jQuery("<div/>",{class:"alert alert-info",role:"alert"}).append(jQuery("<p/>").append(Sao.common.ICONFACTORY.get_icon_img("tryton-info",{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Write Concurrency Warning: "))).text(Sao.i18n.gettext("This record has been modified while you were editing it."))).append(jQuery("<p/>").text(Sao.i18n.gettext("Choose:"))).append(jQuery("<ul/>").append(jQuery("<li/>").text(Sao.i18n.gettext('"Cancel" to cancel saving;'))).append(jQuery("<li/>").text(Sao.i18n.gettext('"Compare" to see the modified version;'))).append(jQuery("<li/>").text(Sao.i18n.gettext('"Write Anyway" to save your current version.'))))),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(e),o.reject()}).appendTo(e.footer),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("Compare")}).text(Sao.i18n.gettext("Compare")).click(()=>{this.close(e),Sao.rpc({method:"model."+t+".read",params:[[i],["rec_name"],n]},Sao.Session.current_session).then(function(e){e=e[0].rec_name;Sao.Tab.create({model:t,res_id:i,name:Sao.i18n.gettext("Compare: %1",e),domain:[["id","=",i]],context:n,mode:["form"]}),o.reject()})}).appendTo(e.footer),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("Write Anyway")}).text(Sao.i18n.gettext("Write Anyway")).click(()=>{this.close(e),o.resolve()}).appendTo(e.footer),e}}),Sao.common.concurrency=new Sao.common.ConcurrencyDialog,Sao.common.ErrorDialog=Sao.class_(Sao.common.UniqueDialog,{class_:"error-dialog",build_dialog:function(e,t,i){var n=Sao.common.ConcurrencyDialog._super.build_dialog.call(this);return n.modal.find(".modal-dialog").removeClass("modal-sm").addClass("modal-lg"),n.add_title(Sao.i18n.gettext("Application Error")),n.body.append(jQuery("<div/>",{class:"alert alert-danger",role:"alert"}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-error",{"aria-hidden":!0})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Warning: "))).append(jQuery("<p/>").append(jQuery("<pre/>").text(t))).append(jQuery("<p/>").append(jQuery("<a/>",{class:"btn btn-link",href:Sao.config.bug_url,target:"_blank",rel:"noreferrer noopener"}).text(Sao.i18n.gettext("Report Bug"))))),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("Close")}).text(Sao.i18n.gettext("Close")).click(()=>{this.close(n),i.resolve()}).appendTo(n.footer),n}}),Sao.common.error=new Sao.common.ErrorDialog,Sao.common.Processing=Sao.class_(Object,{queries:0,timeout:3e3,init:function(){this.el=jQuery("<div/>",{id:"processing",class:"text-center"});for(var e=jQuery("<span/>",{class:"label label-info",text:Sao.i18n.gettext("Processing")}).appendTo(this.el),t=0;t<3;t++)e.append(jQuery("<span/>",{class:"dot",text:"."}));this.el.hide(),jQuery(()=>{this.el.appendTo("body")})},show:function(){return window.setTimeout(()=>{this.queries+=1,this.el.show()},this.timeout)},hide:function(e){window.clearTimeout(e),0<this.queries&&--this.queries,this.queries<=0&&(this.queries=0,this.el.hide())}}),Sao.common.processing=new Sao.common.Processing,Sao.common.set_overflow=function(e,t){var i,t="hide"==t?i="":(i="visible","none");e.closest(".treeview").css("overflow",i).css("max-height",t),e.closest(".modal-body").css("overflow",i),e.closest(".navbar-collapse.in").css("overflow-y",i),e.closest(".content-box").css("overflow-y",i),e.parents("fieldset.form-group_").css("overflow",i),Sao.common.scrollIntoViewIfNeeded(e)},Sao.common.InputCompletion=Sao.class_(Object,{init:function(e,t,i,n){e.is("input")?(e.wrap('<div class="dropdown"/>'),this.dropdown=e.parent()):(e.addClass("dropdown"),this.dropdown=e),this.input=e.find("input").add(e.filter("input")).first(),this.input.attr("autocomplete","off"),jQuery("<span/>",{"data-toggle":"dropdown"}).appendTo(this.dropdown),this.menu=jQuery("<ul/>",{class:"dropdown-menu",role:"listbox"}).appendTo(this.dropdown),this.separator=jQuery("<li/>",{role:"separator",class:"divider"}).appendTo(this.menu),this.separator.hide(),this.source=t,this.match_selected=i,this.format=n,this.action_activated=null,this._search_text=null,this.input.on("input",()=>{window.setTimeout(this._input.bind(this),300,this.input.val())}),this.input.keydown(e=>{e.which==Sao.common.ESC_KEYCODE?this.dropdown.hasClass("open")&&(e.preventDefault(),e.stopPropagation(),this.menu.dropdown("toggle")):e.which==Sao.common.DOWN_KEYCODE&&this.dropdown.hasClass("open")&&(e.preventDefault(),e.stopPropagation(),this.menu.find("li > a").first().focus())}),this.menu.keydown(e=>{e.which==Sao.common.ESC_KEYCODE&&(e.preventDefault(),e.stopPropagation(),this.menu.dropdown("toggle"))}),this.dropdown.on("hide.bs.dropdown",()=>{this.input.focus(),Sao.common.set_overflow(this.input,"hide")}),this.dropdown.on("show.bs.dropdown",()=>{Sao.common.set_overflow(this.input,"show")})},set_actions:function(e,t=!0,i=!0){void 0!==e&&(this.action_activated=e);e=[];t&&e.push(["search",Sao.i18n.gettext("Search...")]),i&&e.push(["create",Sao.i18n.gettext("Create...")]),this.menu.find("li.action").remove(),jQuery.isEmptyObject(e)?this.separator.hide():(this.separator.show(),e.forEach(function(e){var t=e[0],e=e[1];jQuery("<li/>",{class:"action action-"+t}).append(jQuery("<a/>",{href:"#"}).text(this._format_action(e))).click(e=>{e.preventDefault(),this.action_activated&&this.action_activated(t),this.input.val("")}).appendTo(this.menu)},this))},_format:function(e){return this.format?this.format(e):jQuery("<span/>").text(e)},_format_action:function(e){return this.format_action?this.format_action(e):e},_input:function(t){t==this.input.val()&&(this.source instanceof Array?jQuery.when(this.source.filter(function(e){return e.toLowerCase().startsWith(t.toLowerCase())})):this.source(t)).then(e=>{t==this.input.val()&&this._set_selection(e)})},_set_selection:function(e){void 0===e&&(e=[]),this.menu.find("li.completion").remove(),e.reverse().forEach(function(t){jQuery("<li/>",{class:"completion"}).append(jQuery("<a/>",{href:"#"}).append(this._format(t))).click(e=>{e.preventDefault(),this.match_selected&&this.match_selected(t),this.input.focus()}).prependTo(this.menu)},this),this.input.val()&&(this.menu.find("li.completion").length||this.menu.find("li.action").length)?this.dropdown.hasClass("open")||this.menu.dropdown("toggle"):this.dropdown.hasClass("open")&&this.menu.dropdown("toggle")}}),Sao.common.get_completion=function(e,t,i,n,o=!0,s=!0){e=new Sao.common.InputCompletion(e,t,i,function(e){return e.name});return n&&e.set_actions(n,o,s),e._allow_create=s,e},Sao.common.update_completion=function(t,e,i,n,o){var s=t.val();if(!s||!n)return jQuery.when();void 0===o&&(o=i.get_domain(e));var a=i.get_search_context(e),i=i.get_search_order(e);return new Sao.Model(n).execute("autocomplete",[s,o,Sao.config.limit,i],a).then(function(e){return e.filter(e=>e.id||t.completion._allow_create).map(e=>(null===e.id&&(e.name=Sao.i18n.gettext('Create "%1"...',e.name)),e))},function(){Sao.Logger.warn("Unable to search for completion of %s",n)})},Sao.common.Paned=Sao.class_(Object,{init:function(e){var t;this._orientation=e,this.el=jQuery("<div/>"),"horizontal"==e?(t=jQuery("<div/>",{class:"row"}).appendTo(this.el),this.child1=jQuery("<div/>",{class:"col-md-6"}).appendTo(t),this.child2=jQuery("<div/>",{class:"col-md-6"}).appendTo(t)):"vertical"==e&&(this.child1=jQuery("<div/>",{class:"row"}).appendTo(this.el),this.child2=jQuery("<div/>",{class:"row"}).appendTo(this.el))},get_child1:function(){return this.child1},get_child2:function(){return this.child2}}),Sao.common.get_focus_chain=function(e){e=e.find("input,select,textarea");return e.sort(function(e,t){return"tabindex"in e.attributes&&"tabindex"in t.attributes?parseInt(e.attributes.tabindex.value)-parseInt(t.attributes.tabindex.value):"tabindex"in e.attributes?-1:"tabindex"in t.attributes?1:0}),e},Sao.common.find_focusable_child=function(e){var t,i,n,o;if(!e.is(":visible"))return null;if(~["input","select","textarea"].indexOf(e[0].tagName.toLowerCase())&&!e.prop("readonly"))return e;for(t=0,i=(n=Sao.common.get_focus_chain(e)).length;t<i;t++)if(o=Sao.common.find_focusable_child(jQuery(n[t])))return o},Sao.common.find_first_focus_widget=function(e,t){var i,n,o,s;if(1==t.length)return jQuery(t[0]);for(o=Sao.common.get_focus_chain(e),i=0;i<o.length;i++){for(s=[],n=0;n<t.length;n++)0<jQuery(t[n]).closest(o[i]).length&&s.push(t[n]);if(0<s.length)return Sao.common.find_first_focus_widget(jQuery(o[i]),s)}},Sao.common.apply_label_attributes=function(e,t,i){t?e.removeClass("editable required"):(e.addClass("editable"),i?e.addClass("required"):e.removeClass("required"))},Sao.common.download_file=function(e,t,i){void 0===i&&(i={type:Sao.common.guess_mimetype(t)});var n,o,e=new Blob([e],i);window.navigator&&window.navigator.msSaveOrOpenBlob?window.navigator.msSaveOrOpenBlob(e,t):(i=window.URL.createObjectURL(e),n=new Sao.Dialog(Sao.i18n.gettext("Download")),e=function(){n.modal.modal("hide")},o=jQuery("<a/>",{href:i,download:t,text:t,target:"_blank"}).appendTo(n.body).click(e),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("Close")}).text(Sao.i18n.gettext("Close")).click(e).appendTo(n.footer),n.modal.on("shown.bs.modal",function(){o[0].click()}),n.modal.modal("show"),n.modal.on("hidden.bs.modal",function(){jQuery(this).remove(),window.URL.revokeObjectURL(this.blob_url)}))},Sao.common.get_input_data=function(e,t,i){for(var n=0;n<e[0].files.length;n++)Sao.common.get_file_data(e[0].files[n],t,i)},Sao.common.get_file_data=function(t,i,n){var o=new FileReader;o.onload=function(){var e=new Uint8Array(o.result);n&&(e=String.fromCharCode.apply(null,e)),i(e,t.name)},o.readAsArrayBuffer(t)},Sao.common.ellipsize=function(e,t){var i;return e.length<=t?e:(i=Sao.i18n.gettext("..."),e.slice(0,t-i.length)+i)},Sao.common.accesskey=function(e){for(var t=0;t<e.length;t++){var i=e.charAt(t).toLowerCase();if(!~["d","e","f","i","n","t","w"].indexOf(i))return i}},Sao.common.debounce=function(t,i){return(...e)=>{clearTimeout(t._debounceTimeout),t._debounceTimeout=setTimeout(()=>{t.apply(this,e)},i)}},Sao.common.uuid4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})},Sao.common.COLOR_SCHEMES={red:"#cf1d1d",green:"#3fb41b",blue:"#224565",grey:"#444444",black:"#000000",darkcyan:"#305755"},Sao.common.hex2rgb=function(e,t){t=t||2;var i=parseInt("f".repeat(t),16);return[parseInt(e.substring(1,t+1),16)/i,parseInt(e.substring(t+1,2*t+1),16)/i,parseInt(e.substring(2*t+1,3*t+1),16)/i]},Sao.common.rgb2hex=function(e,t){t=t||2;var i=parseInt("f".repeat(t),16);return"#"+e.map(function(e){return Math.round(e*i).toString(16)}).join("")},Sao.common.rgb2hsv=function(e){var t,i,n=e[0],o=e[1],s=e[2],a=Math.max.apply(null,e),e=Math.min.apply(null,e);return e==a?[0,0,a]:(t=(a-n)/(a-e),i=(a-o)/(a-e),s=(a-s)/(a-e),[(n==a?s-i:o==a?2+t-s:4+i-t)/6%1,(a-e)/a,a])},Sao.common.hsv2rgb=function(e){var t,i,n,o=e[0],s=e[1],e=e[2];return 0==s?[e,e,e]:(i=e*(1-s),n=e*(1-s*(t=6*o-(o=Math.trunc(6*o)))),s=e*(1-s*(1-t)),0==(o%=6)?[e,s,i]:1==o?[n,e,i]:2==o?[i,e,s]:3==o?[i,n,e]:4==o?[s,i,e]:5==o?[e,i,n]:void 0)},Sao.common.generateColorscheme=function(e,t,i=.1){for(var e=Sao.common.hex2rgb(Sao.common.COLOR_SCHEMES[e]||e),e=Sao.common.rgb2hsv(e),n=e[0],o=e[1],s=e[2],a=(t.length&&(i=Math.min(i,(1-s)/t.length)),{}),r=0;r<t.length;r++)a[t[r]]=Sao.common.rgb2hex(Sao.common.hsv2rgb([(n+.618033988749895*r)%1,o,(s+i*r)%1]));return a},Sao.common.richtext_toolbar=function(){function n(e){document.execCommand(e.data)}function e(e){var t=jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(o);for(const i of e)jQuery("<button/>",{class:"btn btn-default",type:"button",title:i.label}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-format-"+i.icon)).appendTo(t).click(i.command,n)}var o=jQuery("<div/>",{class:"btn-toolbar",role:"toolbar"});e([{icon:"bold",command:"bold",label:Sao.i18n.gettext("Bold")},{icon:"italic",command:"italic",label:Sao.i18n.gettext("Italic")},{icon:"underline",command:"underline",label:Sao.i18n.gettext("Underline")}]);var t;for(t of[{heading:Sao.i18n.gettext("Font"),options:["Normal","Serif","Sans","Monospace"],command:"fontname"},{heading:Sao.i18n.gettext("Size"),options:[1,2,3,4,5,6,7],command:"fontsize"}]){var i=jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(o),i=(jQuery("<button/>",{class:"btn btn-default dropdown-toggle",type:"button","data-toggle":"dropdown","aria-expanded":!1,"aria-haspopup":!0}).append(t.heading).append(jQuery("<span/>",{class:"caret"})).appendTo(i),jQuery("<ul/>",{class:"dropdown-menu"}).appendTo(i));t.options.forEach(function(e,i){return function(t){e.append(jQuery("<li/>").append(jQuery("<a/>",{href:"#"}).text(t).click(function(e){e.preventDefault(),document.execCommand(i.command,!1,t)})))}}(i,t))}return e([{icon:"align-left",command:Sao.i18n.rtl?"justifyRight":"justifyLeft",label:Sao.i18n.rtl?Sao.i18n.gettext("Justify Right"):Sao.i18n.gettext("Justify Left")},{icon:"align-center",command:"justifyCenter",label:Sao.i18n.gettext("Justify Center")},{icon:"align-right",command:Sao.i18n.rtl?"justifyLeft":"justifyRight",label:Sao.i18n.rtl?Sao.i18n.gettext("Justify Left"):Sao.i18n.gettext("Justify Right")},{icon:"align-justify",command:"justifyFull",label:Sao.i18n.gettext("Justify Full")}]),[["foreColor","#000000"]].forEach(function(e){var t=e[0],e=e[1];jQuery("<input/>",{class:"btn btn-default",type:"color"}).appendTo(o).change(function(){document.execCommand(t,!1,jQuery(this).val())}).focusin(function(){document.execCommand(t,!1,jQuery(this).val())}).val(e)}),o},Sao.common.richtext_normalize=function(e){e=jQuery("<div/>").html(e);return e.find("div").each(function(e,t){var i;(t=jQuery(t)).css("text-align")&&(i=t.css("text-align").split("-").pop(),t.attr("align",i),t.css("text-align","")),"start"==t.attr("align")&&(Sao.i18n.rtl?t.attr("align","right"):t.attr("align","left"))}),e.html()},Sao.common.image_url=function(e){if(!e)return null;var t="";try{var i=e;i instanceof Uint8Array&&(i=(new TextDecoder).decode(e)),jQuery.parseXML(i)&&(t="image/svg+xml")}catch(e){}i=new Blob([e],{type:t});return window.URL.createObjectURL(i)},Sao.common.play_sound=function(e="success"){e=new Audio("sounds/"+e+".wav");e.volume=localStorage.getItem("sao_sound_volume")||.5,e.play()}}(),!function(){"use strict";Sao.Model=Sao.class_(Object,{init:function(e,t){this.name=e,this.session=Sao.Session.current_session,this.fields={}},add_fields:function(e){var t,i=[];for(t in e){var n,o=e[t];t in this.fields?jQuery.extend(this.fields[t].description,o):(n=Sao.field.get(o.type),this.fields[t]=new n(o),i.push(t))}return i},execute:function(e,t,i={},n=!0,o=!0){e={method:"model."+this.name+"."+e,params:t.concat(i)};return Sao.rpc(e,this.session,n,o)},copy:function(e,t){return jQuery.isEmptyObject(e)?jQuery.when():(e=e.map(function(e){return e.id}),this.execute("copy",[e,{}],t))}}),Sao.Group=function(e,t,i){return i.prm=jQuery.when(),i.model=e,i._context=t,i.on_write=[],i.parent=void 0,i.screens=[],i.parent_name="",i.children=[],i.child_name="",i.parent_datetime_field=void 0,i.record_removed=[],i.record_deleted=[],i.__readonly=!1,i.exclude_field=null,i.skip_model_access=!1,i.forEach(function(e,t,i){e.group=i}),Object.defineProperty(i,"readonly",{get:function(){var e=Sao.common.MODELACCESS.get(this.model.name);return!(!this.context._datetime&&(e.write||e.create||this.skip_model_access))||this.__readonly},set:function(e){this.__readonly=e}}),i.load=function(e,t=!1,i=-1){-1==i&&(i=this.length);var n=[];for(const a of e){let e=this.get(a);e||(((e=new Sao.Record(this.model,a)).group=this).splice(i,0,e),i+=1),n.push(e)}var o=[];for(const r of this.record_removed)~e.indexOf(r.id)||o.push(r);this.record_removed=o;var s=[];for(const l of this.record_deleted)~e.indexOf(l.id)||s.push(l);if(this.record_deleted=s,n.length&&t){for(const c of n)c.modified_fields.id=!0;this.record_modified()}},i.get=function(e){for(const t of this)if(t.id==e)return t},i.new_=function(e,t,i=null){t=new Sao.Record(this.model,t);return t.group=this,e&&t.default_get(i),t},i.add=function(e,t=-1,i=!0){-1==t&&(t=this.length),t=Math.min(t,this.length),e.group!=this&&(e.group=this),this.indexOf(e)<0&&this.splice(t,0,e);for(var n of this.record_removed)n.id==e.id&&this.record_removed.splice(this.record_removed.indexOf(n),1);for(var o of this.record_deleted)o.id==e.id&&this.record_deleted.splice(this.record_deleted.indexOf(o),1);return e.modified_fields.id=!0,i&&this.parent&&this.model.fields[this.parent_name]&&((t=this.model.fields[this.parent_name])instanceof Sao.field.Many2One||t instanceof Sao.field.Reference)&&(i=[this.parent.id,""],t instanceof Sao.field.Reference&&(i=[this.parent.model.name,i]),t.set_client(e,i)),e},i.remove=function(e,t,i=!1,n=!0){this.indexOf(e);0<=e.id&&(t?(~this.record_deleted.indexOf(e)&&this.record_deleted.splice(this.record_deleted.indexOf(e),1),~this.record_removed.indexOf(e)||this.record_removed.push(e)):(~this.record_removed.indexOf(e)&&this.record_removed.splice(this.record_removed.indexOf(e),1),~this.record_deleted.indexOf(e)||this.record_deleted.push(e))),e.modified_fields.id=!0,(e.id<0||i)&&this._remove(e),n&&this.record_modified()},i._remove=function(e){e=this.indexOf(e);this.splice(e,1)},i.unremove=function(e){this.record_removed.splice(this.record_removed.indexOf(e),1),this.record_deleted.splice(this.record_deleted.indexOf(e),1),e.group.record_modified()},i.clear=function(){this.splice(0,this.length),this.record_removed=[],this.record_deleted=[]},i.record_modified=function(){if(this.parent)this.parent.modified_fields[this.child_name]=!0,this.parent.model.fields[this.child_name].changed(this.parent),this.parent.validate(null,!0,!1,!0),this.parent.group.record_modified();else for(const e of this.screens)e.record_modified()},i.record_notify=function(e){for(const t of this.screens)t.record_notify(e)},i.delete_=function(i){if(jQuery.isEmptyObject(i))return jQuery.when();var n=this.root_group,o=(Sao.Logger.assert(i.every(e=>e.model.name==this.model.name),"records not from the same model"),Sao.Logger.assert(i.every(e=>e.group.root_group==n),"records not from the same root group"),i=i.filter(e=>0<=e.id),this.context);o._timestamp={};for(const e of i)jQuery.extend(o._timestamp,e.get_timestamp());var s=i.map(function(e){return e.id});return n.on_write_ids(s).then(e=>{for(const t of i)t.destroy();return e=e.filter(e=>!~s.indexOf(e)),this.model.execute("delete",[s],o).then(()=>{n.reload(e)})})},Object.defineProperty(i,"root_group",{get:function(){for(var e=this,t=this.parent;t;)e=t.group,t=t.parent;return e}}),i.save=function(){var t=[];if(this.forEach(e=>{t.push(e.save())}),!jQuery.isEmptyObject(this.record_deleted)){for(const e of this.record_deleted)this._remove(e);t.push(this.delete_(this.record_deleted)),this.record_deleted.splice(0,this.record_deleted.length)}return jQuery.when.apply(jQuery,t)},i.written=function(t){return"number"==typeof t&&(t=[t]),this.on_write_ids(t).then(e=>{e=e.filter(e=>!~t.indexOf(e)),this.root_group.reload(e)})},i.reload=function(e){for(const i of this.children)i.reload(e);for(const n of e){var t=this.get(n);t&&jQuery.isEmptyObject(t.modified_fields)&&t.cancel()}},i.on_write_ids=function(t){var i=[],n=[];return this.on_write.forEach(e=>{e=this.model.execute(e,[t],this._context).then(e=>{jQuery.extend(n,e)});i.push(e)}),jQuery.when.apply(jQuery,i).then(()=>n.filter((e,t,i)=>t==i.indexOf(e)))},i.set_parent=function(e){(this.parent=e)&&e.model.name==this.model.name&&this.parent.group.children.push(this)},i.add_fields=function(e){e=this.model.add_fields(e);if(!jQuery.isEmptyObject(this)){var i=[];for(const t of this)t.id<0&&i.push(t);i.length&&e.length&&this.model.execute("default_get",[e,this.context]).then(e=>{for(const t of i)t.set_default(e,!0,!1);this.record_modified()})}},i.destroy=function(){var e;this.parent&&~(e=this.parent.group.children.indexOf(this))&&this.parent.group.children.splice(e,1),this.parent=null},Object.defineProperty(i,"domain",{get:function(){var e=[];for(const t of this.screens)t.attributes.domain&&e.push(t.attributes.domain);return this.parent&&this.child_name?[e,this.parent.model.fields[this.child_name].get_domain(this.parent)]:e}}),Object.defineProperty(i,"context",{get:function(){return this._get_context()},set:function(e){this._context=jQuery.extend({},e)}}),Object.defineProperty(i,"local_context",{get:function(){return this._get_context(!0)}}),i._get_context=function(e){var t,i,n=e?{}:jQuery.extend({},this.model.session.context);return this.parent&&(t=this.parent.get_context(e),jQuery.extend(n,t),this.child_name in this.parent.model.fields)&&(i=this.parent.model.fields[this.child_name],jQuery.extend(n,i.get_context(this.parent,t,e))),jQuery.extend(n,this._context),this.parent_datetime_field&&(n._datetime=this.parent.get_eval()[this.parent_datetime_field]),n},i.clean4inversion=function(e){var t,i;return jQuery.isEmptyObject(e)?[]:(i=new Sao.common.DomainInversion,t=e[0],e=e.slice(1),~["AND","OR"].indexOf(t)||(i.is_leaf(t)?(i=t[0])in this.model.fields&&this.model.fields[i].description.readonly&&(t=[]):t=this.clean4inversion(t)),[t].concat(this.clean4inversion(e)))},i.domain4inversion=function(){var e=this.domain;return this.__domain4inversion&&Sao.common.compare(this.__domain4inversion[0],e)||(this.__domain4inversion=[e,this.clean4inversion(e)]),this.__domain4inversion[1]},i.get_by_path=function(i){i=jQuery.extend([],i);var n=null,o=this,s=function(){var e,t;return jQuery.isEmptyObject(i)?n:(e=i[0][0],t=i[0][1],i.splice(0,1),(n=o.get(t))?e?n.load(e).then(function(){return(o=n._values[e])?s():null}):s():null)};return jQuery.when().then(s)},i.set_sequence=function(e,t){var i,n,o,s,a=!1,r=null,l=0===t?function(e,t){return t<e}:function(e,t){return e<t};for(const i of this)(i.get_loaded([e])||a||i.id<0)&&(n=r?(r.load(e,!1),r.field_get(e)):null,o=!1,null===(s=i.field_get(e))?n?o=!0:r&&(0<=i.id?o=l(i.id,r.id):0===t&&(o=!0)):s===n?r&&(0<=i.id?o=l(i.id,r.id):0===t&&(o=!0)):s<=(n||0)&&(o=!0),o)&&(null===n&&(n=0),n+=1,i.field_set_client(e,n),a=i),r=i},i},Sao.Record=Sao.class_(Object,{id_counter:-1,init:function(e,t=null){this.model=e,this.group=Sao.Group(e,{},[]),this.id=null===t?Sao.Record.prototype.id_counter:t,this.id<0&&Sao.Record.prototype.id_counter--,this._values={},this.modified_fields={},this._loaded={},this.fields={},this._timestamp=null,this._write=!0,this._delete=!0,this.resources=null,this.button_clicks={},this.links_counts={},this.state_attrs={},this.autocompletion={},this.exception=!1,this.destroyed=!1},get modified(){return!jQuery.isEmptyObject(this.modified_fields)&&(Sao.Logger.info("Modified fields of %s@%s",this.id,this.model.name,Object.keys(this.modified_fields)),!0)},save:function(t=!1){var e=this.get_context(),i=jQuery.when();if(this.id<0||this.modified){var n=this.get();if(this.id<0)try{this.id=this.model.execute("create",[[n]],e,!1)[0]}catch(e){return e.promise?e.then(()=>this.save(t)):jQuery.Deferred().reject()}else jQuery.isEmptyObject(n)||(e._timestamp=this.get_timestamp(),i=this.model.execute("write",[[this.id],n],e));i=i.done(()=>{if(this.cancel(),t)return this.reload()}),this.group&&(i=i.done(()=>this.group.written(this.id)))}return this.group.parent&&(delete this.group.parent.modified_fields[this.group.child_name],i=i.done(()=>this.group.parent.save(t))),i},reload:function(e,t=!0){if(this.id<0)return t?jQuery.when():null;if(!e)return this.load("*",t);var i,n;if(t)return i=e.map(e=>this.load(e)),jQuery.when.apply(jQuery,i);for(n of e)this.load(n,t)},is_loaded:function(e){return this.id<0||e in this._loaded},load:function(t,e=!0,i=!0){if(this.destroyed||this.is_loaded(t))return e?jQuery.when():"*"!==t?this.model.fields[t]:void 0;if(e&&"pending"==this.group.prm.state())return this.group.prm.then(()=>this.load(t));var n,o,s,l={};if(l[this.id]=this,"*"==t)for(var a in n="eager",o=new Set,this.model.fields){"lazy"==((s=this.model.fields[a]).description.loading||"eager")&&(n="lazy");for(const j of s.views)o.add(j)}else n=this.model.fields[t].description.loading||"eager",o=this.model.fields[t].views;var r={};if("eager"==n)for(a in this.model.fields)"eager"==((s=this.model.fields[a]).description.loading||"eager")&&(r[a]=s);else r=this.model.fields;var c=[];for(a in r)s=r[a],a in this._loaded||o.size&&!Sao.common.intersect(Array.from(o).sort(),Array.from(s.views).sort())||c.push(a);var d=c.slice(),h=["many2one","one2one","reference"],u=["selection","multiselection"];for(const a of c){var _=this.model.fields[a].description;~h.indexOf(_.type)?d.push(a+".rec_name"):~u.indexOf(_.type)&&"eager"==(_.loading||"lazy")&&d.push(a+":string")}~c.indexOf("rec_name")||d.push("rec_name"),d.push("_timestamp"),d.push("_write"),d.push("_delete");var m=jQuery.extend({},this.get_context());if("eager"==n){var p=Math.trunc(Sao.config.limit/Math.min(d.length,10));const O=e=>!e.destroyed&&0<=e.id&&!(t in e._loaded);var f,g=e=>O(e)&&void 0===l[e.id]&&(e.group===this.group||JSON.stringify(e.get_context())===JSON.stringify(m)),v=this.group.parent&&this.group.parent.model.name==this.model.name?(f=(f=[]).concat.apply(f,this.group.parent.group.children),g):(f=this.group,O),S=f.indexOf(this);if(~S)for(var y,b=f.length,w=1;Object.keys(l).length<p&&(0<=S-w||S+w<b)&&w<2*p;)0<=S-w&&v(y=f[S-w])&&(l[y.id]=y),S+w<b&&v(y=f[S+w])&&(l[y.id]=y),w++}for(a in this.model.fields)this.model.fields.hasOwnProperty(a)&&"binary"==this.model.fields[a].description.type&&~d.indexOf(a,d)&&(m[this.model.name+"."+a]="size");g=this.model.execute("read",[Object.keys(l).map(e=>parseInt(e,10)),d],m,e,i);const x=(e,t=!1)=>{var i,n={};for(const r of e)n[r.id]=r;for(i in l)if(l.hasOwnProperty(i)){var o=l[i],s=(o.exception||(o.exception=t),n[i]);if(o&&s){for(var a in this.modified_fields)this.modified_fields.hasOwnProperty(a)&&delete s[a];o.set(s,!1)}}};i=()=>{var e,t,i=[];for(t in l){e={id:t};for(const n of d)"id"!=n&&(e[n]=null);i.push(e)}return x(i,!0)};return e?(this.group.prm=g.then(x,i),this.group.prm):(g?x(g):i(),"*"!==t?this.model.fields[t]:void 0)},set:function(e,t=!0,i=!0){var n,o,s,a,r={},l=[];for(n in e)e.hasOwnProperty(n)&&(a=e[n],"_timestamp"==n?this._timestamp||(this._timestamp=a):"_write"==n||"_delete"==n?this[n]=a:n in this.model.fields?this.model.fields[n]instanceof Sao.field.One2Many?r[n]=a:((o=this.model.fields[n])instanceof Sao.field.Many2One||o instanceof Sao.field.Reference?this._values[s=n+"."]=e[s]||{}:(o instanceof Sao.field.Selection||o instanceof Sao.field.MultiSelection)&&((s=n+":string")in e?this._values[s]=e[s]:delete this._values[s]),this.model.fields[n].set(this,a),this._loaded[n]=!0,l.push(n)):"rec_name"==n&&(this._values[n]=a));for(n in r)this.model.fields[n].set(this,a=r[n]),this._loaded[n]=!0,l.push(n);i&&this.validate(l,!0,!1,!1),t&&this.set_modified()},get:function(){var e,t,i={};for(e in this.model.fields)this.model.fields.hasOwnProperty(e)&&((t=this.model.fields[e]).description.readonly&&(!(t instanceof Sao.field.One2Many)||t instanceof Sao.field.Many2Many)||void 0===this.modified_fields[e]&&0<=this.id||(i[e]=t.get(this),t instanceof Sao.field.One2Many&&0===i[e].length&&delete i[e]));return i},invalid_fields:function(){var e,t={};for(e in this.model.fields){var i=this.model.fields[e].get_state_attrs(this).invalid;i&&(t[e]=i)}return t},get_context:function(e){return e?this.group.local_context:this.group.context},field_get:function(e){return this.model.fields[e].get(this)},field_set:function(e,t){this.model.fields[e].set(this,t)},field_get_client:function(e){return this.model.fields[e].get_client(this)},field_set_client:function(e,t,i){this.model.fields[e].set_client(this,t,i)},default_get:function(e=null){if(jQuery.isEmptyObject(this.model.fields))return jQuery.when();var t=this.get_context();if(e)for(const i in e)Sao.setdefault(t,"default_"+i,e[i]);return this.model.execute("default_get",[Object.keys(this.model.fields)],t).then(e=>{var t;return this.group.parent&&this.group.parent_name in this.group.model.fields&&((t=this.group.model.fields[this.group.parent_name])instanceof Sao.field.Reference?e[this.group.parent_name]=[this.group.parent.model.name,this.group.parent.id]:t.description.relation==this.group.parent.model.name&&(e[this.group.parent_name]=this.group.parent.id)),this.set_default(e)})},set_default:function(e,t=!0,i=!0){var n,o,s,a=[],r=[];for(n in e)"_write"==n||"_delete"==n||"_timestamp"==n?this[n]=e[n]:e.hasOwnProperty(n)&&(o=e[n],n in this.model.fields)&&n!=this.group.exclude_field&&((this.model.fields[n]instanceof Sao.field.Many2One||this.model.fields[n]instanceof Sao.field.Reference)&&(this._values[s=n+"."]=e[s]||{}),a.push(this.model.fields[n].set_default(this,o)),this._loaded[n]=!0,r.push(n));return jQuery.when.apply(jQuery,a).then(()=>{this.on_change(r),this.on_change_with(r);var e=()=>{if(i)return this.set_modified(),jQuery.when.apply(jQuery,this.group.root_group.screens.map(e=>e.display()))};return t?this.validate(null,!0).then(e):e()})},get_timestamp:function(){var e,t={};for(e in t[this.model.name+","+this.id]=this._timestamp,this.model.fields)this.model.fields.hasOwnProperty(e)&&e in this._loaded&&jQuery.extend(t,this.model.fields[e].get_timestamp(this));return t},get_eval:function(){var e,t={};for(e in this.model.fields)!this._loaded.hasOwnProperty(e)&&0<=this.id||(t[e]=this.model.fields[e].get_eval(this));return t.id=this.id,t},get_on_change_value:function(e){var t,i={};for(t in this.model.fields)e&&~e.indexOf(t)||0<=this.id&&(!this._loaded[t]||!this.modified_fields[t])||(i[t]=this.model.fields[t].get_on_change_value(this));return i.id=this.id,i},_get_on_change_args:function(e){var t={},i=Sao.common.EvalEnvironment(this,"on_change");for(const o of e){var n=i;for(const s of o.split("."))void 0!==n&&(n=n[s]);t[o]=n}return t},on_change:function(e){var t,i={};for(const a of e){var n=this.model.fields[a].description.on_change;jQuery.isEmptyObject(n)||(i=jQuery.extend(i,this._get_on_change_args(n)))}if(!jQuery.isEmptyObject(i)){try{if(1==e.length||void 0===i.id){t=[];for(const r of e)t.push(this.model.execute("on_change_"+r,[i],this.get_context(),!1))}else t=[this.model.execute("on_change",[i,e],this.get_context(),!1)]}catch(e){return}t.forEach(this.set_on_change,this)}var o=Sao.common.MODELNOTIFICATION.get(this.model.name),s=new Set(o);e.some(e=>s.has(e))&&(i=this._get_on_change_args(o),this.model.execute("on_change_notify",[i],this.get_context()).then(this.group.record_notify.bind(this.group)))},on_change_with:function(e){var t,i,n,o={},s={},a={};for(t in this.model.fields)if(this.model.fields.hasOwnProperty(t)&&(i=this.model.fields[t].description.on_change_with,!jQuery.isEmptyObject(i))){for(var r=0;r<e.length&&!~i.indexOf(e[r]);r++);r>=e.length||(jQuery.isEmptyObject(Sao.common.intersect(Object.keys(o).sort(),i.sort()))?(o[t]=!0,s=jQuery.extend(s,this._get_on_change_args(i.concat([t]))),(this.model.fields[t]instanceof Sao.field.Many2One||this.model.fields[t]instanceof Sao.field.Reference)&&delete this._values[t+"."]):a[t]=!0)}if((o=Object.keys(o)).length){try{if(1==o.length||void 0===s.id){n={};for(const t of o)n=jQuery.extend(n,this.model.execute("on_change_with_"+t,[s],this.get_context(),!1))}else n=this.model.execute("on_change_with",[s,o],this.get_context(),!1)}catch(e){return}this.set_on_change(n)}if(!jQuery.isEmptyObject(a)){s={};for(const t in a)i=this.model.fields[t].description.on_change_with,s=jQuery.extend(s,this._get_on_change_args(i.concat([t])));o=Object.keys(a);try{if(1==o.length||void 0===s.id){n={};for(const t of o)n=jQuery.extend(n,this.model.execute("on_change_with_"+t,[s],this.get_context(),!1))}else n=this.model.execute("on_change_with",[s,o],this.get_context(),!1)}catch(e){return}this.set_on_change(n)}},set_on_change:function(e){for(var t in e){var i,n=e[t];t in this.model.fields&&((this.model.fields[t]instanceof Sao.field.Many2One||this.model.fields[t]instanceof Sao.field.Reference)&&(this._values[i=t+"."]=e[i]||{}),this.load(t,!1).set_on_change(this,n))}},autocomplete_with:function(e){for(var t in this.model.fields)~(this.model.fields[t].description.autocomplete||[]).indexOf(e)&&this.do_autocomplete(t)},do_autocomplete:function(e){this.autocompletion[e]=[];var t,i=this.model.fields[e].description.autocomplete,i=this._get_on_change_args(i);try{t=this.model.execute("autocomplete_"+e,[i],this.get_context(),!1)}catch(e){t=[]}this.autocompletion[e]=t},on_scan_code:function(e,t){t=this.expr_eval(t);t=this._get_on_change_args(t);return this.model.execute("on_scan_code",[t,e],this.get_context(),!0,!1).then(e=>(this.set_on_change(e),this.set_modified(),!jQuery.isEmptyObject(e)))},reset:function(e){this.cancel(),this.set(e,!0),this.group.parent&&(this.group.parent.on_change([this.group.child_name]),this.group.parent.on_change_with([this.group.child_name]))},expr_eval:function(e){var t,i;return"string"!=typeof e?e:e?"[]"==e?[]:"{}"==e?{}:((t=this.get_eval()).context=this.get_context(),t.active_model=this.model.name,t.active_id=this.id,this.group.parent&&this.group.parent_name&&(i=Sao.common.EvalEnvironment(this.group.parent),t["_parent_"+this.group.parent_name]=i),new Sao.PYSON.Decoder(t).decode(e)):void 0},rec_name:function(){return this.model.execute("read",[[this.id],["rec_name"]],this.get_context()).then(function(e){return e[0].rec_name})},validate:function(n,o,s,a){var e=()=>{var e,t,i=!0;for(e in this.model.fields)a&&0<=this.id&&!(e in this._loaded)||this.model.fields.hasOwnProperty(e)&&(t=this.model.fields[e],n&&!~n.indexOf(e)||t.description.readonly||e==this.group.exclude_field||t.validate(this,o,s)||(i=!1));return i};return a?(this._check_load(n,!1),e()):this._check_load(n).then(e)},pre_validate:function(){var e;return jQuery.isEmptyObject(this.modified_fields)?jQuery.Deferred().resolve(!0):(e=this._get_on_change_args(Object.keys(this.modified_fields).concat(["id"])),this.model.execute("pre_validate",[e],this.get_context()))},cancel:function(){this._loaded={},this._values={},this.modified_fields={},this._timestamp=null,this.button_clicks={},this.links_counts={},this.exception=!1},_check_load:function(e,t=!0){return this.get_loaded(e)?jQuery.when():this.reload(e,t)},get_loaded:function(e){if(jQuery.isEmptyObject(e))return Sao.common.compare(Object.keys(this.model.fields).sort(),Object.keys(this._loaded).sort());var t=!0;for(const i of e)i in this._loaded||i in this.modified_fields||(t=!1);return t},get root_parent(){for(var e=this;e.group.parent;)e=e.group.parent;return e},get_path:function(e){for(var t=[],i=this,n="";i&&(t.push([n,i.id]),i.group!==e);)n=i.group.child_name,i=i.group.parent;return t.reverse(),t},get_index_path:function(e){for(var t=[],i=this;i&&(t.push(i.group.indexOf(i)),i.group!==e);)i=i.group.parent;return t.reverse(),t},children_group:function(t){var i=jQuery.Deferred();return t?this._check_load([t]).done(()=>{var e=this._values[t];void 0===e?i.resolve(null):(e.model.fields!==this.group.model.fields&&(jQuery.extend(this.group.model.fields,e.model.fields),e.model.fields=this.group.model.fields),e.on_write=this.group.on_write,e.readonly=this.group.readonly,jQuery.extend(e._context,this.group._context),i.resolve(e))}):i.resolve([]),i},get deleted(){return Boolean(~this.group.record_deleted.indexOf(this))},get removed(){return Boolean(~this.group.record_removed.indexOf(this))},get readonly(){return this.deleted||this.removed||this.exception||this.group.readonly||!this._write},get deletable(){return this._delete},get identity(){return JSON.stringify(Object.keys(this._values).reduce((e,t)=>{var i=this.model.fields[t];return i&&(i instanceof Sao.field.Binary?e[t]=i.get_size(this):e[t]=i.get(this)),e},{}))},set_field_context:function(){for(var e in this.model.fields){var t,i;this.model.fields.hasOwnProperty(e)&&(t=this.model.fields[e],(e=this._values[e])instanceof Array)&&(i=Object.getOwnPropertyDescriptor(e,"context"))&&i.set&&(i=t.description.context)&&(e.context=this.expr_eval(i))}},get_resources:function(e){e=0<=this.id&&(!this.resources||e)?this.model.execute("resources",[this.id],this.get_context()).then(e=>this.resources=e):jQuery.when(this.resources);return e},get_button_clicks:function(t){var e;return this.id<0?jQuery.when():void 0!==(e=this.button_clicks[t])?jQuery.when(e):Sao.rpc({method:"model.ir.model.button.click.get_click",params:[this.model.name,t,this.id,{}]},this.model.session).then(e=>this.button_clicks[t]=e)},set_modified:function(e){e&&(this.modified_fields[e]=!0),this.group.record_modified()},destroy:function(){for(const e of Object.values(this._values))e&&e.hasOwnProperty("destroy")&&e.destroy();this.destroyed=!0}}),Sao.field={},Sao.field.get=function(e){switch(e){case"char":return Sao.field.Char;case"selection":return Sao.field.Selection;case"multiselection":return Sao.field.MultiSelection;case"datetime":case"timestamp":return Sao.field.DateTime;case"date":return Sao.field.Date;case"time":return Sao.field.Time;case"timedelta":return Sao.field.TimeDelta;case"float":return Sao.field.Float;case"numeric":return Sao.field.Numeric;case"integer":return Sao.field.Integer;case"boolean":return Sao.field.Boolean;case"many2one":return Sao.field.Many2One;case"one2one":return Sao.field.One2One;case"one2many":return Sao.field.One2Many;case"many2many":return Sao.field.Many2Many;case"reference":return Sao.field.Reference;case"binary":return Sao.field.Binary;case"dict":return Sao.field.Dict;default:return Sao.field.Char}},Sao.field.Field=Sao.class_(Object,{_default:null,_single_value:!0,init:function(e){this.description=e,this.name=e.name,this.views=new Set},set:function(e,t){e._values[this.name]=t},get:function(e){e=e._values[this.name];return e=void 0===e?this._default:e},_has_changed:function(e,t){return JSON.stringify(e)!=JSON.stringify(t)},set_client:function(e,t,i){var n=this.get(e);this.set(e,t),this._has_changed(n,this.get(e))?(this.changed(e),e.validate(null,!0,!1,!0),e.set_modified(this.name)):i&&(this.changed(e),e.validate(null,!0,!1,!0),e.set_modified())},get_client:function(e){return this.get(e)},set_default:function(e,t){this.set(e,t),e.modified_fields[this.name]=!0},set_on_change:function(e,t){this.set(e,t),e.modified_fields[this.name]=!0},changed:function(e){e.on_change([this.name]),e.on_change_with([this.name]),e.autocomplete_with(this.name),e.set_field_context()},get_timestamp:function(e){return{}},get_context:function(e,t,i){t=t?jQuery.extend({},t):e.get_context(i);return jQuery.extend(t,e.expr_eval(this.description.context||{})),t},get_search_context:function(e){var t=this.get_context(e);return jQuery.extend(t,e.expr_eval(this.description.search_context||{})),t},get_search_order:function(e){return e.expr_eval(this.description.search_order||null)},get_domains:function(e,t){t=(new Sao.common.DomainInversion).domain_inversion([e.group.domain4inversion(),t||[]],this.name,Sao.common.EvalEnvironment(e)),"boolean"!=typeof t||t?"boolean"==typeof t&&(t=t&&[]):t=[["id","=",null]],e=e.expr_eval(this.description.domain||[]);return[t,e]},get_domain:function(e){var e=this.get_domains(e),t=e[0],e=e[1],i=new Sao.common.DomainInversion;return i.concat([i.localize_domain(t),e])},validation_domains:function(e,t){return(new Sao.common.DomainInversion).concat(this.get_domains(e,t))},get_eval:function(e){return this.get(e)},get_on_change_value:function(e){return this.get_eval(e)},set_state:function(e,t=["readonly","required","invisible"]){var i=e.expr_eval(this.description.states||{});for(const n of t)"readonly"==n&&this.description.readonly||(void 0!==i[n]?this.get_state_attrs(e)[n]=i[n]:void 0!==this.description[n]&&(this.get_state_attrs(e)[n]=this.description[n]));(e.group.readonly||this.get_state_attrs(e).domain_readonly||e.parent_name==this.name)&&(this.get_state_attrs(e).readonly=!0)},get_state_attrs:function(e){return this.name in e.state_attrs||(e.state_attrs[this.name]=jQuery.extend({},this.description)),(e.group.readonly||e.readonly)&&(e.state_attrs[this.name].readonly=!0),e.state_attrs[this.name]},_is_empty:function(e){return!this.get_eval(e)},check_required:function(e){var t=this.get_state_attrs(e);return 1!=t.required||!this._is_empty(e)||1==t.readonly},validate:function(e,t,i){if(this.description.readonly)return!0;var n=!1,o=this.get_state_attrs(e),s=Boolean(parseInt(o.required,10)),a=Boolean(parseInt(o.invisible,10)),r=(o.domain_readonly=!1,new Sao.common.DomainInversion),l=r.simplify(this.validation_domains(e,i));if(t||this.check_required(e)||(n="required"),"boolean"==typeof l)l||(n="domain");else if(Sao.common.compare(l,[["id","=",null]]))n="domain";else{var[t,,]=this.get_domains(e,i),c=r.unique_value(l,this._single_value),d=c[0],h=c[1],c=c[2],t=r.unique_value(t,this._single_value)[0];if((!this._is_empty(e)||s||a||t)&&d){!1===c&&(c=null);s=!0,a=jQuery.isEmptyObject(e.group.domain)?r.merge(l):r.merge(e.group.domain),t="AND"==a[0];if(h.contains(".")){var d=h.split(".",1)[0],h=h.split(".",1)[1],u=[];if(t)for(const _ of r.localize_domain(a.slice(1)))u.push(_);"id"==h&&~u.indexOf(d)||(s=!1)}s&&jQuery.isEmptyObject(i)&&(this.set_client(e,c),o.domain_readonly=t)}r.eval_domain(l,Sao.common.EvalEnvironment(e))||(n=l)}return!(o.invalid=n)}}),Sao.field.Char=Sao.class_(Sao.field.Field,{_default:"",set:function(e,t){if(this.description.strip&&t)switch(this.description.strip){case"leading":t=t.trimStart();break;case"trailing":t=t.trimEnd();break;default:t=t.trim()}Sao.field.Char._super.set.call(this,e,t)},get:function(e){return Sao.field.Char._super.get.call(this,e)||this._default}}),Sao.field.Selection=Sao.class_(Sao.field.Field,{_default:null,set_client:function(e,t,i){delete e._values[this.name+":string"],Sao.field.Selection._super.set_client.call(this,e,t,i)}}),Sao.field.MultiSelection=Sao.class_(Sao.field.Selection,{_default:null,_single_value:!1,get:function(e){e=Sao.field.MultiSelection._super.get.call(this,e);return jQuery.isEmptyObject(e)?e=this._default:e.sort(),e},get_eval:function(e){e=Sao.field.MultiSelection._super.get_eval.call(this,e);return e=null===e?[]:e},set_client:function(e,t,i){t=(t="string"==typeof(t=null===t?[]:t)?[t]:t)&&t.slice().sort(),Sao.field.MultiSelection._super.set_client.call(this,e,t,i)}}),Sao.field.DateTime=Sao.class_(Sao.field.Field,{_default:null,time_format:function(e){return e.expr_eval(this.description.format)},set_client:function(e,t,i){var n;t&&(t.isTime?t=(n=this.get(e))?Sao.DateTime.combine(n,t):null:t.isDate&&(n=this.get(e)||Sao.Time(),t=Sao.DateTime.combine(t,n))),Sao.field.DateTime._super.set_client.call(this,e,t,i)},date_format:function(e){e=this.get_context(e);return Sao.common.date_format(e.date_format)}}),Sao.field.Date=Sao.class_(Sao.field.Field,{_default:null,set_client:function(e,t,i){t&&!t.isDate&&(t.isDate=!0,t.isDateTime=!1),Sao.field.Date._super.set_client.call(this,e,t,i)},date_format:function(e){e=this.get_context(e);return Sao.common.date_format(e.date_format)}}),Sao.field.Time=Sao.class_(Sao.field.Field,{_default:null,time_format:function(e){return e.expr_eval(this.description.format)},set_client:function(e,t,i){t&&(t.isDate||t.isDateTime)&&(t=Sao.Time(t.hour(),t.minute(),t.second(),t.millisecond())),Sao.field.Time._super.set_client.call(this,e,t,i)}}),Sao.field.TimeDelta=Sao.class_(Sao.field.Field,{_default:null,converter:function(e){return e.context[this.description.converter]},set_client:function(e,t,i){"string"==typeof t&&(t=Sao.common.timedelta.parse(t,this.converter(e.group))),Sao.field.TimeDelta._super.set_client.call(this,e,t,i)},get_client:function(e){var t=Sao.field.TimeDelta._super.get_client.call(this,e);return Sao.common.timedelta.format(t,this.converter(e.group))}}),Sao.field.Float=Sao.class_(Sao.field.Field,{_default:null,init:function(e){Sao.field.Float._super.init.call(this,e),this._digits={},this._symbol={}},digits:function(e,t=1){var i=e.expr_eval(this.description.digits);if("string"==typeof i){if(!(i in e.model.fields))return;var n=e.model.fields[i],o=n.description.relation,n=n.get(e);if(!(o&&null!==n&&0<=n))return;if(n in this._digits)i=this._digits[n];else{try{i=Sao.rpc({method:"model."+o+".get_digits",params:[n,{}]},e.model.session,!1)}catch(e){return void Sao.Logger.warn("Fail to fetch digits for %s,%s",o,n)}this._digits[n]=i}}if(i&&i.every(function(e){return null!==e}))return e=Math.round(Math.log(Math.abs(t))/Math.LN10),[i[0]+e,i[1]-e]},get_symbol:function(e,t){if(e&&t in e.model.fields){var i=this.get(e)||0,n=1,i=(i<0?n=-1:0===i&&(n=0),e.model.fields[t]),t=i.description.relation,i=i.get(e);if(t&&null!==i&&0<=i){if(i in this._symbol)return this._symbol[i];try{var o=Sao.rpc({method:"model."+t+".get_symbol",params:[i,n,e.get_context()]},e.model.session,!1)||["",1];return this._symbol[i]=o}catch(e){Sao.Logger.warn("Fail to fetch symbol for %s,%s",t,i)}}}return["",1]},check_required:function(e){var t=this.get_state_attrs(e);return 1!=t.required||null!==this.get(e)||1==t.readonly},convert:function(e){return e||0===e?(e=Number(e),isNaN(e)?this._default:e):null},apply_factor:function(e,t,i){return null!==t&&(t/=i,(i=this.digits(e))&&(t=t.toFixed(i[1])),t=this.convert(t)),t},set_client:function(e,t,i,n=1){t=this.apply_factor(e,this.convert(t),n),Sao.field.Float._super.set_client.call(this,e,t,i)},get_client:function(e,t=1,i=!0){var n=this.get(e);return null!==n?(i={useGrouping:i},(e=this.digits(e,t))&&(i.minimumFractionDigits=e[1],i.maximumFractionDigits=e[1]),(n*t).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),i)):""}}),Sao.field.Numeric=Sao.class_(Sao.field.Float,{convert:function(e){return e||0===e?(e=new Sao.Decimal(e),isNaN(e.valueOf())?this._default:e):null}}),Sao.field.Integer=Sao.class_(Sao.field.Float,{convert:function(e){return e||0===e?(e=parseInt(e,10),isNaN(e)?this._default:e):null}}),Sao.field.Boolean=Sao.class_(Sao.field.Field,{_default:!1,set_client:function(e,t,i){t=Boolean(t),Sao.field.Boolean._super.set_client.call(this,e,t,i)},get:function(e){return Boolean(e._values[this.name])},get_client:function(e){return Boolean(e._values[this.name])}}),Sao.field.Many2One=Sao.class_(Sao.field.Field,{_default:null,check_required:function(e){var t=this.get_state_attrs(e);return 1!=t.required||null!==this.get(e)||1==t.readonly},get_client:function(e){var t=(e._values[this.name+"."]||{}).rec_name;return void 0===t&&(this.set(e,this.get(e)),t=(e._values[this.name+"."]||{}).rec_name||""),t},set:function(e,t){var i,n=(e._values[this.name+"."]||{}).rec_name||"";!n&&0<=t&&null!==t&&(i=e.model.fields[this.name].description.relation,n=Sao.rpc({method:"model."+i+".read",params:[[t],["rec_name"],e.get_context()]},e.model.session,!1)[0].rec_name),Sao.setdefault(e._values,this.name+".",{}).rec_name=n,e._values[this.name]=t},set_client:function(e,t,i){var n;t instanceof Array?(n=t[1],t=t[0]):n=t==this.get(e)&&(e._values[this.name+"."]||{}).rec_name||"",t<0&&this.name!=e.group.parent_name&&(t=null,n=""),Sao.setdefault(e._values,this.name+".",{}).rec_name=n,Sao.field.Many2One._super.set_client.call(this,e,t,i)},get_context:function(e,t,i){t=Sao.field.Many2One._super.get_context.call(this,e,t,i);return this.description.datetime_field&&(t._datetime=e.get_eval()[this.description.datetime_field]),t},validation_domains:function(e,t){return this.get_domains(e,t)[0]},get_domain:function(e){var e=this.get_domains(e),t=e[0],e=e[1],i=new Sao.common.DomainInversion;return i.concat([i.localize_domain(t,this.name),e])},get_on_change_value:function(e){return e.group.parent_name==this.name&&e.group.parent?e.group.parent.get_on_change_value([e.group.child_name]):Sao.field.Many2One._super.get_on_change_value.call(this,e)}}),Sao.field.One2One=Sao.class_(Sao.field.Many2One,{}),Sao.field.One2Many=Sao.class_(Sao.field.Field,{init:function(e){Sao.field.One2Many._super.init.call(this,e)},_default:null,_single_value:!1,_set_value:function(e,t,i,n){this._set_default_value(e);var o,s=e._values[this.name];jQuery.when();if(jQuery.isEmptyObject(t)&&(t=[]),"list values"==(o=jQuery.isEmptyObject(t)||!isNaN(parseInt(t[0],10))?"list ids":"list values")){var a=this.get_context(e),r=new Set;for(const h of t)for(const u in h)u in s.model.fields||~u.indexOf(".")||r.add(u);if(r.size){var l,a={method:"model."+this.description.relation+".fields_get",params:[Array.from(r),a]};try{l=Sao.rpc(a,e.model.session,!1)}catch(e){return}s.add_fields(l)}}if("list ids"==o){var c=[];for(const _ of s)~t.indexOf(_.id)||c.push(_);for(const m of c)s.remove(m,!0,!1,!1);s.load(t,n||i)}else{for(const p of t){var d="id"in p?(d=s.get(p.id))||s.new_(!1,p.id):s.new_(!1);i?(d.set_default(p,!1,!1),s.add(d,-1,!1)):(d.set(p,!1),s.push(d))}s.record_modified()}},set:function(e,t,i=!1){var n,o=e._values[this.name];void 0!==o?(n=o.model,o.destroy()):n=e.model.name==this.description.relation?e.model:new Sao.Model(this.description.relation),e._values[this.name]=void 0,this._set_default_value(e,n),this._set_value(e,t,i)},get:function(e){e=e._values[this.name];if(void 0===e)return[];var t,i=e.record_removed,n=e.record_deleted,o=[],s=this.description.relation_field||"",a=[],r=[],l=[];for(const c of e)~i.indexOf(c)||~n.indexOf(c)||(0<=c.id?c.modified&&(delete(t=c.get())[s],jQuery.isEmptyObject(t)||(l.push([c.id]),l.push(t)),a.push(c.id)):(delete(t=c.get())[s],r.push(t)));return jQuery.isEmptyObject(a)||o.push(["add",a]),jQuery.isEmptyObject(r)||o.push(["create",r]),jQuery.isEmptyObject(l)||o.push(["write"].concat(l)),jQuery.isEmptyObject(i)||o.push(["remove",i.map(function(e){return e.id})]),jQuery.isEmptyObject(n)||o.push(["delete",n.map(function(e){return e.id})]),o},set_client:function(e,t,i){"number"==typeof(t=null===t?[]:t)&&(t=[t]);var n=this.get_eval(e),n=!Sao.common.compare(n.sort(),t.sort());this._set_value(e,t,!1,n),n?(this.changed(e),e.validate(null,!0,!1,!0),e.set_modified(this.name)):i&&(this.changed(e),e.validate(null,!0,!1,!0),e.set_modified())},get_client:function(e){return this._set_default_value(e),e._values[this.name]},set_default:function(e,t){return e.modified_fields[this.name]=!0,this.set(e,t,!0)},set_on_change:function(e,t){var i;if(e.modified_fields[this.name]=!0,this._set_default_value(e),t instanceof Array)return this._set_value(e,t,!1,!0);var n={};if(t&&(t.add||t.update)){var o=this.get_context(e),s=e._values[this.name].model.fields,a=[];if(t.add)for(const g of t.add)a.push(g[1]);for(const v of[a,t.update])if(!jQuery.isEmptyObject(v))for(const S of v)for(const y of Object.keys(S))y in s||"id"==y||~y.indexOf(".")||(n[y]=!0);if(jQuery.isEmptyObject(n))i={};else{o={method:"model."+this.description.relation+".fields_get",params:[Object.keys(n),o]};try{i=Sao.rpc(o,e.model.session,!1)}catch(e){return}}}var r,l=e._values[this.name];if(t&&t.delete)for(const b of t.delete){var c=l.get(b);c&&l.remove(c,!1,!1,!1)}if(t&&t.remove)for(const w of t.remove){var d=l.get(w);d&&l.remove(d,!0,!1,!1)}if(t&&(t.add||t.update)){if(t.update)for(const x of t.update)if(x.id){var h=l.get(x.id);if(h){var u,_={};for(u in x)u in n||(_[u]=x[u]);h.set_on_change(_)}}if(l.add_fields(i),t.add)for(const j of t.add){let e;var m=j[0],p=j[1],f=p.id;delete p.id,e=(e=f?l.get(f):e)||l.new_(!1,f),l.add(e,m,!1),e.set_on_change(p)}if(t.update)for(const O of t.update)O.id&&(r=l.get(O.id))&&r.set_on_change(O)}},_set_default_value:function(e,t){void 0===e._values[this.name]&&(t=t||new Sao.Model(this.description.relation),e.model.name==this.description.relation&&(t=e.model),(t=Sao.Group(t,{},[])).set_parent(e),t.parent_name=this.description.relation_field,t.child_name=this.name,t.parent_datetime_field=this.description.datetime_field,e._values[this.name]=t)},get_timestamp:function(e){var t={},i=e._values[this.name]||[],n=i.filter(function(e){return e.modified});for(const e of jQuery.extend(n,i.record_removed,i.record_deleted))jQuery.extend(t,e.get_timestamp());return t},get_eval:function(e){var t=[],e=e._values[this.name];if(void 0!==e){var i=e.record_removed,n=e.record_deleted;for(const o of e)~i.indexOf(o)||~n.indexOf(o)||t.push(o.id)}return t},get_on_change_value:function(e){var t=[],e=e._values[this.name];if(void 0!==e)for(const i of e)i.deleted||i.removed||t.push(i.get_on_change_value([this.description.relation_field||""]));return t},get_removed_ids:function(e){return e._values[this.name].record_removed.map(function(e){return e.id})},get_domain:function(e){return this.get_domains(e)[1]},validation_domains:function(e,t){return this.get_domains(e,t)[0]},validate:function(e,t,i){var n=!1,o=new Sao.common.DomainInversion,s=o.localize_domain(o.domain_inversion(e.group.clean4inversion(i||[]),this.name,Sao.common.EvalEnvironment(e)),this.name);"boolean"==typeof s&&(s=s?[]:[["id","=",null]]);for(const a of e._values[this.name]||[])!a.get_loaded()&&0<=a.id&&jQuery.isEmptyObject(i)||a.validate(null,t,s,!0)||(n="children");o=Sao.field.One2Many._super.validate.call(this,e,t,i);return o&&n?(this.get_state_attrs(e).invalid=n,!1):o},set_state:function(e,t){this._set_default_value(e),Sao.field.One2Many._super.set_state.call(this,e,t)},_is_empty:function(e){return jQuery.isEmptyObject(this.get_eval(e))}}),Sao.field.Many2Many=Sao.class_(Sao.field.One2Many,{get_on_change_value:function(e){return this.get_eval(e)}}),Sao.field.Reference=Sao.class_(Sao.field.Field,{_default:null,get_client:function(e){return e._values[this.name]?[e._values[this.name][0],(e._values[this.name+"."]||{}).rec_name||""]:null},get:function(e){return e._values[this.name]&&e._values[this.name][0]&&null!==e._values[this.name][1]&&-1<=e._values[this.name][1]?e._values[this.name].join(","):null},set_client:function(e,t,i){var n,o,s;t&&(n=(t="string"==typeof t?t.split(","):t)[0],(o=t[1])instanceof Array?(s=o[1],o=o[0]):s=[n,o=o&&!isNaN(parseInt(o,10))?parseInt(o,10):o].join(",")==this.get(e)&&(e._values[this.name+"."]||{}).rec_name||"",Sao.setdefault(e._values,this.name+".",{}).rec_name=s,t=[n,o]),Sao.field.Reference._super.set_client.call(this,e,t,i)},set:function(e,t){var i,n;t?("string"==typeof t?(i=t.split(",")[0],(n=t.split(",")[1])?isNaN(parseInt(n,10))||(n=parseInt(n,10)):n=null):(i=t[0],n=t[1]),t=(e._values[this.name+"."]||{}).rec_name||"",i&&null!==n&&0<=n?!t&&0<=n&&(t=Sao.rpc({method:"model."+i+".read",params:[[n],["rec_name"],e.get_context()]},e.model.session,!1)[0].rec_name):t=i?"":n,Sao.setdefault(e._values,this.name+".",{}).rec_name=t,e._values[this.name]=[i,n]):e._values[this.name]=this._default},get_on_change_value:function(e){return e.group.parent_name==this.name&&e.group.parent?[e.group.parent.model.name,e.group.parent.get_on_change_value([e.group.child_name])]:Sao.field.Reference._super.get_on_change_value.call(this,e)},get_context:function(e,t,i){t=Sao.field.Reference._super.get_context.call(this,e,t,i);return this.description.datetime_field&&(t._datetime=e.get_eval()[this.description.datetime_field]),t},validation_domains:function(e,t){return this.get_domains(e,t)[0]},get_domains:function(e,t){var i=null,e=(e._values[this.name]&&(i=e._values[this.name][0]),Sao.field.Reference._super.get_domains.call(this,e,t));return e[1]=e[1][i]||[],e},get_domain:function(e){var t=null,e=(e._values[this.name]&&(t=e._values[this.name][0]),this.get_domains(e)),i=e[0],e=e[1],n=new Sao.common.DomainInversion,i=n.filter_leaf(i,this.name,t);return i=n.prepare_reference_domain(i,this.name),n.concat([n.localize_domain(i,this.name,!0),e])},get_search_order:function(e){var t,i=Sao.field.Reference._super.get_search_order.call(this,e);return null!==i&&(t=null,i=i[t=e._values[this.name]?e._values[this.name][0]:t]||null),i},get_models:function(e){var e=this.get_domains(e),t=new Sao.common.DomainInversion,i=t.prepare_reference_domain(e[0],this.name);return t.extract_reference_models(t.concat([i,e[1]]),this.name)},_is_empty:function(e){var t=Sao.field.Reference._super._is_empty.call(this,e);return t=!t&&e._values[this.name][1]<0?!0:t}}),Sao.field.Binary=Sao.class_(Sao.field.Field,{_default:null,_has_changed:function(e,t){return e!=t},get_size:function(e){e=e._values[this.name]||0;return e instanceof Uint8Array||"string"==typeof e?e.length:e},get_data:function(t){var e=t._values[this.name],i=jQuery.when(e);if(!(e instanceof Uint8Array)&&"string"!=typeof e&&null!==e){if(t.id<0)return i;e=t.get_context(),i=t.model.execute("read",[[t.id],[this.name]],e).then(e=>(e=e[0][this.name],this.set(t,e),e))}return i}}),Sao.field.Dict=Sao.class_(Sao.field.Field,{_default:{},_single_value:!1,init:function(e){Sao.field.Dict._super.init.call(this,e),this.schema_model=new Sao.Model(e.schema_model),this.keys={}},set:function(e,t){if(t){var i,n=[];for(i in t)n.push(i);n.sort();var o,s={};for(o in n)s[i=n[o]]=t[i];t=s}Sao.field.Dict._super.set.call(this,e,t)},get:function(e){return jQuery.extend({},Sao.field.Dict._super.get.call(this,e))},get_client:function(e){return Sao.field.Dict._super.get_client.call(this,e)},validation_domains:function(e,t){return this.get_domains(e,t)[0]},get_domain:function(e){var t=new Sao.common.DomainInversion,e=this.get_domains(e),i=e[0],e=e[1];return t.concat([t.localize_domain(i),e])},date_format:function(e){e=this.get_context(e);return Sao.common.date_format(e.date_format)},time_format:function(e){return"%X"},add_keys:function(e,t){this.description.schema_model;for(var i=this.get_context(t),n=this.get_domain(t),o=Math.min(10,Sao.config.limit),s=(e=jQuery.extend([],e),e=>{for(const t of e)this.keys[t.name]=t}),a=[];0<e.length;){var r=e.splice(0,o);a.push(this.schema_model.execute("search_get_keys",[[["name","in",r],n],Sao.config.limit],i).then(s))}return jQuery.when.apply(jQuery,a)},add_new_keys:function(e,t){t=this.get_context(t);return this.schema_model.execute("get_keys",[e],t).then(e=>{var t=[];for(const i of e)this.keys[i.name]=i,t.push(i.name);return t})},validate:function(e,t,i){t=Sao.field.Dict._super.validate.call(this,e,t,i);if(this.description.readonly)return t;var n,o,s=new Sao.PYSON.Decoder,i=this.get_eval(e),a=[];for(n in i)n in this.keys&&(o=this.keys[n].domain)&&a.push(s.decode(o));i=(new Sao.common.DomainInversion).eval_domain(a,i);return i||(this.get_state_attrs(e).invalid="domain"),t&&i}})}(),!function(){"use strict";Sao.Tab=Sao.class_(Object,{init:function(e){Sao.Tab.tabs.push(this),this.attributes=jQuery.extend({},e),this.buttons={},this.menu_buttons={},this.id="tab-"+Sao.Tab.counter++,this.name="",this.name_el=jQuery("<span/>"),this.view_prm=jQuery.when()},menu_def:function(){return[{id:"switch_",icon:"tryton-switch",label:Sao.i18n.gettext("Switch"),tooltip:Sao.i18n.gettext("Switch view")},{id:"previous",icon:"tryton-back",label:Sao.i18n.gettext("Previous"),tooltip:Sao.i18n.gettext("Previous Record")},{id:"next",icon:"tryton-forward",label:Sao.i18n.gettext("Next"),tooltip:Sao.i18n.gettext("Next Record")},{id:"search",icon:"tryton-search",label:Sao.i18n.gettext("Search")},null,{id:"new_",icon:"tryton-create",label:Sao.i18n.gettext("New"),tooltip:Sao.i18n.gettext("Create a new record")},{id:"save",icon:"tryton-save",label:Sao.i18n.gettext("Save"),tooltip:Sao.i18n.gettext("Save this record")},{id:"reload",icon:"tryton-refresh",label:Sao.i18n.gettext("Reload/Undo"),tooltip:Sao.i18n.gettext("Reload")},{id:"copy",icon:"tryton-copy",label:Sao.i18n.gettext("Duplicate")},{id:"delete_",icon:"tryton-delete",label:Sao.i18n.gettext("Delete")},null,{id:"logs",icon:"tryton-log",label:Sao.i18n.gettext("View Logs...")},{id:this.screen&&Sao.common.MODELHISTORY.contains(this.screen.model_name)?"revision":null,icon:"tryton-history",label:Sao.i18n.gettext("Show revisions...")},null,{id:"attach",icon:"tryton-attach",label:Sao.i18n.gettext("Attachment"),tooltip:Sao.i18n.gettext("Add an attachment to the record"),dropdown:!0},{id:"note",icon:"tryton-note",label:Sao.i18n.gettext("Note"),tooltip:Sao.i18n.gettext("Add a note to the record")},{id:"action",icon:"tryton-launch",label:Sao.i18n.gettext("Action")},null,{id:"relate",icon:"tryton-link",label:Sao.i18n.gettext("Relate")},{id:"print",icon:"tryton-print",label:Sao.i18n.gettext("Print")},{id:"email",icon:"tryton-email",label:Sao.i18n.gettext("E-Mail..."),tooltip:Sao.i18n.gettext("Send an e-mail using the record")},null,{id:"export",icon:"tryton-export",label:Sao.i18n.gettext("Export")},{id:"import",icon:"tryton-import",label:Sao.i18n.gettext("Import")},null,{id:"close",icon:"tryton-close",label:Sao.i18n.gettext("Close Tab")}]},create_tabcontent:function(){this.el=jQuery("<div/>",{class:"panel panel-default "+this.class_});var e=this.create_toolbar().appendTo(this.el);this.title=e.find(".title"),this.main=jQuery("<div/>",{class:"panel-body row"}).appendTo(this.el),this.content=jQuery("<div/>",{class:"col-xs-12"}).appendTo(this.main),this.info_bar&&this.el.append(this.info_bar.el)},set_menu:function(n){var o;this.menu_def().forEach(t=>{if(t){if(!this[t.id])return;var i=jQuery("<li/>",{role:"presentation"}),e=jQuery("<a/>",{id:t.id,role:"menuitem",href:"#",tabindex:-1}).text(" "+t.label).prepend(Sao.common.ICONFACTORY.get_icon_img(t.icon,{"aria-hidden":"true"})).appendTo(i);this.menu_buttons[t.id]=i,e.click(e=>{e.preventDefault(),i.hasClass("disabled")||this[t.id]()})}else{if(!o)return;i=jQuery("<li/>",{role:"separator",class:"divider hidden-xs"})}(o=i).appendTo(n)})},create_toolbar:function(){var i,n=jQuery("<nav/>",{class:"toolbar panel-heading",role:"toolbar"}).append(jQuery("<div/>",{class:"container-fluid navbar-inverse"}).append(jQuery("<div/>",{class:"dropdown navbar-header navbar-left flip"}).append(jQuery("<a/>",{href:"#",class:"navbar-brand dropdown-toggle","data-toggle":"dropdown",role:"button","aria-expanded":!1,"aria-haspopup":!0}).append(jQuery("<span/>",{class:"title"})).append(jQuery("<span/>",{class:"caret"}))).append(jQuery("<ul/>",{class:"dropdown-menu",role:"menu"})).append(jQuery("<button/>",{type:"button",class:"close visible-xs","aria-label":Sao.i18n.gettext("Close"),title:Sao.i18n.gettext("Close")}).append(jQuery("<span/>",{"aria-hidden":!0}).append("×")).click(()=>{this.close()}))).append(jQuery("<div/>",{class:"btn-toolbar navbar-right flip",role:"toolbar"})));this.set_menu(n.find('ul[role*="menu"]'));return this.menu_def().forEach(e=>{var t;e&&e.tooltip?e.id&&this[e.id]&&(i=i||jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(n.find(".btn-toolbar")),t={type:"button",class:"btn btn-default navbar-btn",title:e.label,id:e.id},e.dropdown&&(t.class+=" dropdown-toggle",t["data-toggle"]="dropdown",t["aria-expanded"]=!1,t["aria-haspopup"]=!0),t=jQuery("<button/>",t).append(Sao.common.ICONFACTORY.get_icon_img(e.icon,{"aria-hidden":"true"})),this.buttons[e.id]=t,e.dropdown?jQuery("<div/>",{class:"btn-group dropdown",role:"group"}).append(t.append(jQuery("<span/>",{class:"caret"}))).append(jQuery("<ul/>",{class:"dropdown-menu",role:"menu","aria-labelledby":e.id})).appendTo(i):t.appendTo(i),this.buttons[e.id].click(e,e=>{var t=e.data,i=this.buttons[t.id];i.data("disabled")?e.preventDefault():(i.data("disabled",!0),(this[t.id](this)||jQuery.when()).always(function(){i.data("disabled",!1)}))})):i=null}),this.buttons.previous&&(this.status_label=jQuery("<span/>",{class:"badge"}).appendTo(jQuery("<div/>",{class:"navbar-text hidden-xs"}).insertAfter(this.buttons.previous)),this.buttons.previous.addClass("hidden-xs")),this.buttons.next&&this.buttons.next.addClass("hidden-xs"),n.find(".btn-toolbar > .btn-group").last().addClass("hidden-xs").find(".dropdown").on("show.bs.dropdown",function(){jQuery(this).parents(".btn-group").removeClass("hidden-xs")}).on("hide.bs.dropdown",function(){jQuery(this).parents(".btn-group").addClass("hidden-xs")}),n},show:function(){Sao.common.scrollIntoViewIfNeeded(jQuery("#tablist").find('a[href="#'+this.id+'"]').tab("show"))},close:function(){var i=jQuery("#tabs"),n=jQuery("#tablist").find("#nav-"+this.id),o=i.find("#"+this.id);return this.show(),this._close_allowed().then(()=>{var e=n.nextAll("li").first(),t=(e.length||(e=n.prevAll("li").first()),n.remove(),o.remove(),Sao.Tab.tabs.indexOf(this));0<=t&&Sao.Tab.tabs.splice(t,1),e.length?e.find("a").tab("show"):Sao.set_url(),i.trigger("ready")})},_close_allowed:function(){return jQuery.when()},set_name:function(e){this.name=e,this.name_el.text(e.split(" / ").pop()),this.name_el.attr("title",e)},get_url:function(){},compare:function(e){return!1}}),Sao.Tab.counter=0,Sao.Tab.tabs=[],Sao.Tab.tabs.close=function(e){var t;return e&&Sao.Tab.tabs.length?Sao.common.sur.run(Sao.i18n.gettext("The following action requires to close all tabs.\nDo you want to continue?")).then(function(){return Sao.Tab.tabs.close(!1)}):Sao.Tab.tabs.length?(t=Sao.Tab.tabs[0]).close().then(function(){return~Sao.Tab.tabs.indexOf(t)?jQuery.Deferred().reject():Sao.Tab.tabs.close()}):Sao.main_menu_screen?Sao.main_menu_screen.save_tree_state().then(function(){Sao.main_menu_screen=null}):jQuery.when()},Sao.Tab.tabs.get_current=function(){return jQuery("#tablist").find("li.active").data("tab")},Sao.Tab.tabs.close_current=function(){this.get_current().close()},Sao.Tab.create=function(e){var t,i=jQuery("#tablist");void 0===e.context&&(e.context={});for(const n of Sao.Tab.tabs)if(n.compare(e))return void Sao.common.scrollIntoViewIfNeeded(i.find('a[href="#'+n.id+'"]').tab("show"));(t=e.model?new Sao.Tab.Form(e.model,e):new Sao.Tab.Board(e)).view_prm.done(function(){Sao.Tab.add(t)})},Sao.Tab.add=function(t){var i=jQuery("#tabs"),e=jQuery("#tablist"),n=jQuery("#tabcontent"),o=jQuery("<a/>",{"aria-controls":t.id,role:"tab","data-toggle":"tab",href:"#"+t.id}).on("show.bs.tab",function(){Sao.set_url(t.get_url(),t.name.split(" / ").pop())}).append(jQuery("<button/>",{class:"close","aria-label":Sao.i18n.gettext("Close"),title:Sao.i18n.gettext("Close")}).append(jQuery("<span/>",{"aria-hidden":!0}).append("×")).click(function(e){e.preventDefault(),t.close()})).append(t.name_el);jQuery("<li/>",{role:"presentation","data-placement":"bottom",id:"nav-"+t.id}).append(o).appendTo(e).data("tab",t),jQuery("<div/>",{role:"tabpanel",class:"tab-pane",id:t.id}).append(t.el).appendTo(n),o.on("hide.bs.tab",function(e){jQuery(e.target).data("scrollTop",i.scrollTop())}),o.on("shown.bs.tab",function(e){i.scrollTop(jQuery(e.target).data("scrollTop")||0)}),Sao.common.scrollIntoViewIfNeeded(o.tab("show")),i.trigger("ready")},Sao.Tab.previous_tab=function(){Sao.Tab.move("prevAll")},Sao.Tab.next_tab=function(){Sao.Tab.move("nextAll")},Sao.Tab.move=function(e){var t=this.tabs.get_current(),i=jQuery("#tabs"),n=jQuery("#tablist"),t=n.find("#nav-"+t.id)[e]("li").first();(t=t.length?t:"prevAll"==e?n.find("li").last():n.find("li").first())&&(t.find("a").tab("show"),i.trigger("ready"))},Sao.Tab.Form=Sao.class_(Sao.Tab,{class_:"tab-form",init:function(e,t){Sao.Tab.Form._super.init.call(this,t);var i=(i=(t=jQuery.extend({},t)).name)||Sao.common.MODELNAME.get(e),n=(this.set_name(i),t.res_id&&t.hasOwnProperty("tab_domain")&&delete t.tab_domain,t.breadcrumb=[i],new Sao.Screen(e,t));n.windows.push(this),this.screen=n,this.info_bar=new Sao.Window.InfoBar,this.create_tabcontent(),this.attachment_screen=null,n.switch_callback=()=>{this===Sao.Tab.tabs.get_current()&&Sao.set_url(this.get_url(),this.name.split(" / ").pop())},this.view_prm=this.screen.switch_view().done(()=>{this.set_buttons_sensitive(),this.content.append(n.screen_container.el),t.res_id?(jQuery.isArray(t.res_id)||(t.res_id=[t.res_id]),n.load(t.res_id),t.res_id.length&&(n.current_record=n.group.get(t.res_id[0])),n.display()):("form"==n.current_view.view_type&&n.new_(),~["tree","graph","calendar"].indexOf(n.current_view.view_type)&&n.search_filter()),this.update_revision()})},create_toolbar:function(){var i=Sao.Tab.Form._super.create_toolbar.call(this),l=this.screen,n=l.model.execute("view_toolbar_get",[],l.context,!1);return[["action","tryton-launch",Sao.i18n.gettext("Launch action")],["relate","tryton-link",Sao.i18n.gettext("Open related records")],["print","tryton-print",Sao.i18n.gettext("Print report")]].forEach(a=>{var e=jQuery("<div/>",{class:"btn-group dropdown",role:"group"}).append(jQuery("<button/>",{type:"button",class:"btn btn-default navbar-btn dropdown-toggle","data-toggle":"dropdown","aria-expanded":!1,"aria-haspopup":!0,title:a[2],id:a[0]}).append(Sao.common.ICONFACTORY.get_icon_img(a[1],{"aria-hidden":"true"})).append(jQuery("<span/>",{class:"caret"}))).append(jQuery("<ul/>",{class:"dropdown-menu",role:"menu","aria-labelledby":a[0]})).insertBefore(i.find("button#email")),t=e.find("button"),r=(this.buttons[a[0]]=t,e.on("show.bs.dropdown",function(){jQuery(this).parents(".btn-group").removeClass("hidden-xs")}).on("hide.bs.dropdown",function(){jQuery(this).parents(".btn-group").addClass("hidden-xs")}),e.find(".dropdown-menu"));t.click(function(){r.find(["."+a[0]+"_button",".divider-button","."+a[0]+"_plugin",".divider-plugin"].join(",")).remove();var e=l.get_buttons().filter(function(e){return a[0]==(e.attributes.keyword||"action")}),t=(e.length&&r.append(jQuery("<li/>",{role:"separator",class:"divider divider-button"})),e.forEach(function(t){jQuery("<li/>",{role:"presentation",class:a[0]+"_button"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(t.attributes.string||"")).click(function(e){e.preventDefault(),l.button(t.attributes)}).appendTo(r)}),[]);for(const o of Sao.Plugins)for(const s of o.get_plugins(l.model.name)){var i=s[0],n=s[1];(s[2]||"action")==a[0]&&t.push([i,n])}t.length&&r.append(jQuery("<li/>",{role:"separator",class:"divider divider-plugin"})),t.forEach(function(e){var t=e[0],n=e[1];jQuery("<li/>",{role:"presentation",class:a[0]+"_plugin"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(t)).click(function(e){e.preventDefault();var e=l.current_view.selected_records.map(function(e){return e.id}),t=l.current_record?l.current_record.id:null,i=l.context_screen?l.context_screen.model_name:null;n({model:l.model.name,model_context:i,id:t,ids:e,paths:l.selected_paths})}).appendTo(r)})}),n[a[0]].forEach(s=>{jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(s.name)).click(e=>{e.preventDefault(),this.modified_save().then(function(){var e,t=jQuery.extend({},s),i=null,n=(l.current_record&&(i=l.current_record.id),e="listed"==s.records?(n=l.listed_records,l.listed_paths):(n=l.selected_records,l.selected_paths),n.map(function(e){return e.id})),o=l.context_screen?l.context_screen.model_name:null,o={model:l.model_name,model_context:o,id:i,ids:n,paths:e};Sao.Action.execute(t,o,jQuery.extend({},l.local_context))})}).appendTo(r)}),"action"!=a[0]&&(t._can_be_sensitive=Boolean(r.children().length)),"print"==a[0]&&n.exports.length&&(t._can_be_sensitive=!0,n.print.length&&r.append(jQuery("<li/>",{role:"separator",class:"divider"})),n.exports.forEach(t=>{jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(t.name)).click(e=>{e.preventDefault(),this.do_export(t)}).appendTo(r)}))}),this.buttons.attach.on("dragover",!1).on("drop",this.attach_drop.bind(this)),i},create_tabcontent:function(){Sao.Tab.Form._super.create_tabcontent.call(this),this.attachment_preview=jQuery("<div/>",{class:"col-xs-12 attachment-preview"}).prependTo(this.main)},compare:function(e){var t;return!!e&&(t=Sao.common.compare,this.screen.model_name===e.model)&&this.attributes.res_id===e.res_id&&t(this.attributes.domain||[],e.domain||[])&&t(this.attributes.view_ids||[],e.view_ids||[])&&(e.view_ids||t(this.attributes.mode||["tree","form"],e.mode||["tree","form"]))&&JSON.stringify(this.screen.local_context)===JSON.stringify(e.context)&&t(this.attributes.search_value||[],e.search_value||[])&&JSON.stringify(this.screen.attributes.tab_domain)===JSON.stringify(e.tab_domain)},_close_allowed:function(){return this.modified_save().then(null,function(e){return e?jQuery.Deferred().resolve():jQuery.Deferred().reject()})},modified_save:function(){return this.screen.save_tree_state(),this.screen.current_view.set_value(),this.screen.modified()?Sao.common.sur_3b.run(Sao.i18n.gettext("This record has been modified\ndo you want to save it?")).then(e=>{switch(e){case"ok":return this.save();case"ko":var t=this.screen.current_record.id;return this.reload(!1).then(()=>t<0?jQuery.Deferred().reject(!0):this.screen.current_record&&t!=this.screen.current_record.id?jQuery.Deferred().reject():void 0);default:return jQuery.Deferred().reject()}}):jQuery.when()},new_:function(){return Sao.common.MODELACCESS.get(this.screen.model_name).create?this.modified_save().then(()=>this.screen.new_().then(()=>{this.info_bar.clear(),this.set_buttons_sensitive()})):jQuery.when()},save:function(e){e&&this.screen.save_tree_state();e=Sao.common.MODELACCESS.get(this.screen.model_name);return e.write||e.create?this.screen.save_current().then(()=>{this.info_bar.add(Sao.i18n.gettext("Record saved."),"info"),this.screen.count_tab_domain(!0)},()=>(this.info_bar.add(this.screen.invalid_message(),"danger"),jQuery.Deferred().reject())):jQuery.Deferred().reject()},switch_:function(){return this.modified_save().then(()=>this.screen.switch_view())},reload:function(e=!0){var t=()=>this.screen.cancel_current().then(()=>{var t=!1,i=null;return this.screen.current_record&&(i=this.screen.current_record.id),"form"!=this.screen.current_view.view_type?this.screen.search_filter(this.screen.screen_container.search_entry.val()).then(()=>{for(const e of this.screen.group)e.id==i&&(this.screen.current_record=e,t=!0);return t}):t}).then(e=>this.screen.display(e).then(()=>{this.info_bar.clear(),this.set_buttons_sensitive(),this.screen.count_tab_domain()}));return e?this.modified_save().then(t):(this.screen.save_tree_state(!1),t())},copy:function(){return Sao.common.MODELACCESS.get(this.screen.model_name).create?this.modified_save().then(()=>this.screen.copy().then(()=>{this.info_bar.add(Sao.i18n.gettext("Working now on the duplicated record(s)."),"info"),this.screen.count_tab_domain(!0)})):jQuery.when()},delete_:function(){var e;return Sao.common.MODELACCESS.get(this.screen.model_name).delete?(e="form"==this.screen.current_view.view_type?Sao.i18n.gettext("Are you sure to remove this record?"):Sao.i18n.gettext("Are you sure to remove those records?"),Sao.common.sur.run(e).then(()=>this.screen.remove(!0,!1,!0).then(()=>{this.info_bar.add(Sao.i18n.gettext("Records removed."),"info"),this.screen.count_tab_domain(!0)},()=>{this.info_bar.add(Sao.i18n.gettext("Records not removed."),"danger")}))):jQuery.when()},previous:function(){return this.modified_save().then(()=>{var e=this.screen.display_previous();return this.info_bar.clear(),this.set_buttons_sensitive(),e})},next:function(){return this.modified_save().then(()=>{var e=this.screen.display_next();return this.info_bar.clear(),this.set_buttons_sensitive(),e})},search:function(){var e=this.screen.screen_container.search_entry;return e.is(":visible")&&window.setTimeout(function(){e.focus()},0),jQuery.when()},logs:function(){var e=this.screen.current_record;if(!e||e.id<0)return this.info_bar.add(Sao.i18n.gettext("You have to select one record."),"info"),jQuery.when();new Sao.Window.Log(e)},revision:function(){var i=null;this.screen.current_record&&(i=this.screen.current_record.id);const n=t=>e=>{e&&e.add(1,"milliseconds"),(e="form"==this.screen.current_view.view_type&&e&&e<t[t.length-1][0]?t[t.length-1][0]:e)!=this.screen.context._datetime&&(this.screen.clear(),this.screen.group._context._datetime=e,"form"!=this.screen.current_view.view_type?this.screen.search_filter(this.screen.screen_container.search_entry.val()):this.screen.group.load([i]),this.screen.display(!0),this.update_revision())};return this.modified_save().then(()=>{var e=this.screen.current_view.selected_records.map(e=>e.id);return this.screen.model.execute("history_revisions",[e],this.screen.context).then(e=>{var t=this.screen.context._datetime;t&&t.add(-1,"milliseconds"),new Sao.Window.Revision(e,t,n(e))})})},update_revision:function(){var e,t,i=this.screen.context._datetime;i=i?(e=Sao.common.date_format(this.screen.context.date_format),e=" @ "+Sao.common.format_datetime(e+" %H:%M:%S.%f",i),t=Sao.common.ellipsize(this.name,80-e.length)+e,this.name+e):(t=Sao.common.ellipsize(this.name,80),this.name),this.title.text(t),this.title.attr("title",i),this.set_buttons_sensitive()},set_buttons_sensitive:function(){if(this.screen.context._datetime)for(const i of["new_","save","delete_","copy","import"])this.buttons[i]&&this.buttons[i].prop("disabled",!0),this.menu_buttons[i]&&this.menu_buttons[i].addClass("disabled");else{var e=Sao.common.MODELACCESS.get(this.screen.model_name),t=this.screen.modified(),t=new Map([["new_",e.create&&!t],["save",(e.create||e.write)&&t&&!this.screen.readonly],["delete_",e.delete],["copy",e.create],["import",e.create]]);for(const[n,e]of t)this.buttons[n]&&this.buttons[n].prop("disabled",!e),this.menu_buttons[n]&&this.menu_buttons[n].toggleClass("disabled",!e)}},attach:function(e){const t=()=>new Sao.Window.Attachment(n,()=>{this.refresh_resources(!0)}),i=()=>{this.attachment_preview.children().length?(this.attachment_preview.empty(),this.attachment_screen=null,this.attachment_preview.removeClass("col-md-4 col-md-push-8"),this.content.removeClass("col-md-8 col-md-pull-4")):(this.attachment_preview.append(this._attachment_preview_el()),this.refresh_attachment_preview(),this.attachment_preview.addClass("col-md-4 col-md-push-8"),this.content.addClass("col-md-8 col-md-pull-4"))};var n,o,s=this.buttons.attach.parents(".dropdown");if(e)return n=this.screen.current_record,(o=s.find(".dropdown-menu")).empty(),Sao.Window.Attachment.get_attachments(n).then(function(e){e.forEach(function(e){var t=e[0],i=e[1],e=jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(t).appendTo(jQuery("<li/>",{role:"presentation"}).appendTo(o));"string"==typeof i?(e.attr("href",i),e.attr("target","_new")):e.click(function(e){e.preventDefault(),i()})})}).always(function(){o.append(jQuery("<li/>",{class:"divider"})),o.append(jQuery("<li/>",{role:"presentation",class:"input-file"}).append(jQuery("<input/>",{type:"file",role:"menuitem",multiple:!0,tabindex:-1}).change(function(){var i=t();Sao.common.get_input_data(jQuery(this),function(e,t){i.add_data(e,t)})})).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(Sao.i18n.gettext("Add...")))),o.append(jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(Sao.i18n.gettext("Preview")).click(function(e){e.preventDefault(),i()}))),o.append(jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(Sao.i18n.gettext("Manage...")).click(function(e){e.preventDefault(),t()})))});window.setTimeout(()=>{this.buttons.attach.click()})},attach_drop:function(e){e.preventDefault(),e.stopPropagation(),e=e.originalEvent;var t=this.screen.current_record;if(t&&!(t.id<0)){var i,n,o=[],s=[],a=[];if(e.dataTransfer.items)for(Sao.Logger.debug("Attach drop items:",e.dataTransfer.items),i=0;i<e.dataTransfer.items.length;i++){var r,l=e.dataTransfer.items[i];if("string"==l.kind){if("text/uri-list"==l.type)r=s;else{if("text/plain"!=l.type)continue;r=a}l=jQuery.Deferred();e.dataTransfer.items[i].getAsString(l.resolve),r.push(l);break}(n=e.dataTransfer.items[i].getAsFile())&&o.push(n)}else for(i=0;i<e.dataTransfer.files.length;i++)(n=e.dataTransfer.files[i])&&o.push(n);var c=new Sao.Window.Attachment(t,()=>{this.refresh_resources(!0)});for(const n of o)Sao.common.get_file_data(n,c.add_data.bind(c));jQuery.when.apply(jQuery,s).then(function(){function e(e){return Boolean(e)}for(const t of arguments)t.split("\r\n").filter(e).forEach(c.add_uri,c)}),jQuery.when.apply(jQuery,a).then(function(){for(const e of arguments)c.add_text(e)}),e.dataTransfer.items?e.dataTransfer.items.clear():e.dataTransfer.clearData()}},_attachment_preview_el:function(){var e=jQuery("<div/>",{class:"text-center"}),t=jQuery("<div/>",{class:"btn-group"}).appendTo(e),i=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Previous"),title:Sao.i18n.gettext("Previous")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-back")).appendTo(t),n=jQuery("<span/>",{class:"badge"}).text("(0/0)").appendTo(jQuery("<span/>",{class:"btn btn-sm btn-link"}).appendTo(t)),o=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Next"),title:Sao.i18n.gettext("Next")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-forward")).appendTo(t),s=new Sao.Screen("ir.attachment",{readonly:!0,mode:["form"],context:{preview:!0}}),t=(this.attachment_screen=s,i.click(function(){return s.display_previous()}),o.click(function(){return s.display_next()}),{});return t.record_message=function(e,t){e=(e||"_")+"/"+t;n.text(e).attr("title",e),i.prop("disabled",!s.has_previous()),o.prop("disabled",!s.has_next())},s.windows.push(t),s.switch_view().done(function(){e.append(s.screen_container.el)}),e},refresh_attachment_preview:function(e){var t;this.attachment_screen&&(t=this.screen.current_record)&&(t=[["resource","=",t.model.name+","+t.id],["type","=","data"]],Sao.common.compare(this.attachment_screen.domain,t)&&!e||(this.attachment_screen.domain=t,this.attachment_screen.search_filter().then(()=>{var e=this.attachment_screen.group;e.length&&(this.attachment_screen.current_record=e[0],this.attachment_screen.display())})))},note:function(){var e=this.screen.current_record;!e||e.id<0||new Sao.Window.Note(e,()=>{this.refresh_resources(!0)})},email:function(){function a(e){return"ir.action.report"==e.type}this.buttons.email.prop("disabled")||this.modified_save().then(()=>{var o,s=this.screen.current_record;!s||s.id<0||(o=this.title.text(),this.screen.model.execute("view_toolbar_get",[],this.screen.context).then(function(e){var i=e.print.filter(a),n={};for(const t of e.emails)n[t.name]=t.id;s.rec_name().then(function(t){function e(e){new Sao.Window.Email(o+": "+t,s,i,e)}Sao.common.selection(Sao.i18n.gettext("Template"),n,!0).then(e,e)})}))})},refresh_resources:function(e){var t=this.screen.current_record;t?t.get_resources(e).always(this.update_resources.bind(this)):this.update_resources(),e&&this.refresh_attachment_preview(!0)},update_resources:function(e){e=e||{};var t=this.screen.get_id(),s=t<0||null==t,t=(e,t,i,n)=>{var e=this.buttons[e],o=e.find(".badge");o.length||(o=jQuery("<span/>",{class:"badge"}).appendTo(e)),n=n?Sao.config.icon_colors[n]:"",o.css("background-color",n),o.css("color","#fff"),o.text(i),e.attr("title",t),e.prop("disabled",s)},i=e.attachment_count||0,n=i||"";99<i&&(n="99+");t("attach",Sao.i18n.gettext("Attachment (%1)",i),n,1),i=e.note_count||0;var e=e.note_unread||0,n="",o=0<e?2:1;i&&(n=9<i?"+":i,n=9<e?"+/"+n:e+"/"+n),t("note",Sao.i18n.gettext("Note (%1/%2)",e,i),n,o)},record_message:function(t,e,i,n){var o,s=(e,t)=>{this.buttons[e]&&this.buttons[e].prop("disabled",!t),this.menu_buttons[e]&&this.menu_buttons[e].toggleClass("disabled",!t)},a="_",r=(t&&(a=""+t,1<(r=this.screen.selected_records.length))&&(a+="#"+r),this.screen.current_view.view_type),l=1<this.screen.number_of_views;for(const c of["print","relate","email","attach"]){let e=this.buttons[c]._can_be_sensitive;void 0===e&&(e=!0),"print"!=c&&"relate"!=c&&"email"!=c||(e|=this.screen.get_buttons().some(function(e){return(e.attributes.keyword||"action")==c})),s(c,t&&e)}s("switch_",(t||"form"==r)&&l),s("delete_",this.screen.deletable),s("previous",this.screen.has_previous()),s("next",this.screen.has_next()),e<i?(o=a+"@"+Sao.common.humanize(e)+"/"+Sao.common.humanize(i),i>=this.screen.count_limit&&(o+="+")):o=a+"/"+Sao.common.humanize(e),this.status_label.text(o).attr("title",o),this.info_bar.clear(),this.set_buttons_sensitive(),this.refresh_attachment_preview()},record_modified:function(){this.set_buttons_sensitive(),this.info_bar.refresh()},record_saved:function(){this.set_buttons_sensitive(),this.refresh_resources()},action:function(){window.setTimeout(()=>{this.buttons.action.click()})},relate:function(){window.setTimeout(()=>{this.buttons.relate.click()})},print:function(){window.setTimeout(()=>{this.buttons.print.click()})},export:function(){this.modified_save().then(()=>{new Sao.Window.Export(this.title.text(),this.screen,this.screen.current_view.get_fields())})},do_export:function(n){this.modified_save().then(()=>{var e,i="listed"==n.records?(e=this.screen.listed_records.map(e=>e.id),this.screen.listed_paths):(e=this.screen.selected_records.map(e=>e.id),this.screen.selected_paths),t=n["export_fields."].map(e=>e.name);this.screen.model.execute("export_data",[e,t,n.header],this.screen.context).then(function(e){var t={data:e},e=(t.data=e.map((e,t)=>{t=i&&i[t]?i[t].length-1:0;return Sao.Window.Export.format_row(e,t)}),","),t=(navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(e=";"),Papa.unparse(t,{quoteChar:'"',delimiter:e}));navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(t=Sao.BOM_UTF8+t),Sao.common.download_file(t,n.name+".csv",{type:"text/csv;charset=utf-8"})})})},import:function(){Sao.common.MODELACCESS.get(this.screen.model_name).create&&new Sao.Window.Import(this.title.text(),this.screen)},get_url:function(){return this.screen.get_url(this.name)}}),Sao.Tab.Board=Sao.class_(Sao.Tab,{class_:"tab-board",init:function(e){Sao.Tab.Board._super.init.call(this,e),this.model=e.model,this.view_id=0<e.view_ids.length?e.view_ids[0]:null,this.context=e.context;var e=(e=e.name)||Sao.common.MODELNAME.get(this.model);this.name=e,this.dialogs=[],this.board=null,this.create_tabcontent(),this.set_name(this.name),this.title.text(this.name_el.text()),e=new Sao.Model("ir.ui.view"),this.view_prm=e.execute("view_get",[this.view_id],this.context),this.view_prm.done(e=>{e=jQuery(jQuery.parseXML(e.arch)),this.board=new Sao.View.Board(e,this.context),this.board.actions_prms.done(()=>{for(var e=0,t=this.board.actions.length;e<t;e++)this.board.actions[e].screen.windows.push(this);this.board.reload()}),this.content.append(this.board.el)})},compare:function(e){var t;return!!e&&(t=Sao.common.compare,this.model===e.model)&&t(this.attributes.view_ids||[],e.view_ids||[])&&JSON.stringify(this.context)===JSON.stringify(e.context)},reload:function(){this.board.reload()},record_message:function(){for(var e=this.board.actions.length,t=0;t<e;t++)this.board.actions[t].update_domain(this.board.actions)},refresh_resources:function(){},update_resources:function(){}}),Sao.Tab.Wizard=Sao.class_(Sao.Tab,{class_:"tab-wizard",init:function(e){Sao.Tab.Wizard._super.init.call(this),this.wizard=e,this.set_name(e.name),(e.tab=this).create_tabcontent(),this.title.text(this.name_el.text()),this.content.remove(),this.content=e.form,this.main.css("padding-top",0).append(e.form)},create_toolbar:function(){return jQuery("<span/>")},_close_allowed:function(){var e=this.wizard,t=(e.state!==e.end_state&&e.end_state in e.states&&e.response(e.states[e.end_state].attributes),jQuery.Deferred());return e.state===e.end_state?t.resolve():t.reject(),t.promise()}})}(),!function(){"use strict";Sao.ScreenContainer=Sao.class_(Object,{init:function(e,t){this.screen=e,this.alternate_viewport=jQuery("<div/>",{class:"screen-container"}),this.alternate_view=!1,this.search_modal=null,this.search_form=null,this.last_search_text="",this.tab_domain=t||[],this.tab_counter=[],this.el=jQuery("<div/>",{class:"screen-container"}),this.filter_box=jQuery("<form/>",{class:"filter-box"}).submit(e=>{e.preventDefault(),this.do_search()});var n,i,e=jQuery("<div/>",{class:"row"}).appendTo(this.filter_box),o=(this.el.append(this.filter_box),this.filter_button=jQuery("<button/>",{type:"button",class:"btn btn-link",title:Sao.i18n.gettext("Filters")}).text(Sao.i18n.gettext("Filters")),this.filter_button.click(this.search_box.bind(this)),this.search_entry=jQuery("<input/>",{class:"form-control mousetrap",placeholder:Sao.i18n.gettext("Search"),autocomplete:"off"}),this.search_list=jQuery("<datalist/>"),this.search_list.uniqueId(),this.search_entry.attr("list",this.search_list.attr("id")),this.search_entry.on("input",this.update.bind(this)),jQuery("<button/>",{type:"button",class:"btn btn-default hidden-md hidden-lg","aria-label":Sao.i18n.gettext("Clear Search"),title:Sao.i18n.gettext("Clear Search")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-clear"))),t=(o.hide(),o.click(()=>{this.search_entry.val("").change(),this.do_search()}),this.search_entry.on("keyup change",()=>{this.search_entry.val()?o.show():o.hide(),this.bookmark_match()}),jQuery("<button/>",{type:"submit",class:"btn btn-default","aria-label":Sao.i18n.gettext("Search"),title:Sao.i18n.gettext("Search")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-search"))),s=(this.but_active=jQuery("<button/>",{type:"button",class:"btn btn-default hidden-xs","aria-expanded":!1}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-archive",{"aria-hidden":!0})),this._set_active_tooltip(),this.but_active.click(this.search_active.bind(this)),this.but_bookmark=jQuery("<button/>",{type:"button",class:"btn btn-default dropdown-toggle","data-toggle":"dropdown","aria-expanded":!1,"aria-label":Sao.i18n.gettext("Bookmarks"),title:Sao.i18n.gettext("Bookmarks")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-bookmark",{"aria-hidden":!0})).uniqueId(),jQuery("<ul/>",{class:"dropdown-menu dropdown-menu-right",role:"menu","aria-labelledby":this.but_bookmark.attr("id")}));this.but_bookmark.click(()=>{s.empty();for(const i of this.bookmarks()){var e=i[1],t=i[2];jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(e).click(t,this.bookmark_activate.bind(this))).appendTo(s)}}),this.but_star=jQuery("<button/>",{class:"btn btn-default hidden-xs",type:"button"}).append(jQuery("<img/>",{class:"icon","aria-hidden":!0}).data("star",!1)).click(this.star_click.bind(this)),this.set_star(),jQuery("<div/>",{class:"input-group input-group-sm"}).append(jQuery("<span/>",{class:"input-group-btn"}).append(this.filter_button)).append(this.search_entry).append(this.search_list).append(jQuery("<span/>",{class:"input-group-btn"}).append(o).append(t).append(this.but_star).append(this.but_bookmark).append(s).append(this.but_active)).appendTo(jQuery("<div/>",{class:"col-sm-10 col-xs-12"}).appendTo(e)),this.but_prev=jQuery("<button/>",{type:"button",class:"btn btn-default btn-sm","aria-label":Sao.i18n.gettext("Previous"),title:Sao.i18n.gettext("Previous")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-back",{"aria-hidden":!0})),this.but_prev.click(this.search_prev.bind(this)),this.but_next=jQuery("<button/>",{type:"button",class:"btn btn-default btn-sm","aria-label":Sao.i18n.gettext("Next"),title:Sao.i18n.gettext("Next")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-forward",{"aria-hidden":!0})),this.but_next.click(this.search_next.bind(this)),jQuery("<div/>",{class:"btn-group",role:"group"}).append(this.but_prev).append(this.but_next).appendTo(jQuery("<div/>",{class:"col-sm-2 pull-right"}).appendTo(e)),this.content_box=jQuery("<div/>",{class:"content-box"}),jQuery.isEmptyObject(this.tab_domain)?this.tab=null:(this.tab=jQuery("<div/>",{class:"tab-domain"}).appendTo(this.el),n=jQuery("<ul/>",{class:"nav nav-tabs",role:"tablist"}).appendTo(this.tab),jQuery("<div/>",{class:"tab-content"}).appendTo(this.tab),this.tab_domain.forEach((e,t)=>{var e=e[0],i=jQuery("<span/>",{class:"badge badge-empty"}).html(" ");i.css("visibility","hidden"),jQuery("<li/>",{role:"presentation",id:"nav-"+t}).append(jQuery("<a/>",{"aria-controls":t,role:"tab","data-toggle":"tab",href:"#"+t}).text(e+" ").append(i)).appendTo(n);this.tab_counter.push(i)}),n.find("a:first").tab("show"),i=this,n.find("a").click(function(e){e.preventDefault(),jQuery(this).tab("show"),i.do_search(),i.screen.count_tab_domain(!0)})),this.el.append(this.content_box)},set_text:function(e){this.search_entry.val(e),this.bookmark_match()},update:function(){var e=this.screen.domain_parser.completion(this.get_text());this.search_list.empty();for(const t of e)jQuery("<option/>",{value:t.trim()}).appendTo(this.search_list)},set_star:function(e){var t,i=this.but_star.children("img"),n=e?(t="tryton-star",Sao.i18n.gettext("Remove this bookmark")):(t="tryton-star-border",Sao.i18n.gettext("Bookmark this filter"));this.but_star.data("star",Boolean(e)),this.but_star.attr("title",n),this.but_star.attr("aria-label",n),Sao.common.ICONFACTORY.get_icon_url(t).then(function(e){i.attr("src",e)})},get_star:function(){return this.but_star.data("star")},star_click:function(){var i,e=this.get_star(),n=this.screen.model_name;const o=()=>{this.bookmark_match(),this.but_bookmark.prop("disabled",jQuery.isEmptyObject(this.bookmarks()))};e?(e=this.bookmark_match(),Sao.common.VIEW_SEARCH.remove(n,e).then(function(){o()})):(i=this.get_text())&&Sao.common.ask.run(Sao.i18n.gettext("Bookmark Name:"),"bookmark").then(e=>{var t;e&&(t=this.screen.domain_parser.parse(i),Sao.common.VIEW_SEARCH.add(n,e,t).then(function(){o()}),this.set_text(this.screen.domain_parser.string(t)))})},bookmarks:function(){return Sao.common.VIEW_SEARCH.get(this.screen.model_name).filter(e=>this.screen.domain_parser.stringable(e[2]))},bookmark_activate:function(e){e.preventDefault();e=e.data;this.set_text(this.screen.domain_parser.string(e)),this.do_search()},bookmark_match:function(){var e=this.get_text();if(e){var t=this.screen.domain_parser.parse(e);this.get_star();for(const s of this.bookmarks()){var i=s[0],n=(s[1],s[2]),o=s[3];if(this.screen.domain_parser.string(n)===e||Sao.common.compare(n,t))return this.set_star(!0),this.but_star.prop("disabled",!o),i}this.but_star.prop("disabled",!e)}this.set_star(!1)},search_prev:function(){this.screen.search_prev(this.get_text())},search_next:function(){this.screen.search_next(this.get_text())},search_active:function(){this.but_active.toggleClass("active"),this._set_active_tooltip(),this.screen.search_filter(this.get_text())},_set_active_tooltip:function(){var e=this.but_active.hasClass("active")?Sao.i18n.gettext("Show active records"):Sao.i18n.gettext("Show inactive records");this.but_active.attr("aria-label",e),this.but_active.attr("title",e)},get_tab_index:function(){return this.tab?this.tab.find("li").index(this.tab.find("li.active")):-1},get_tab_domain:function(){var e;return!this.tab||(e=this.get_tab_index())<0?[]:this.tab_domain[e][1]},set_tab_counter:function(e,t=null){var i;jQuery.isEmptyObject(this.tab_counter)||!this.tab||(t=null===t?this.tab.find("li").index(this.tab.find("li.active")):t)<0||(t=this.tab_counter[t],null===e?(t.attr("title",""),t.html(" "),t.css("visibility","hidden")):(i=Sao.common.humanize(e),1e3<=e&&(i+="+"),t.attr("title",i),t.text(99<e?"99+":e),t.css("visibility","visible")))},do_search:function(){return this.screen.search_filter(this.get_text())},show_filter:function(){this.but_bookmark.prop("disabled",jQuery.isEmptyObject(this.bookmarks())),this.bookmark_match(),this.filter_box.show(),this.tab&&this.tab.show()},hide_filter:function(){this.filter_box.hide(),this.tab&&this.tab.hide()},set:function(e){(this.alternate_view?(this.alternate_viewport.children().detach(),this.alternate_viewport):(this.content_box.children().detach(),this.content_box)).append(e)},get_text:function(){return this.search_entry.val()},search_box:function(){var e=this.screen.domain_parser;const t=()=>{this.search_modal.modal("hide");var t="",i=e.quote.bind(e);for(const s of this.search_form.fields){var n=s[0],o=s[1];let e;(e=o instanceof Sao.ScreenContainer.Between||o instanceof Sao.ScreenContainer.Selection?o.get_value(i):i(o.val()))&&(t+=i(n)+": "+e+" ")}this.set_text(t),this.do_search().then(()=>{this.last_search_text=this.get_text()})};if(!this.search_modal){var i,n=new Sao.Dialog(Sao.i18n.gettext("Filters"),"","lg"),o=(this.search_modal=n.modal,this.search_form=n.content,this.search_form.addClass("form-horizontal"),this.search_form.submit(function(e){e.preventDefault(),t()}),[]);for(i in e.fields){var s=e.fields[i];!s.searchable&&void 0!==s.searchable||s.name.contains(".")||o.push(s)}var a="filter-"+this.screen.model_name+"-";this.search_form.fields=[];for(const p of o){var r,l,c,d,h,u=jQuery("<div/>",{class:"form-group form-group-sm"}).append(jQuery("<label/>",{class:"col-sm-4 control-label",for:a+p.name,text:p.string})).appendTo(n.body);switch(p.type){case"boolean":l=r=jQuery("<select/>",{class:"form-control input-sm",id:a+p.name});for(const f of["",Sao.i18n.gettext("True"),Sao.i18n.gettext("False")])jQuery("<option/>",{value:f,text:f}).appendTo(r);break;case"selection":case"multiselection":r=(l=new Sao.ScreenContainer.Selection(p.selection,a+p.name)).el;break;case"date":c=Sao.common.date_format(this.screen.context.date_format),r=(l=new Sao.ScreenContainer.Dates(c,a+p.name)).el;break;case"datetime":d=Sao.common.date_format(this.screen.context.date_format),h=new Sao.PYSON.Decoder({}).decode(p.format),h=Sao.common.moment_format(h),r=(l=new Sao.ScreenContainer.DateTimes(c=d+" "+h,a+p.name)).el;break;case"time":h=new Sao.PYSON.Decoder({}).decode(p.format),c=Sao.common.moment_format(h),r=(l=new Sao.ScreenContainer.Times(c,a+p.name)).el;break;case"integer":case"float":case"numeric":r=(l=new Sao.ScreenContainer.Numbers(a+p.name)).el;break;default:l=r=jQuery("<input/>",{class:"form-control input-sm",type:"text",placeholder:p.string,id:a+p.name})}jQuery("<div/>",{class:"col-sm-8"}).append(r).appendTo(u),this.search_form.fields.push([p.string,l,r])}jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("Find")}).text(Sao.i18n.gettext("Find")).click(t).appendTo(n.footer)}if(this.search_modal.modal("show"),this.last_search_text.trim()!==this.get_text().trim()){for(var _=0;_<this.search_form.fields.length;_++){var m=this.search_form.fields[_][1];m instanceof Sao.ScreenContainer.Selection?m.set_value([]):m instanceof Sao.ScreenContainer.Between?m.set_value(null,null):m.val("")}this.search_form.fields[0][2].focus()}}}),Sao.ScreenContainer.Between=Sao.class_(Object,{init:function(e){this.el=jQuery("<div/>",{class:"row",id:e}),this.from=this.build_entry(Sao.i18n.gettext("From"),jQuery("<div/>",{class:"col-md-5"}).appendTo(this.el)),jQuery("<p/>",{class:"text-center"}).append("..").appendTo(jQuery("<div/>",{class:"col-md-1"}).appendTo(this.el)),this.to=this.build_entry(Sao.i18n.gettext("To"),jQuery("<div/>",{class:"col-md-5"}).appendTo(this.el))},build_entry:function(e,t){},get_value:function(e){var t=this._get_value(this.from),i=this._get_value(this.to);return t&&i?t!==i?e(t)+".."+e(i):e(t):t?">="+e(t):i?"<="+e(i):void 0},_get_value:function(e){},set_value:function(e,t){this._set_value(this.from,e),this._set_value(this.to,t)},_set_value:function(e,t){},_from_changed:function(e){this._set_value(this.to,this._get_value(this.from))}}),Sao.ScreenContainer.BetweenDates=Sao.class_(Sao.ScreenContainer.Between,{init:function(e,t){this.format=e,Sao.ScreenContainer.BetweenDates._super.init.call(this,t),this.from.change(this._from_changed.bind(this))},_get_value:function(e,t){return e.find("input[type=text]").val()},_set_value:function(e,t){e.find("input[type=text]").val(t)}}),Sao.ScreenContainer.Dates=Sao.class_(Sao.ScreenContainer.BetweenDates,{_input:"date",_input_format:"%Y-%m-%d",_format:Sao.common.format_date,_parse:Sao.common.parse_date,build_entry:function(e,t){var i,t=jQuery("<div/>",{class:"input-group input-group-sm input-icon input-icon-secondary input-"+this._input}).appendTo(t),n=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap"}).appendTo(t),o=jQuery("<input/>",{type:this._input,role:"button",tabindex:-1}),s=(o.click(()=>{var e=this._parse(this.format,n.val()),e=this._format(this._input_format,e);o.val(e)}),o.change(()=>{var e=o.val();e&&(e=this._parse(this._input_format,e),e=this._format(this.format,e),n.val(e),n.focus())}),o[0].type==this._input&&(i=jQuery("<div/>",{class:"icon-input icon-secondary","aria-label":Sao.i18n.gettext("Open the calendar"),title:Sao.i18n.gettext("Open the calendar")}).appendTo(t),o.appendTo(i),Sao.common.ICONFACTORY.get_icon_img("tryton-date").appendTo(i)),new Mousetrap(n[0]));return s.bind("enter",(e,t)=>{var i=this._parse(this.format,n.val()),i=this._format(this.format,i);n.val(i)}),s.bind("=",(e,t)=>{e.preventDefault(),n.val(this._format(this.format,moment()))}),Sao.common.DATE_OPERATORS.forEach(i=>{s.bind(i[0],(e,t)=>{e.preventDefault();e=this._parse(this.format,n.val())||Sao.DateTime();e.add(i[1]),n.val(this._format(this.format,e))})}),t}}),Sao.ScreenContainer.DateTimes=Sao.class_(Sao.ScreenContainer.Dates,{_input:"datetime-local",_input_format:"%Y-%m-%dT%H:%M:%S",_format:Sao.common.format_datetime,_parse:Sao.common.parse_datetime}),Sao.ScreenContainer.Times=Sao.class_(Sao.ScreenContainer.Dates,{_input:"time",_input_format:"%H:%M:%S",_format:Sao.common.format_time,_parse:Sao.common.parse_time,build_entry:function(e,t){e=Sao.ScreenContainer.Times._super.build_entry.call(this,e,t);return~navigator.userAgent.indexOf("Firefox")&&e.find(".icon-input").hide(),e}}),Sao.ScreenContainer.Numbers=Sao.class_(Sao.ScreenContainer.Between,{init:function(e){Sao.ScreenContainer.Numbers._super.init.call(this,e),this.from.change(this._from_changed.bind(this))},build_entry:function(e,t){return jQuery("<input/>",{class:"form-control input-sm",type:"number",step:"any"}).appendTo(t)},_get_value:function(e,t){return e.val()},_set_value:function(e,t){return e.val(t)}}),Sao.ScreenContainer.Selection=Sao.class_(Object,{init:function(e,t){this.el=jQuery("<select/>",{class:"form-control input-sm",multiple:!0,id:t});for(const i of e)jQuery("<option/>",{value:i[1],text:i[1]}).appendTo(this.el)},get_value:function(e){var t=this.el.val();return t=jQuery.isEmptyObject(t)?null:jQuery.map(t,e).reduce(function(e,t){return e&&(e+=";"),e+t})},set_value:function(e){this.el.val(e)}}),Sao.Screen=Sao.class_(Object,{init:function(e,t){this.model_name=e,this.windows=[],this.model=new Sao.Model(e,t),this.attributes=jQuery.extend({},t),this.view_ids=jQuery.extend([],t.view_ids),this.view_to_load=jQuery.extend([],t.mode||["tree","form"]),this.views=[],this.views_preload=t.views_preload||{},this.exclude_field=t.exclude_field,this.current_view=null,this.domain=t.domain||[],this.context_domain=t.context_domain,this.size_limit=null,void 0===this.attributes.limit?this.limit=Sao.config.limit:this.limit=t.limit,this._current_domain=[],this.offset=0,this.order=this.default_order=t.order,this.readonly=this.attributes.readonly||!1;e=Sao.common.MODELACCESS.get(e);e.write||e.create||(this.readonly=!0),this.search_count=0,this.new_group(t.context||{}),this.current_record=null,this.screen_container=new Sao.ScreenContainer(this,t.tab_domain),this.breadcrumb=t.breadcrumb||[],this.context_screen=null,t.context_model&&(this.context_screen=new Sao.Screen(t.context_model,{mode:["form"],context:t.context}),this.context_screen_prm=this.context_screen.switch_view().then(()=>(jQuery("<div/>",{class:"row"}).append(jQuery("<div/>",{class:"col-md-12"}).append(this.context_screen.screen_container.el)).prependTo(this.screen_container.filter_box),this.context_screen.new_()))),t.row_activate?this.row_activate=t.row_activate:this.row_activate=this.default_row_activate,this.tree_states={},this.tree_states_done=[],this.fields_view_tree={},this._domain_parser={},this.pre_validate=!1,this.switch_callback=null},get readonly(){var e=this.selected_records.some(function(e){return e.readonly});return this.__readonly||e},set readonly(e){this.__readonly=e},get deletable(){return this.selected_records.every(function(e){return e.deletable})},get count_limit(){return 100*this.limit+this.offset},load_next_view:function(){var e,t;return jQuery.isEmptyObject(this.view_to_load)?jQuery.when():(jQuery.isEmptyObject(this.view_ids)||(e=this.view_ids.shift()),t=this.view_to_load.shift(),this.add_view_id(e,t))},add_view_id:function(e,t){var i;if(e&&this.views_preload[String(e)])i=this.views_preload[String(e)];else{if(e||!this.views_preload[t])return this.model.execute("fields_view_get",[e,t],this.context).pipe(this.add_view.bind(this));i=this.views_preload[t]}return this.add_view(i),jQuery.when()},add_view:function(e){var t,i=e.arch,n=e.fields,o=e.view_id,i=jQuery(jQuery.parseXML(i)),s=("tree"==i.children().prop("tagName")&&(this.fields_view_tree[o]=e),"eager");for(t in"form"==i.children().prop("tagName")&&(s="lazy"),n)t in this.model.fields&&"eager"!=s?n[t].loading=this.model.fields[t].description.loading:n[t].loading=s;for(t in this.group.add_fields(n),n)this.group.model.fields[t].views.add(o);i=Sao.View.parse(this,o,e.type,i,e.field_childs);return this.views.push(i),i},get number_of_views(){return this.views.length+this.view_to_load.length},switch_view:function(a=null,r=null,t=null,l=!0){if(null!==r&&(r=Number(r)),this.current_view){this.current_view.set_value(),this.current_record&&!~this.current_record.group.indexOf(this.current_record)&&(this.current_record=null);var e=this.current_view.get_fields();if(this.current_record&&this.current_view.editable&&!this.current_record.validate(e,!1,!1,!0))return this.screen_container.set(this.current_view.el),this.current_view.display().done(()=>{this.set_cursor()})}const c=()=>{var e;return!!this.current_view&&(e=!0,null!==a&&(e&=this.current_view.view_type==a),null!==r&&(e&=this.current_view.view_id==r),null!==t&&(e&=this.current_view.creatable==t),e)},d=()=>{const e=()=>{return this.screen_container.set(this.current_view.el),(l?this.display().done(()=>{this.set_cursor()}):jQuery.when()).done(()=>{this.switch_callback&&this.switch_callback()})},t=()=>{this.current_view=this.views[this.views.length-1]};for(var i=()=>(t(),(c()?e:d)()),n=e=>e.view_id==r,o=0;o<this.views.length+this.view_to_load.length;o++){if(this.view_to_load.length)return this.load_next_view().then(i);if(null!==r&&!this.views.find(n))return this.add_view_id(r,a).then(t);var s=this.views.indexOf(this.current_view);if(this.current_view=this.views[(s+1)%this.views.length],c())break}return e()};return d()},search_filter:function(e,i){if(i=i||!1,this.context_screen&&!i){if("pending"==this.context_screen_prm.state())return this.context_screen_prm.then(()=>this.search_filter(e));var t=this.context_screen.current_record;if(t&&!t.validate(null,!1,null,!0))return this.new_group(),this.context_screen.display(!0),jQuery.when();t=this.context_screen.get_on_change_value();delete t.id,this.new_group(jQuery.extend(this.local_context,t))}var t=new Sao.common.DomainInversion,n=this.search_domain(e,!0),t=t.canonicalize(n),o=(Sao.common.compare(t,this._current_domain)||(this._current_domain=t,this.offset=0),this.context);"none"!=this.screen_container.but_active.css("display")&&this.screen_container.but_active.hasClass("active")&&(o.active_test=!1);const s=()=>this.model.execute("search",[n,this.offset,this.limit,this.order],o).then(e=>e.length||this.offset<=0?e:(this.offset=Math.max(this.offset-this.limit,0),s()));return s().then(t=>{var e=jQuery.when(this.search_count);return i||(null!==this.limit&&t.length==this.limit?e=this.model.execute("search_count",[n,0,this.count_limit],o).then(e=>(this.search_count=e,this.search_count),()=>(this.search_count=0,this.search_count)):this.search_count=t.length),e.then(e=>(this.screen_container.but_next.prop("disabled",!(void 0!==this.limit&&t.length==this.limit&&e>this.limit+this.offset)),this.screen_container.but_prev.prop("disabled",this.offset<=0),i?t:(this.clear(),this.load(t).then(()=>{this.count_tab_domain()}))))})},search_domain:function(e=null,t=!1,i=!0){t=t||!1;var n,o=[];return!this.group.parent&&this.domain_parser?(n=this.domain_parser,null!==e?o=n.parse(e):(o=this.attributes.search_value,this.attributes.search_value=null),t&&this.screen_container.set_text(n.string(o))):o=[["id","in",this.group.map(function(e){return e.id})]],jQuery.isEmptyObject(o)?o=this.domain:jQuery.isEmptyObject(this.domain)||(o=["AND",o,this.domain]),"none"!=this.screen_container.but_active.css("display")&&this.screen_container.but_active.hasClass("active")&&(o=jQuery.isEmptyObject(o)?[["active","=",!1]]:[o,["active","=",!1]]),this.current_view&&"calendar"==this.current_view.view_type&&(o=jQuery.isEmptyObject(o)?this.current_view.current_domain():["AND",o,this.current_view.current_domain()]),this.context_domain&&(o=["AND",o,new Sao.PYSON.Decoder(this.context).decode(this.context_domain)]),i&&(e=this.screen_container.get_tab_domain(),jQuery.isEmptyObject(e)||(o=["AND",o,e])),o},count_tab_domain:function(i=!1){var n=this.search_domain(this.screen_container.get_text(),!1,!1),o=this.screen_container.get_tab_index();this.screen_container.tab_domain.forEach((e,t)=>{!e[2]||i&&t!=o||(e=["AND",e[1],n],this.screen_container.set_tab_counter(null,t),this.group.model.execute("search_count",[e,0,1e3],this.context).then(e=>{this.screen_container.set_tab_counter(e,t)}))})},get context(){var e=this.group.context;return this.context_screen&&(e.context_model=this.context_screen.model_name),e},get local_context(){var e=this.group.local_context;return this.context_screen&&(e.context_model=this.context_screen.model_name),e},set_group:function(e){var t,i={},n={};if(this.group){for(t in this.group.model.fields){var o=this.group.model.fields[t];i[t]=o.description,n[t]=o.views}this.group.screens.splice(this.group.screens.indexOf(this),1),jQuery.extend(e.on_write,this.group.on_write),e.on_write=e.on_write.filter(function(e,t,i){return t==i.indexOf(e)}),this.group.parent&&!e.parent&&(e.parent=this.group.parent)}for(t in e.screens.push(this),this.tree_states_done=[],this.views.map(function(e){e.reset()}),this.group=e,this.model=e.model,this.group.parent&&(this.order=null),this.current_record=null,this.group.add_fields(i),n)for(const s of n[t])this.group.model.fields[t].views.add(s);this.group.exclude_field=this.exclude_field},new_group:function(e){e=e||this.context;e=new Sao.Group(this.model,e,[]);e.readonly=this.__readonly,this.set_group(e)},record_modified:function(e=!0){for(const t of this.windows)t.record_modified&&t.record_modified();if(e)return this.display()},record_notify:function(e){for(const n of this.windows)if(n.info_bar){n.info_bar.refresh("notification");for(const o of e){var t=o[0],i=o[1];n.info_bar.add(i,t,"notification")}}},record_message:function(e,t,i,n){for(const o of this.windows)o.record_message&&o.record_message(e,t,i,n)},record_saved:function(){for(const e of this.windows)e.record_saved&&e.record_saved()},update_resources:function(e){for(const t of this.windows)t.update_resources&&t.update_resources(e)},has_update_resources:function(){return this.windows.some(function(e){return e.update_resources})},get current_record(){return this.__current_record},set current_record(e){var t,i,n;this.__current_record===e&&e||(n=i=null,(this.__current_record=e)&&(i=0<=(t=this.group.indexOf(e))?t+this.offset+1:e.get_index_path(),n=e.id),this.record_message(i||0,this.group.length+this.offset,this.search_count,n),this.switch_callback&&this.switch_callback(),this.has_update_resources()&&(e?e.get_resources().always(this.update_resources.bind(this)):this.update_resources()))},load:function(e,t=!0,i=!1,n=-1){return this.group.load(e,i,n),this.current_view&&this.current_view.reset(),this.current_record=null,this.display(t)},display:function(e){var t=[];if(this.views&&this.current_view){var i=this.search_active(~["tree","graph","calendar"].indexOf(this.current_view.view_type));t.push(i);for(const n of this.views)n&&(n==this.current_view||n.el.parent().length)&&t.push(n.display());"tree"==this.current_view.view_type&&"active"in(this.fields_view_tree[this.current_view.view_id]||{}).fields?this.screen_container.but_active.show():this.screen_container.but_active.hide()}return jQuery.when.apply(jQuery,t).then(()=>this.set_tree_state().then(()=>{this.current_record=this.current_record,e&&this.set_cursor(!1,!1)}))},_get_next_record:function(){var e=this.current_view;if(e&&~["tree","form","list-form"].indexOf(e.view_type)&&this.current_record&&this.current_record.group){for(var t=this.current_record.group,i=this.current_record;t;){var n=t.indexOf(i);if(n<t.length-1){i=t[n+1];break}if(!t.parent||i.group.model.name!=t.parent.group.model.name)break;i=t.parent,t=t.parent.group}return i}return this.group[0]},has_next:function(){var e=this._get_next_record();return e&&e!==this.current_record},display_next:function(){var e=this.current_view;return e&&e.set_value(),this.set_cursor(!1,!1),this.current_record=this._get_next_record(),this.set_cursor(!1,!1),e?e.display():jQuery.when()},_get_previous_record:function(){var e=this.current_view;if(e&&~["tree","form","list-form"].indexOf(e.view_type)&&this.current_record&&this.current_record.group){for(var t=this.current_record.group,i=this.current_record;t;){var n=t.indexOf(i);if(0<n){i=t[n-1];break}if(!t.parent||i.group.model.name!=t.parent.group.model.name)break;i=t.parent,t=t.parent.group}return i}return this.group[0]},has_previous:function(){var e=this._get_previous_record();return e&&e!==this.current_record},display_previous:function(){var e=this.current_view;return e&&e.set_value(),this.set_cursor(!1,!1),this.current_record=this._get_previous_record(),this.set_cursor(!1,!1),e?e.display():jQuery.when()},get selected_records(){return this.current_view?this.current_view.selected_records:[]},get selected_paths(){if(this.current_view&&"tree"==this.current_view.view_type)return this.current_view.get_selected_paths()},get listed_records(){return this.current_view&&~["tree","calendar","list-form"].indexOf(this.current_view.view_type)?this.current_view.listed_records:this.current_record?[this.current_record]:[]},get listed_paths(){if(this.current_view&&"tree"==this.current_view.view_type)return this.current_view.get_listed_paths()},clear:function(){this.current_record=null,this.group.clear(),this.tree_states_done=[],this.views.map(function(e){e.reset()})},default_row_activate:function(){this.current_view&&"tree"==this.current_view.view_type&&1==this.current_view.attributes.keyword_open?this.get_id()&&Sao.Action.exec_keyword("tree_open",{model:this.model_name,id:this.get_id(),ids:[this.get_id()]},this.local_context,!1):this.modified()||this.switch_view("form")},get_id:function(){if(this.current_record)return this.current_record.id},new_:function(i=!0,n=null){var o,s=this.current_view,e=jQuery.when();return this.current_view&&"calendar"==this.current_view.view_type&&(o=this.current_view.get_selected_date()),(e=this.current_view&&!this.current_view.creatable?this.switch_view("form",void 0,!0,!1):e).then(()=>{var e,t;if(this.current_view&&this.current_view.editable)return e=(this.current_record||this).group,t=e.new_(!1),(i?t.default_get(n):jQuery.when()).then(()=>(e.add(t,this.new_position),this.current_record=t,"calendar"==s.view_type&&s.set_default_date(t,o),this.display().then(()=>(this.set_cursor(!0,!0),t))))})},get new_position(){var e=null!==this.order?this.order:this.default_order;if(e)for(var t=0;t<e.length;t++){var i=e[t][0],n=e[t][1];if("id"==i&&n){if(n.startsWith("DESC"))return 0;if(n.startsWith("ASC"))return-1}}return this.group.parent?-1:0},set_on_write:function(e){!e||~this.group.on_write.indexOf(e)||this.group.on_write.push(e)},cancel_current:function(e){var t=[];return this.current_record&&(this.current_record.cancel(),this.current_record.id<0)&&(e?(this.current_record.reset(e),this.display()):t.push(this.remove(!1,!1,!1,[this.current_record]))),jQuery.when.apply(jQuery,t)},save_current:function(){var e=this.current_record;if(!e){if(!(this.current_view&&"tree"==this.current_view.view_type&&this.group&&this.group.length))return jQuery.when();this.current_record=this.group[0],e=this.current_record}this.current_view&&(this.current_view.set_value(),n=this.current_view.get_fields());var t=e.get_path(this.group),i=jQuery.Deferred();if(this.current_view&&"tree"==this.current_view.view_type)i=this.group.save().then(()=>this.current_record);else if(e.validate(n,null,null,!0))i=e.save().then(()=>e);else if(this.current_view)return this.current_view.display().then(()=>(this.set_cursor(),jQuery.Deferred().reject()));var n=()=>this.display().always(()=>this.record_saved()).then(()=>i,()=>i);return i.then(e=>(t&&e&&e.id&&t.splice(-1,1,[t[t.length-1][0],e.id]),this.group.get_by_path(t).then(e=>{this.current_record=e}))).then(n,n)},set_cursor:function(e,t){this.current_view&&~["tree","form","list-form"].indexOf(this.current_view.view_type)&&this.current_view.set_cursor(e,t)},modified:function(){function e(e){return e.modified||e.id<0}if(this.current_view&&"tree"!=this.current_view.view_type){if(this.current_record&&e(this.current_record))return!0}else if(this.group.some(e))return!0;return!(!this.current_view||!this.current_view.modified)},unremove:function(){if(this.current_view)for(const e of this.current_view.selected_records)e.group.unremove(e)},remove:function(n,o,s,a){var e=jQuery.when();return!a&&this.current_view&&(a=this.current_view.selected_records),jQuery.isEmptyObject(a)?e:(e=n?this.group.delete_(a):e).then(()=>{for(const t of a)t.group.remove(t,o,s,!1);a[0].group.record_modified();var e=[];if(n)for(const i of a)i.group.parent&&e.push(i.group.parent.save(!1)),~i.group.record_deleted.indexOf(i)&&i.group.record_deleted.splice(i.group.record_deleted.indexOf(i),1),~i.group.record_removed.indexOf(i)&&i.group.record_removed.splice(i.group.record_removed.indexOf(i),1);return this.current_record=null,jQuery.when.apply(jQuery,e).then(()=>this.display().done(()=>{this.set_cursor()}))})},copy:function(){var t=jQuery.Deferred(),e=this.current_view?this.current_view.selected_records:[];return this.model.copy(e,this.context).then(e=>{this.group.load(e,!1,this.new_position),jQuery.isEmptyObject(e)||(this.current_record=this.group.get(e[0])),this.display(!0).always(t.resolve)},t.reject),t.promise()},search_active:function(e){return e&&!this.group.parent?this.screen_container.show_filter():this.screen_container.hide_filter(),jQuery.when()},get domain_parser(){var e=this.current_view?this.current_view.view_id:null;if(e in this._domain_parser)return this._domain_parser[e];e in this.fields_view_tree?i=this.fields_view_tree[e]:(i=this.model.execute("fields_view_get",[!1,"tree"],this.context,!1),this.fields_view_tree[e]=i);var t,i,s,a=jQuery.extend({},i.fields);for(t in a){var n=a[t];"selection"!=n.type&&"multiselection"!=n.type&&"reference"!=n.type||n.selection instanceof Array||((n=jQuery.extend({},n)).selection=this.get_selection(n),a[t]=n)}"arch"in i&&(i=jQuery(jQuery.parseXML(i.arch)),s={},i.find("tree").children().each(function(e,t){if("field"==t.tagName){var i=t.getAttribute("name");if(!(i in s)){s[i]=a[i];for(const o of["string","factor"])t.getAttribute(o)&&(s[i][o]=t.getAttribute(o))}var n=t.getAttribute("symbol");!n||n in s||(s[n]=a[n])}}),a=s);for(const[t,o,r]of new Set([["id",Sao.i18n.gettext("ID"),"integer"],["create_uid",Sao.i18n.gettext("Created by"),"many2one"],["create_date",Sao.i18n.gettext("Created at"),"datetime"],["write_uid",Sao.i18n.gettext("Modified by"),"many2one"],["write_date",Sao.i18n.gettext("Modified at"),"datetime"]]))t in a||(a[t]={string:o,name:t,type:r},"datetime"==r&&(a[t].format='"%H:%M:%S"'));return i=new Sao.common.DomainParser(a,this.context),this._domain_parser[e]=i},get_selection:function(e){var t,i=e.selection_change_with;if(jQuery.isEmptyObject(i))t=this.model.execute(e.selection,[],void 0,!1);else{var n={};for(const o of i)n[o]=null;t=this.model.execute(e.selection,[n],void 0,!1)}return t.sort(function(e,t){return e[1].localeCompare(t[1])})},search_prev:function(e){this.limit&&(this.offset=Math.max(this.offset-this.limit,0)),this.search_filter(e)},search_next:function(e){this.limit&&(this.offset+=this.limit),this.search_filter(e)},invalid_message:function(e){var t,i={};for(t in(e=e||this.current_record).model.fields){var n=e.model.fields[t];i[t]=n.description}var o=new Sao.common.DomainParser(i),s=[],a=e.invalid_fields();for(const n of Object.keys(a).sort()){var r=a[n],l=e.model.fields[n].description.string;"required"==r||Sao.common.compare(r,[[n,"!=",null]])?s.push(Sao.i18n.gettext('"%1" is required.',l)):"domain"==r?s.push(Sao.i18n.gettext('"%1" is not valid according to its domain.',l)):"children"==r?s.push(Sao.i18n.gettext('The values of "%1" are not valid.',l)):o.stringable(r)?s.push(o.string(r)):s.push(Sao.i18n.gettext('"%1" is not valid according to its domain.'),l)}return 5<s.length&&(s.splice(5,s.length),s.push("...")),s.join("\n")},get:function(){return this.current_record?(this.current_view&&this.current_view.set_value(),this.current_record.get()):null},get_on_change_value:function(){return this.current_record?(this.current_view&&this.current_view.set_value(),this.current_record.get_on_change_value()):null},reload:function(e,t){this.group.reload(e);var i=[];return t&&i.push(this.group.written(e)),this.group.parent&&i.push(this.group.parent.root_parent.reload()),jQuery.when.apply(jQuery,i).then(()=>this.display())},get_buttons:function(){var e=this.current_view?this.current_view.selected_records:[];if(jQuery.isEmptyObject(e))return[];var t=this.current_view?this.current_view.get_buttons():[];for(const i of e)t=t.filter(function(e){return"instance"!==e.attributes.type&&!((e=i.expr_eval(e.attributes.states||{})).invisible||e.readonly)});return t},button:function(s){var a,r,t;const l=e=>this.reload(a,!0).then(()=>{"string"==typeof e?this.client_action(e):e&&Sao.Action.execute(e,{model:this.model_name,id:this.current_record.id,ids:a},null,this.context,!0),this.record_saved()});this.current_view&&(r=this.current_view.selected_records,this.current_view.set_value(),t=this.current_view.get_fields());var e=[];const c=e=>()=>{this.display(!0),e.validate(t)};for(const n of r){var i=n.expr_eval(s.states||{}).pre_validate||[];e.push(n.validate(t,!1,i))}return jQuery.when.apply(jQuery,e).then((...e)=>{for(var i=0;i<r.length;i++){var t=r[i],n=e[i];if(!n)return void Sao.common.warning.run(this.invalid_message(t),Sao.i18n.gettext("Pre-validation")).then(c(t))}var o=jQuery.when();return(o=s.confirm?Sao.common.sur.run(s.confirm):o).then(()=>{var e,t=this.current_record;return"instance"===s.type?(e=t.expr_eval(s.change||[]),e=t._get_on_change_args(e),t.model.execute(s.name,[e],this.context).then(function(e){t.set_on_change(e),t.set_modified()})):t.save(!1).then(()=>{var e=this.context;for(e._timestamp={},a=[],i=0;i<r.length;i++)t=r[i],jQuery.extend(e._timestamp,t.get_timestamp()),a.push(t.id);return t.model.execute(s.name,[a],e).then(l).fail(()=>this.reload(a,!0))})})})},client_action:function(e){var t=Sao.common.MODELACCESS.get(this.model_name);"new"==e?t.create&&this.new_():"delete"==e?!t.delete||this.current_record&&!this.current_record.deletable||this.remove(!this.group.parent,!1,!this.group.parent):"remove"==e?t.write&&t.read&&this.group.parent&&this.remove(!1,!0,!1):"copy"==e?t.create&&this.copy():"next"==e?this.display_next():"previous"==e?this.display_previous():"close"==e?Sao.Tab.tabs.close_current():e.startsWith("switch")?this.switch_view.apply(this,e.split(" ",3).slice(1)):"reload"==e?this.current_view&&~["tree","graph","calendar"].indexOf(this.current_view.view_type)&&!this.group.parent&&this.search_filter():"reload menu"==e?Sao.Session.current_session.reload_context().then(function(){Sao.menu()}):"reload context"==e&&Sao.Session.current_session.reload_context()},get_url:function(e){function t(e){return JSON.stringify(Sao.rpc.prepareObject(e))}var i,n=[],o=(jQuery.isEmptyObject(this.domain)||n.push(["domain",t(this.domain)]),this.local_context),o=(jQuery.isEmptyObject(o)||n.push(["context",t(o)]),this.context_screen&&n.push(["context_model",this.context_screen.model_name]),e&&n.push(["name",t(e)]),jQuery.isEmptyObject(this.attributes.tab_domain)||n.push(["tab_domain",t(this.attributes.tab_domain)]),["model",this.model_name]),e=this.views.map(function(e){return e.view_id}).concat(this.view_ids);return this.current_view&&"form"!=this.current_view.view_type?(i=this.attributes.search_value||(i=this.screen_container.get_text(),this.domain_parser.parse(i)),jQuery.isEmptyObject(i)||n.push(["search_value",t(i)])):this.current_record&&-1<this.current_record.id&&(o.push(this.current_record.id),this.current_view)&&(i=e.indexOf(this.current_view.view_id),e=e.slice(i).concat(e.slice(0,i))),jQuery.isEmptyObject(e)||n.push(["views",t(e)]),n=n.map(function(e){return e.map(encodeURIComponent).join("=")}).join("&"),o=o.join("/"),n&&(o+=";"+n),o},save_tree_state:function(e=!0){for(var t,i,n,o,s,a,r,l=[],c=this.group.parent?this.group.parent.id:null,d=function(){Sao.Session.current_session.cache.clear("model.ir.ui.view_tree_state.get")},h=()=>{Sao.Logger.warn("Unable to set view tree state for %s",this.model_name)},u=0,_=this.views.length;u<_;u++)if("form"==(t=this.views[u]).view_type){for(var m in t.widgets)if(t.widgets.hasOwnProperty(m))for(n=0,o=(i=t.widgets[m]).length;n<o;n++)i[n].screen&&(r=i[n].screen.save_tree_state(e),l.push(r));1==this.views.length&&this.current_record&&(c in this.tree_states||(this.tree_states[c]={}),this.tree_states[c][t.children_field||null]=[[],[[this.current_record.id]]])}else~["tree","list-form"].indexOf(t.view_type)&&(s="tree"==t.view_type?t.get_expanded_paths():[],a=t.get_selected_paths(),c in this.tree_states||(this.tree_states[c]={}),this.tree_states[c][t.children_field||null]=[s,a],e)&&parseInt(t.attributes.tree_state,10)&&(r=new Sao.Model("ir.ui.view_tree_state").execute("set",[this.model_name,this.get_tree_domain(c),t.children_field,JSON.stringify(s),JSON.stringify(a)],{}).then(d).fail(h),l.push(r));return jQuery.when.apply(jQuery,l)},get_tree_domain:function(e){e=e?(this.domain||[]).concat([[this.exclude_field,"=",e]]):this.domain;return JSON.stringify(Sao.rpc.prepareObject(e))},set_tree_state:function(){var t,e,a=this.current_view;return!a||!~["tree","form","list-form"].indexOf(a.view_type)||~this.tree_states_done.indexOf(a)||"form"==a.view_type&&!jQuery.isEmptyObject(this.tree_states_done)||(~["tree","list-form"].indexOf(a.view_type)&&!parseInt(a.attributes.tree_state,10)&&this.tree_states_done.push(a),(t=this.group.parent?this.group.parent.id:null)<0)?jQuery.when():(t in this.tree_states||(this.tree_states[t]={}),e=void 0===(e=this.tree_states[t][a.children_field||null])&&parseInt(a.attributes.tree_state,10)?new Sao.Model("ir.ui.view_tree_state").execute("get",[this.model_name,this.get_tree_domain(t),a.children_field],{}).then(e=>(e=[JSON.parse(e[0]),JSON.parse(e[1])],t in this.tree_states||(this.tree_states[t]={}),this.tree_states[t][a.children_field||null]=e)).fail(()=>{Sao.Logger.warn("Unable to get view tree state for %s",this.model_name)}):jQuery.when(e),this.tree_states_done.push(a),e.done(e=>{var t,i=[],n=[];if(e&&(i=e[0],n=e[1]),"tree"==a.view_type)return a.display(n,i);if("list-form"==a.view_type)return a.display(n);if(!jQuery.isEmptyObject(n)){for(const s of n[0]){var o=this.group.get(s);if(!o)break;t=o}t&&t!=this.current_record&&(this.current_record=t,a.display())}}))}}),Sao.Screen.tree_column_optional={}}(),!function(){"use strict";Sao.View=Sao.class_(Object,{view_type:null,el:null,mnemonic_widget:null,view_id:null,modified:null,editable:null,creatable:null,children_field:null,xml_parser:null,init:function(e,t,i){this.view_id=e,this.screen=t,this.widgets={},this.state_widgets=[];e=i.children()[0].attributes;this.attributes={};for(const s of e)this.attributes[s.name]=s.value;t.set_on_write(this.attributes.on_write);var n,o={};for(n in this.screen.model.fields)o[n]=this.screen.model.fields[n].description;this.xml_parser&&new this.xml_parser(this,this.screen.exclude_field,o).parse(i.children()[0]),this.reset()},set_value:function(){},get record(){return this.screen.current_record},set record(e){this.screen.current_record=e},get group(){return this.screen.group},get selected_records(){return[]},get_fields:function(){return[]},get_buttons:function(){return[]},reset:function(){}}),Sao.View.idpath2path=function(e,t){var i,n=[];if(!t)return[];for(var o=0,s=e.rows.length;o<s;o++)if(e.rows[o].record.id==t[0]){n.push(o),i=Sao.View.idpath2path(e.rows[o],t.slice(1,t.length)),n=n.concat(i);break}return n},Sao.View.parse=function(e,t,i,n,o){switch(i){case"tree":return new Sao.View.Tree(t,e,n,o);case"form":return new Sao.View.Form(t,e,n);case"graph":return new Sao.View.Graph(t,e,n);case"calendar":return new Sao.View.Calendar(t,e,n);case"list-form":return new Sao.View.ListForm(t,e,n)}},Sao.View.XMLViewParser=Sao.class_(Object,{init:function(e,t,i){this.view=e,this.exclude_field=t,this.field_attrs=i},_node_attributes:function(e){var t,i={};for(t of e.attributes)i[t.name]=t.value;var n={};i.name&&(n=this.field_attrs[i.name]||{});for(const o of["readonly","homogeneous"])i[o]&&(i[o]=1==i[o]);for(const s of["yexpand","yfill","xexpand","xfill","colspan","position","height","width"])i[s]&&(i[s]=Number(i[s]));for(const a of["xalign","yalign"])i[a]&&(i[a]=Number(i[a]));if(!jQuery.isEmptyObject(n)){i.widget||(i.widget=n.type),"label"==e.tagName&&void 0===i.string&&(i.string=n.string+Sao.i18n.gettext(":")),"field"!=e.tagName||i.help||(i.help=n.help);for(const r of["relation","domain","selection","string","states","relation_field","views","invisible","add_remove","sort","context","size","filename","autocomplete","translate","create","delete","selection_change_with","schema_model","required","help_selection","help_field","order","symbol","monetary"])r in n&&!(r in i)&&(i[r]=n[r])}return i},parse:function(e){var t;e.tagName&&(t=this._node_attributes(e),this["_parse_"+e.tagName](e,t))}})}(),!function(){"use strict";function s(e){return e.replace(/[\n\r]/gm,"")}Sao.View.FormXMLViewParser=Sao.class_(Sao.View.XMLViewParser,{init:function(e,t,i){Sao.View.FormXMLViewParser._super.init.call(this,e,t,i),this._containers=[],this._mnemonics={}},get container(){return 0<this._containers.length?this._containers[this._containers.length-1]:null},_parse_form:function(e,t){var i=new Sao.View.Form.Container(Number(e.getAttribute("col")||4));if(this.view.containers.push(i),this.parse_child(e,i),0<this._containers.length)throw"AssertionError";this.view.el.append(i.el)},parse_child:function(e,t){t&&this._containers.push(t);for(const i of e.childNodes)this.parse(i);t&&(t instanceof Sao.View.Form.Container&&t.setup_grid_template(),this._containers.pop())},_parse_field:function(e,t){var i,n=t.name;n&&n==this.exclude_field?this.container.add(null,t):(i=new Sao.View.FormXMLViewParser.WIDGETS[t.widget](this.view,t),this.view.widgets[n]||(this.view.widgets[n]=[]),this.view.widgets[n].push(i),i.position=this.view.widget_id+=1,i.expand&&(void 0===t.yexpand&&(t.yexpand=!0),void 0===t.yfill)&&(t.yfill=!0),void 0!==t.height&&(i.el.css("min-height",t.height+"px"),1==i.el.children().length)&&i.el.children().css("min-height","inherit"),void 0!==t.width&&i.el.css("min-width",t.width+"px"),void 0===t.xalign&&(t.xexpand?t.xalign=0:t.xalign=.5),void 0===t.yalign&&(t.yexpand?t.yalign=0:t.yalign=.5),this.container.add(i,t),this._mnemonics[n]&&i.labelled&&(t=this._mnemonics[n],n=Sao.common.accesskey(t.label_el.text()),t.label_el.uniqueId(),i.labelled.uniqueId(),i.labelled.attr("aria-labelledby",t.el.attr("id")),i.labelled.attr("accesskey",n),~["INPUT","SELECT"].indexOf(i.labelled.get(0).tagName)&&jQuery("<span/>",{"data-accesskey":n}).appendTo(i.labelled.parent()),t.label_el.attr("for",i.labelled.attr("id"))))},_parse_button:function(e,t){var i=new Sao.common.Button(t);i.el.click(i,this.view.button_clicked.bind(this.view)),this.view.state_widgets.push(i),this.container.add(i,t)},_parse_link:function(e,t){var i=new Sao.View.Form.Link(t);this.view.state_widgets.push(i),this.container.add(i,t)},_parse_image:function(e,t){var i=new Sao.View.Form.Image_(t);this.view.state_widgets.push(i),this.container.add(i,t)},_parse_separator:function(e,t){var i,n,o=t.name;o&&o==this.exclude_field?this.container.add(null,t):(n=t.string,i=new Sao.View.Form.Separator(n,t),n&&(n=t.xalign,i.label_el.css("text-align",n=.5==(n=void 0===n?0:n)?"center":n<=.5?"start":"end")),this.view.state_widgets.push(i),this.container.add(i,t),o&&(this._mnemonics[o]=i))},_parse_label:function(e,t){var i,n=t.name;n&&n==this.exclude_field?this.container.add(null,t):(void 0===t.xexpand&&(t.xexpand=0),void 0===t.xalign&&(t.xalign=1),void 0===t.yalign&&(t.yalign=.5),i=new Sao.View.Form.Label(t.string,t),this.view.state_widgets.push(i),this.container.add(i,t),n&&(this._mnemonics[n]=i))},_parse_newline:function(e,t){this.container.add_row()},_parse_notebook:function(e,t){void 0===t.colspan&&(t.colspan=4);var i=new Sao.View.Form.Notebook(t);void 0!==t.height&&i.el.css("min-height",t.height+"px"),void 0!==t.width&&i.el.css("min-width",t.width+"px"),this.view.state_widgets.push(i),this.view.notebooks.push(i),this.container.add(i,t),this.parse_child(e,i)},_parse_page:function(e,t){var i;t.name&&t.name==this.exclude_field||(i=new Sao.View.Form.Container(Number(e.getAttribute("col")||4)),this.view.containers.push(i),this.parse_child(e,i),e=new Sao.View.Form.Page(this.container.add(i.el,t.string,t.icon),t),this.view.state_widgets.push(e))},_parse_group:function(e,t){var i,n=new Sao.View.Form.Container(Number(e.getAttribute("col")||4));this.view.containers.push(n),void 0===t.xalign&&(t.xalign=.5),void 0===t.yalign&&(t.yalign=.5),t.name&&t.name==this.exclude_field?this.container.add(null,t):(void 0!==t.expandable?((i=new Sao.View.Form.Expander(t)).set_expanded("1"===t.expandable),this.view.expandables.push(i)):i=new Sao.View.Form.Group(t),i.add(n),this.view.state_widgets.push(i),this.container.add(i,t),this.parse_child(e,n))},_parse_hpaned:function(e,t){this._parse_paned(e,t,"horizontal")},_parse_vpaned:function(e,t){this._parse_paned(e,t,"vertical")},_parse_paned:function(e,t,i){i=new Sao.common.Paned(i);this.container.add(i,t),this.parse_child(e,i)},_parse_child:function(e,t){var i=this.container,n=new Sao.View.Form.Container(Number(e.getAttribute("col")||4));this.view.containers.push(n),this.parse_child(e,n),(i.get_child1().children().length?i.get_child2():i.get_child1()).append(n.el)}}),Sao.View.Form=Sao.class_(Sao.View,{editable:!0,creatable:!0,view_type:"form",xml_parser:Sao.View.FormXMLViewParser,init:function(e,t,i){this.el=jQuery("<div/>",{class:"form"}),this.notebooks=[],this.expandables=[],this.containers=[],this.widget_id=0,Sao.View.Form._super.init.call(this,e,t,i),this.attributes.creatable&&(this.creatable=Boolean(parseInt(this.attributes.creatable,10))),this.attributes.scan_code&&(this.scan_code_btn=new Sao.common.Button({string:Sao.i18n.gettext("Scan"),icon:"tryton-barcode-scanner",states:this.attributes.scan_code_states},null,"lg","btn-primary"),this.scan_code_btn.el.click(()=>{new Sao.Window.CodeScanner(this.on_scan_code.bind(this),"loop"==this.attributes.scan_code)}),this.el.append(jQuery("<div/>",{class:"btn-code-scanner"}).append(this.scan_code_btn.el)),this.state_widgets.push(this.scan_code_btn))},get_fields:function(){return Object.keys(this.widgets)},get_buttons:function(){var e,t=[];for(e in this.state_widgets){var i=this.state_widgets[e];i instanceof Sao.common.Button&&t.push(i)}return t},display:function(){var l,e=this.record,t=[];if(this.scan_code_btn&&this.scan_code_btn.el.toggle(Boolean(e)),e){var i=new Set(this.get_fields());for(const s in e.model.fields)~(l=e.model.fields[s]).views.has(this.view_id)&&i.add(s);var n=[];for(const a of i)l=e.model.fields[a],n.push([a,"eager"==(l.description.loading||"eager"),l.views.size]);n.sort(function(e,t){return!e[1]&&t[1]?-1:e[1]&&!t[1]?1:e[2]-t[2]});for(const r of n){var o=r[0];t.push(e.load(o))}}return jQuery.when.apply(jQuery,t).done(()=>{var e=this.record;for(const o in this.widgets){var t=this.widgets[o];l=null,(l=e?e.model.fields[o]:l)&&l.set_state(e);for(const s of t)s.display()}var i=[];for(const a in this.state_widgets){var n=this.state_widgets[a].set_state(e);n&&i.push(n)}for(const r of this.containers)r.set_grid_template();jQuery.when.apply(jQuery,i).done(()=>{for(const e of this.containers)e.set_grid_template()})})},set_value:function(){var e=this.record;if(e)for(var t in this.widgets)if(t in e.model.fields){var i=this.widgets[t],n=e.model.fields[t];for(const o of i)o.set_value(e,n)}},button_clicked:function(e){e=e.data;e.el.prop("disabled",!0),this.screen.button(e.attributes)},on_scan_code:function(e){var t=this.record;return t?t.on_scan_code(e,this.attributes.scan_code_depends||[]).done(()=>{"submit"==this.attributes.scan_code&&this.el.parents("form").submit()}):jQuery.when()},get selected_records(){return this.record?[this.record]:[]},get modified(){for(var e in this.widgets)for(const t of this.widgets[e])if(t.modified)return!0;return!1},set_cursor:function(e,t){var i,n,o,s,a,r,l,c,d,h,u=0<jQuery(document.activeElement).closest(this.el).length;if(t||!u){if(t)for(i=0;i<this.notebooks.length;i++)(a=this.notebooks[i]).set_current_page();this.attributes.cursor in this.widgets?s=Sao.common.find_focusable_child(this.widgets[this.attributes.cursor][0].el):(r=Sao.common.find_focusable_child(this.el))&&r.focus()}u=this.record;if(u){var _=[],m=this.el.find(".has-error");for(n in u.invalid_fields())for(c=this.widgets[n]||[],i=0;i<m.length;i++)for(d=jQuery(m[i]),o=0;o<c.length;o++)if(0<d.closest(c[o].el).length){_.push(d);break}0<_.length&&(s=Sao.common.find_first_focus_widget(this.el,_))}if(s){for(i=0;i<this.notebooks.length;i++)for(h=(a=this.notebooks[i]).get_n_pages(),o=0;o<h;o++)if(r=a.get_nth_page(o),0<jQuery(s).closest(r).length){a.set_current_page(o);break}for(i=0;i<this.expandables.length;i++)l=this.expandables[i],0<jQuery(s).closest(l.el).length&&l.set_expanded(!0);jQuery(s).find("input,select,textarea").addBack(s).focus()}}}),Sao.View.Form.Container=Sao.class_(Object,{init:function(e=4){this.col=e=e<0?0:e,this.el=jQuery("<div/>",{class:"form-container"}),this.col<=0?this.el.addClass("form-hcontainer"):1==this.col&&this.el.addClass("form-vcontainer"),this._col=1,this._row=1,this._xexpand=new Set,this._colspans=[],this._yexpand=new Set,this._grid_cols=[],this._grid_rows=[]},add_row:function(){this._col=1,this._row+=1},add:function(e,t){var i,n,o=t.colspan,s=(void 0===o&&(o=1),t.xfill),a=(void 0===s&&(s=1),t.xexpand),r=(void 0===a&&(a=1),0<this.col&&(o>this.col&&(o=this.col),this._col+o>this.col+1)&&(this._col=1,this._row+=1),e&&(i=e.el),jQuery("<div/>",{class:"form-item "+(e&&e.class_||"")}).append(i));if(r.css("grid-column",this._col+" / "+(this._col+o)),r.css("grid-row",this._row+" / "+(this._row+1)),this.el.append(r),e){if(a&&1==o)this._xexpand.add(this._col);else if(a){for(var l=[],c=this._col;c<this._col+o;c++)l.push(c);this._colspans.push(l)}t.yexpand&&this._yexpand.add(this._row),this._col+=o,void 0!==t.xalign?(n=.5==t.xalign?"center":t.xalign<=.5?"start":"end",r.addClass("xalign-"+n)):r.addClass("xalign-start"),a&&r.addClass("xexpand"),s&&(r.addClass("xfill"),a)&&i.addClass("xexpand"),void 0!==t.yalign&&(n=.5==t.yalign?"center":t.yalign<=.5?"start":"end",r.addClass("yalign-"+n)),t.yfill&&(r.addClass("yfill"),t.yexpand)&&i.addClass("yexpand"),t.help&&e.el.attr("title",t.help)}else this._col+=o},setup_grid_template:function(){for(const n of this._colspans){var e=!1;for(const i of n)if(this._xexpand.has(i)){e=!0;break}e||this._xexpand.add(Math.round((n[0]+n[n.length-1])/2))}var t,i=this.col<=0?this._col:this.col;if(this._xexpand.size)for(t=1;t<=i;t++)this._xexpand.has(t)?this._grid_cols.push(`minmax(min-content, ${i}fr)`):this._grid_cols.push("min-content");else for(t=1;t<=i;t++)this._grid_cols.push("min-content");if(this._yexpand.size)for(t=1;t<=this._row;t++)this._yexpand.has(t)?this._grid_rows.push(`minmax(min-content, ${this._row}fr)`):this._grid_rows.push("min-content");else for(t=1;t<=this._row;t++)this._grid_rows.push("min-content")},set_grid_template:function(){for(var e,t,i,n,o,s=this._grid_cols.slice(),a=this._grid_rows.slice(),r=[],l=[],c=0;c<s.length;c++)r.push([]);for(c=0;c<a.length;c++)l.push([]);for(o of this.el.children()){for(o=jQuery(o),e=parseInt(o.css("grid-column-start"),10),t=parseInt(o.css("grid-column-end"),10),i=parseInt(o.css("grid-row-start"),10),n=parseInt(o.css("grid-row-end"),10),c=e;c<t;c++)r[c-1].push(o);for(c=i;c<n;c++)l[c-1].push(o)}function d(e){var t=!0;for(const i of e.children(":not(.tooltip)"))if("none"!=jQuery(i).css("display")){t=!1;break}return e.toggleClass("form-empty",t),t}for(c=0;c<s.length;c++)r[c].every(d)&&(s[c]="0px");for(c=0;c<a.length;c++)l[c].every(d)&&(a[c]="0px");this.el.css("grid-template-columns",s.join(" ")),this.el.css("grid-template-rows",a.join(" "))}}),Sao.View.Form.StateWidget=Sao.class_(Object,{init:function(e){this.attributes=e},set_state:function(e){e=e?e.expr_eval(this.attributes.states||{}):{},e=e.invisible;(e=void 0===e?this.attributes.invisible:e)?this.hide():this.show()},show:function(){this.el.show()},hide:function(){this.el.hide()}}),Sao.View.Form.LabelMixin=Sao.class_(Sao.View.Form.StateWidget,{set_state:function(e){var t,i;Sao.View.Form.LabelMixin._super.set_state.call(this,e),this.attributes.name&&e&&(t=e.model.fields[this.attributes.name]),void 0===this.attributes.string||this.attributes.string||(i="",t&&e&&(i=t.get_client(e)||""),this.label_el.text(i)),void 0===(i=e?e.expr_eval(this.attributes.states||{}):{}).readonly&&(i.readonly=!t),Sao.common.apply_label_attributes(this.label_el,t&&t.description.readonly||i.readonly,t&&t.description.required||i.required)}}),Sao.View.Form.Separator=Sao.class_(Sao.View.Form.LabelMixin,{init:function(e,t){Sao.View.Form.Separator._super.init.call(this,t),this.el=jQuery("<div/>",{class:"form-separator"}),this.label_el=jQuery("<label/>"),e&&this.label_el.text(e),this.el.append(this.label_el),this.el.append(jQuery("<hr/>"))}}),Sao.View.Form.Label=Sao.class_(Sao.View.Form.LabelMixin,{class_:"form-label",init:function(e,t){Sao.View.Form.Label._super.init.call(this,t),this.el=this.label_el=jQuery("<label/>",{text:e,class:this.class_})}}),Sao.View.Form.Notebook=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-notebook",init:function(e){Sao.View.Form.Notebook._super.init.call(this,e),this.el=jQuery("<div/>",{class:this.class_}),this.nav=jQuery("<ul/>",{class:"nav nav-tabs",role:"tablist"}).appendTo(this.el),this.panes=jQuery("<div/>",{class:"tab-content"}).appendTo(this.el),this.selected=!1},add:function(e,t,i){var n=jQuery("<div/>",{role:"tabpanel",class:"tab-pane"}).uniqueId(),o=n.attr("id"),i=Sao.common.ICONFACTORY.get_icon_img(i),o=jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{"aria-controls":o,role:"tab","data-toggle":"tab",href:"#"+o}).text(t).prepend(i)).appendTo(this.nav);return n.append(e).appendTo(this.panes),this.selected||(o.addClass("active"),n.addClass("active"),this.selected=!0),o},set_current_page:function(e=null){e=null===e?":visible:first":":eq("+e+"):visible";this.nav.find("li"+e+" a").tab("show")},get_n_pages:function(){return this.nav.find("li[role='presentation']").length},get_nth_page:function(e){return jQuery(this.panes.find("div[role='tabpanel']")[e])}}),Sao.View.Form.Page=Sao.class_(Sao.View.Form.StateWidget,{init:function(e,t){Sao.View.Form.Page._super.init.call(this,t),this.el=e},hide:function(){Sao.View.Form.Page._super.hide.call(this),this.el.hasClass("active")&&this.el.siblings(":visible").first().find("a").tab("show")}}),Sao.View.Form.Group=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-group_",init:function(e){Sao.View.Form.Group._super.init.call(this,e),this.el=jQuery("<fieldset/>",{class:this.class_}),e.string&&this.el.append(jQuery("<legend/>").text(e.string))},add:function(e){this.el.append(e.el)}}),Sao.View.Form.Expander=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-group-expandable",init:function(e){Sao.View.Form.Expander._super.init.call(this,e),this.el=jQuery("<div/>",{class:"panel panel-default "+this.class_});var t=jQuery("<div/>",{class:"panel-heading"}).appendTo(this.el),t=(t.uniqueId(),this.collapsible=jQuery("<div/>",{class:"panel-collapse collapse","aria-labelledby":t.attr("id")}).appendTo(this.el),this.collapsible.uniqueId(),this.body=jQuery("<div/>",{class:"panel-body"}).appendTo(this.collapsible),jQuery("<label/>",{class:"panel-title"}).appendTo(t)),t=jQuery("<a/>",{role:"button","data-toggle":"collapse",href:"#"+this.collapsible.attr("id"),"aria-controls":this.collapsible.attr("id"),"aria-expanded":"1"==e.expandable}).appendTo(t);e.string&&t.text(e.string),t.append(jQuery("<span/>",{class:"caret"}))},add:function(e){this.body.empty(),this.body.append(e.el)},set_expanded:function(e){e?this.collapsible.collapse("show"):this.collapsible.collapse("hide")}}),Sao.View.Form.Link=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-link",init:function(e){var t;Sao.View.Form.Link._super.init.call(this,e),this.el=jQuery("<button/>",{class:this.class_+" btn btn-link",name:e.name,type:"button"}),e.icon&&(t=jQuery("<img/>",{class:"icon"}).prependTo(this.el),Sao.common.ICONFACTORY.get_icon_url(e.icon).done(function(e){t.attr("src",e)})),this.label=jQuery("<div/>").appendTo(this.el),this._current=null},get action_id(){return parseInt(this.attributes.id,10)},set_state:function(e){if(Sao.View.Form.Link._super.set_state.call(this,e),"none"!=this.el.css("display")){var t={},i={},n={};if(e){if(e.id<0)return void this.hide();t={model:e.model.name,id:e.id,ids:[e.id]},i=e.get_context(),n={active_model:e.model.name,active_id:e.id,active_ids:[e.id]},this._current=e.id}else this._current=null;n.context=i,this.el.off("click"),this.el.click([t,i],this.clicked.bind(this));var o,s,a=Sao.rpc({method:"model.ir.action.get_action_value",params:[this.action_id,i]},Sao.Session.current_session,!1),r=(this.label.text(a.name),this.el.attr("title",a.name),new Sao.PYSON.Decoder(n)),l=r.decode(a.pyson_domain),c=(a.pyson_search_value&&(l=[l,r.decode(a.pyson_search_value)]),a.domains.filter(function(e){return e[2]}).map(function(e){var t=e[0],e=e[1];return[t,r.decode(e)]}));const d=[];return e&&e.links_counts[this.action_id]?(o=e.links_counts[this.action_id],this.set_label(a.name,c,o)):(o=c.length?c.map(function(){return 0}):[0],e&&(e.links_counts[this.action_id]=o),s=this._current,c.length?c.map(function(e,t){e=e[1],e=Sao.rpc({method:"model."+a.res_model+".search_count",params:[["AND",l,e],0,100,i]},Sao.Session.current_session).then(e=>{this._set_count(e,t,s,o,a.name,c)});d.push(e)},this):(t=Sao.rpc({method:"model."+a.res_model+".search_count",params:[l,0,100,i]},Sao.Session.current_session).then(e=>{this._set_count(e,0,s,o,a.name,c)}),d.push(t))),jQuery.when.apply(jQuery,d)}},_set_count:function(e,t,i,n,o,s){i==this._current&&(n[t]=e=99<e?"99+":e,this.set_label(o,s,n))},set_label:function(e,t,i){this.label.text(e),this.el.attr("accesskey",Sao.common.accesskey(e)),t.length?t.map(function(e,t){e=e[0];this.label.append(jQuery("<br/>")),this.label.append(e+" "),jQuery("<span/>",{class:"badge"}).text(i[t]).appendTo(this.label)},this):(this.label.append(" "),jQuery("<span/>",{class:"badge"}).text(i[0]).appendTo(this.label)),"hide"===this.attributes.empty&&(i.filter(function(e){return 0!=e}).length?this.el.show():this.el.hide())},clicked:function(e){Sao.Action.execute(this.action_id,e.data[0],e.data[1],!0)}}),Sao.View.Form.Image_=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-image_",init:function(e){switch(Sao.View.Form.Image_._super.init.call(this,e),this.el=jQuery("<div/>",{class:this.class_}),this.img=jQuery("<img/>",{class:"center-block",width:(e.size||48)+"px",height:(e.size||48)+"px"}).appendTo(this.el),e.border){case"rounded":this.img.addClass("img-rounded");break;case"circle":this.img.addClass("img-circle")}},set_state:function(e){var t;Sao.View.Form.Image_._super.set_state.call(this,e),e&&((t=this.attributes.name)in e.model.fields&&(t=e.model.fields[t].get(e)),"url"==this.attributes.type?t?(this.attributes.url_size&&((e=new URL(t,window.location)).searchParams.set(this.attributes.url_size,this.attributes.size||48),t=e.href),this.img.attr("src",t)):this.img.removeAttr("src"):Sao.common.ICONFACTORY.get_icon_url(t).done(e=>{e?this.img.attr("src",e):this.img.removeAttr("src")}))}}),Sao.View.Form.Widget=Sao.class_(Object,{expand:!1,init:function(e,t){this.view=e,this.attributes=t,this.el=null,this.position=0,this.visible=!0,this.labelled=null},display:function(){var e,t=this.field,i=this.record,n=this.attributes.readonly,o=this.attributes.invisible,s=this.attributes.required;t?(i=t.get_state_attrs(i),void 0===n&&void 0===(n=i.readonly)&&(n=!1),void 0===s&&void 0===(s=i.required)&&(s=!1),this.view.screen.attributes.readonly&&(n=!0),this.set_readonly(n),n?this.el.addClass("readonly"):this.el.removeClass("readonly"),e=this._required_el(),this.set_required(s),!n&&s?e.addClass("required"):e.removeClass("required"),e=i.invalid,i=this._invalid_el(),!n&&e?i.addClass("has-error"):i.removeClass("has-error"),void 0===o&&void 0===(o=t.get_state_attrs(this.record).invisible)&&(o=!1),this.set_invisible(o)):(void 0===o&&(o=!1),void 0===s&&(s=!1),this.set_readonly(n=void 0===n?!0:n),this.set_invisible(o),this.set_required(s))},_required_el:function(){return this.el},_invalid_el:function(){return this.el},get field_name(){return this.attributes.name},get model_name(){return this.view.screen.model_name},get model(){return this.view.screen.model},get record(){return this.view.record},get field(){var e=this.record;if(e)return e.model.fields[this.field_name]},focus_out:function(){this.field&&this.visible&&this.set_value()},get_value:function(){},set_value:function(){},set_readonly:function(e){this._readonly=e},set_required:function(e){},get modified(){return!1},send_modified:function(){window.setTimeout(()=>{var e=this.get_value();window.setTimeout(()=>{this.record&&this.get_value()==e&&this.modified&&this.view.screen.record_modified(!1)},300)})},set_invisible:function(e){this.visible=!e,e?this.el.hide():this.el.show()},focus:function(){this.el.focus()}}),Sao.View.Form.TranslateDialog=Sao.class_(Object,{class_:"form",init:function(e,t){var i=new Sao.Dialog(Sao.i18n.gettext("Translate"),this.class_,"md");this.languages=e,this.read(t,i),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.close(i)}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(this.write.bind(this,t,i)).appendTo(i.footer),i.content.submit(function(e){e.preventDefault(),i.footer.find("button.btn-primary").first().click()}),i.modal.modal("show"),i.modal.on("shown.bs.modal",function(){i.modal.find("input,select").filter(":visible").first().focus()}),i.modal.on("hide.bs.modal",function(){jQuery(this).remove()})},close:function(e){e.modal.modal("hide")},read:function(r,l){function c(e){return e[0][r.field_name]||""}l.content.addClass("form-horizontal"),this.languages.forEach(e=>{var t=jQuery("<div/>",{class:"form-group"}),i=r.translate_widget(),n=(i.attr("data-lang-id",e.id),jQuery("<button/>",{type:"button",class:"btn btn-default"}).text(Sao.i18n.gettext("Edit"))),o=(r._readonly&&n.attr("disabled",!0),jQuery("<span>",{class:"label"})),s=Sao.rpc({method:"model."+r.model.name+".read",params:[[r.record.id],[r.field_name],{language:e.code}]},r.model.session).then(c),a=Sao.rpc({method:"model."+r.model.name+".read",params:[[r.record.id],[r.field_name],{language:e.code,fuzzy_translation:!0}]},r.model.session).then(c);jQuery.when(s,a).done(function(e,t){r.translate_widget_set(i,t),r.translate_widget_set_readonly(i,!0),e!==t&&(o.addClass("label-warning"),o.text(Sao.i18n.gettext("Fuzzy")))}),n.click(function(){jQuery(this).toggleClass("active"),r.translate_widget_set_readonly(i,!jQuery(this).hasClass("active"))}),l.body.append(t),i.uniqueId(),t.append(jQuery("<label/>",{for:i.attr("id"),class:"col-sm-3 control-label"}).append(" "+e.name)),t.append(jQuery("<div/>",{class:"col-sm-9 input-group"}).append(i).append(jQuery("<span/>",{class:"input-group-addon"}).append(n).append(o)))})},write:function(e,t){for(const s of this.languages){var i,n,o=jQuery("[data-lang-id="+s.id+"]");o.attr("readonly")||(e.model.session.context.language,(i={}).language=s.code,i.fuzzy_translation=!1,(n={})[e.field_name]=e.translate_widget_get(o),o=[[e.record.id],n,i],n={method:"model."+e.model.name+".write",params:o},Sao.rpc(n,e.model.session,!1))}e.record.cancel(),e.view.display(),this.close(t)}}),Sao.View.Form.TranslateMixin={},Sao.View.Form.TranslateMixin.init=function(){this.translate||(this.translate=Sao.View.Form.TranslateMixin.translate.bind(this)),this.translate_dialog||(this.translate_dialog=Sao.View.Form.TranslateMixin.translate_dialog.bind(this)),this.translate_widget_set_readonly||(this.translate_widget_set_readonly=Sao.View.Form.TranslateMixin.translate_widget_set_readonly.bind(this)),this.translate_widget_set||(this.translate_widget_set=Sao.View.Form.TranslateMixin.translate_widget_set.bind(this)),this.translate_widget_get||(this.translate_widget_get=Sao.View.Form.TranslateMixin.translate_widget_get.bind(this))},Sao.View.Form.TranslateMixin.translate=function(){var t,e;this.record.id<0||this.record.modified?(e=Sao.i18n.gettext("You need to save the record before adding translations."),Sao.common.message.run(e)):(t=this.model.session,e={method:"model.ir.lang.search",params:[[["translatable","=",!0]]].concat({})},Sao.rpc(e,t).then(e=>{jQuery.isEmptyObject(e)?Sao.common.message.run(Sao.i18n.gettext("No other language available.")):(e={method:"model.ir.lang.read",params:[e,["code","name"]].concat({})},Sao.rpc(e,t).then(e=>{this.translate_dialog(e)}))}))},Sao.View.Form.TranslateMixin.translate_dialog=function(e){new Sao.View.Form.TranslateDialog(e,this)},Sao.View.Form.TranslateMixin.translate_widget_set_readonly=function(e,t){e.prop("readonly",t)},Sao.View.Form.TranslateMixin.translate_widget_set=function(e,t){e.val(t)},Sao.View.Form.TranslateMixin.translate_widget_get=function(e){return e.val()},Sao.View.Form.Char=Sao.class_(Sao.View.Form.Widget,{class_:"form-char",init:function(e,t){Sao.View.Form.Char._super.init.call(this,e,t),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_}),this.group=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el),this.input=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:t.name}).appendTo(this.group),jQuery.isEmptyObject(t.autocomplete)||(this.datalist=jQuery("<datalist/>").appendTo(this.el),this.datalist.uniqueId(),this.input.attr("list",this.datalist.attr("id")),this.input.attr("autocomplete","off")),this.el.change(this.focus_out.bind(this)),this.el.on("keydown",this.send_modified.bind(this)),t.size||this.group.css("width","100%"),this.attributes.translate&&Sao.common.ICONFACTORY.get_icon_img("tryton-translate").appendTo(jQuery("<div/>",{class:"icon-input icon-secondary","aria-label":Sao.i18n.gettext("Translate"),title:Sao.i18n.gettext("Translate")}).appendTo(this.group.addClass("input-icon input-icon-secondary"))).click(this.translate.bind(this))},get_client_value:function(){var e=this.field,t=this.record,i="";return i=e?e.get_client(t):i},display:function(){Sao.View.Form.Char._super.display.call(this);var e=this.record;if(this.datalist){this.datalist.empty();for(const n of e&&(this.field_name in e.autocompletion||e.do_autocomplete(this.field_name),e.autocompletion[this.field_name])||[])jQuery("<option/>",{value:n}).appendTo(this.datalist)}var t="",i="100%";e&&0<(t=e.expr_eval(this.attributes.size))&&(i=null),this.input.val(this.get_client_value()),this.input.attr("maxlength",t),this.input.attr("size",t),this.group.css("width",i)},get modified(){return!(!this.record||!this.field)&&this.get_client_value()!=this.get_value()},set_value:function(){this.field.set_client(this.record,this.input.val())},get_value:function(){return this.input.val()},set_readonly:function(e){Sao.View.Form.Char._super.set_readonly.call(this,e),this.input.prop("readonly",e)},focus:function(){this.input.focus()},translate_widget:function(){return jQuery("<input/>",{class:"form-control",readonly:"readonly",name:this.attributes.name})}}),Sao.View.Form.Password=Sao.class_(Sao.View.Form.Char,{class_:"form-password",init:function(e,t){Sao.View.Form.Password._super.init.call(this,e,t),this.input.prop("type","password"),this.button=jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button"}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group)),this._set_password_label(),this.button.click(this.toggle_visibility.bind(this))},toggle_visibility:function(){"password"==this.input.prop("type")?(this.input.prop("type","text"),this.input.attr("autocomplete","off")):(this.input.prop("type","password"),this.input.removeAttr("autocomplete")),this._set_password_label()},_set_password_label:function(){"password"==this.input.prop("type")?(this.button.text(Sao.i18n.gettext("Show")),this.button.attr("title",Sao.i18n.gettext("Show"))):(this.button.text(Sao.i18n.gettext("Hide")),this.button.attr("title",Sao.i18n.gettext("Hide")))}}),Sao.View.Form.Date=Sao.class_(Sao.View.Form.Widget,{class_:"form-date",_width:"10em",_input:"date",_input_format:"%Y-%m-%d",_format:Sao.common.format_date,_parse:Sao.common.parse_date,init:function(e,t){Sao.View.Form.Date._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_});var e=this.labelled=jQuery("<div/>",{class:"input-group input-group-sm input-icon input-icon-secondary"}).appendTo(this.el),n=(this.date=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:t.name}).appendTo(e),this.date.uniqueId(),this.date.on("keydown",this.send_modified.bind(this)),this.input=jQuery("<input/>",{type:this._input,role:"button",tabindex:-1}),this.input.click(()=>{var e=this.get_value(),e=this._format(this._input_format,e);this.input.val(e)}),this.input.change(()=>{var e=this.input.val();e&&(e=this._parse(this._input_format,e),e=this._format(this.get_format(),e),this.date.val(e).change(),~navigator.userAgent.indexOf("Firefox")||this.date.focus()),this.send_modified()}),this.input[0].type==this._input&&(this.icon=jQuery("<div/>",{class:"icon-input icon-secondary","aria-label":Sao.i18n.gettext("Open the calendar"),title:Sao.i18n.gettext("Open the calendar"),tabindex:-1}).appendTo(e),this.input.appendTo(this.icon),Sao.common.ICONFACTORY.get_icon_img("tryton-date").appendTo(this.icon)),this.date.css("max-width",this._width),this.date.change(this.focus_out.bind(this)),new Mousetrap(this.date[0]));n.bind("enter",(e,t)=>{this.date.prop("readonly")||this.focus_out()}),n.bind("=",(e,t)=>{this.date.prop("readonly")||(e.preventDefault(),this.date.val(this._format(this.get_format(),moment())).change())}),Sao.common.DATE_OPERATORS.forEach(i=>{n.bind(i[0],(e,t)=>{this.date.prop("readonly")||(e.preventDefault(),(e=this.get_value()||Sao.DateTime()).add(i[1]),this.date.val(this._format(this.get_format(),e)).change())})})},get_format:function(){return this.field&&this.record?this.field.date_format(this.record):Sao.common.date_format(this.view.screen.context.date_format)},get_value:function(){return this._parse(this.get_format(),this.date.val())},display:function(){var e,t=this.record,i=this.field;Sao.View.Form.Date._super.display.call(this),t&&(e=i.get_client(t)),this.date.val(this._format(this.get_format(),e))},focus:function(){this.date.focus()},get modified(){var e;return!(!this.record||!this.field)&&(e=this.cast(this.field.get_client(this.record)),JSON.stringify(e)!=JSON.stringify(this.get_value()))},set_value:function(){this.field.set_client(this.record,this.get_value())},set_readonly:function(e){Sao.View.Form.Date._super.set_readonly.call(this,e),this.el.find("input").prop("readonly",e),this.icon&&(e?this.icon.hide():this.icon.show())},cast:function(e){return e=e&&e.isDateTime?e.todate():e}}),Sao.View.Form.DateTime=Sao.class_(Sao.View.Form.Date,{class_:"form-datetime",_width:"20em",_input:"datetime-local",_input_format:"%Y-%m-%dT%H:%M:%S",_format:Sao.common.format_datetime,_parse:Sao.common.parse_datetime,get_format:function(){return this.field&&this.record?this.field.date_format(this.record)+" "+this.field.time_format(this.record):Sao.common.date_format(this.view.screen.context.date_format)+" %X"},cast:function(e){return e}}),Sao.View.Form.Time=Sao.class_(Sao.View.Form.Date,{class_:"form-time",_width:"10em",_input:"time",_input_format:"%H:%M:%S",_format:Sao.common.format_time,_parse:Sao.common.parse_time,init:function(e,t){Sao.View.Form.Time._super.init.call(this,e,t),~navigator.userAgent.indexOf("Firefox")&&this.input.parent().hide()},get_format:function(){return this.field&&this.record?this.field.time_format(this.record):"%X"},cast:function(e){return e=e&&e.isDateTime?e.totime():e}}),Sao.View.Form.TimeDelta=Sao.class_(Sao.View.Form.Widget,{class_:"form-timedelta",init:function(e,t){Sao.View.Form.TimeDelta._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_}),this.input=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:t.name}).appendTo(this.el),this.el.change(this.focus_out.bind(this)),this.el.on("keydown",this.send_modified.bind(this))},display:function(){Sao.View.Form.TimeDelta._super.display.call(this);var e=this.record;e?(e=e.field_get_client(this.field_name),this.input.val(e||"")):this.input.val("")},focus:function(){this.input.focus()},get modified(){var e;return!(!this.record||!this.field)&&(e=this.input.val(),this.field.get_client(this.record)!=e)},set_value:function(){this.field.set_client(this.record,this.input.val())},set_readonly:function(e){Sao.View.Form.TimeDelta._super.set_readonly.call(this,e),this.input.prop("readonly",e)}});function i(e,t){var i=e.attr("id"),n=e.attr("aria-labelledby"),o=t.attr("id"),s=t.attr("aria-labelledby");e.attr("id",o),e.attr("aria-labelledby",s),t.attr("id",i),t.attr("aria-labelledby",n)}function n(e){var t=e.clone().prependTo(e.parent());return t.attr("type","text"),e.attr("type","number"),e.attr("step",1),e.attr("lang",Sao.i18n.getlang()),e.hide().on("focusout",function(){e[0].checkValidity()&&(i(e,t),e.hide(),t.show())}),t.on("focusin",function(){e.prop("readonly")||(i(e,t),t.hide(),e.show(),window.setTimeout(function(){e.focus()}))}),t}Sao.View.Form.Integer=Sao.class_(Sao.View.Form.Char,{class_:"form-integer",init:function(e,t){Sao.View.Form.Integer._super.init.call(this,e,t),this.input_text=this.labelled=n(this.input),this.attributes.symbol&&(this.symbol_start=jQuery("<span/>",{class:"input-group-addon symbol symbol-start"}).prependTo(this.group),this.symbol_end=jQuery("<span/>",{class:"input-group-addon symbol symbol-end"}).appendTo(this.group)),this.group.css("width",""),this.factor=Number(t.factor||1),this.grouping=Boolean(Number(t.grouping||1))},get modified(){var e;return!(!this.record||!this.field)&&(e=this.get_client_value(),JSON.stringify(this.field.convert(e))!=JSON.stringify(this.field.convert(this.get_value())))},set_value:function(){this.field.set_client(this.record,this.get_value(),void 0,this.factor)},get_value:function(){return this.input.val()},get_client_value:function(){var e="",t=this.field;return t&&(null!==(e=t.get(this.record))?(e*=this.factor,(t=t.digits(this.record,this.factor))&&(e=e.toFixed(t[1]))):e=""),e},get width(){return this.attributes.width||8},display:function(){function e(e,t){t?(e.text(t),e.show()):(e.text(""),e.hide())}Sao.View.Form.Integer._super.display.call(this);var t=this.field,i=this.record,n="";null!==this.width&&(this.input_text.css("width",this.width+"ch"),this.input.css("width",this.width+5+"ch")),t&&(n=t.get_client(i,this.factor,this.grouping)),t&&this.attributes.symbol&&(i=(t=t.get_symbol(i,this.attributes.symbol))[0],t[1]<.5?(e(this.symbol_start,i),e(this.symbol_end,"")):(e(this.symbol_start,""),e(this.symbol_end,i))),this.input_text.val(n),this.input_text.attr("maxlength",this.input.attr("maxlength")),this.input_text.attr("size",this.input.attr("size"))},set_readonly:function(e){Sao.View.Form.Integer._super.set_readonly.call(this,e),this.input_text.prop("readonly",e)},focus:function(){(this.input.prop("readonly")?this.input_text:(this.input_text.hide(),this.input.show())).focus()}}),Sao.View.Form.Float=Sao.class_(Sao.View.Form.Integer,{class_:"form-float",get digits(){var e=this.record,t=this.field;if(e&&t)return t.digits(e,this.factor)},get width(){var e=this.digits;return e?e.reduce(function(e,t){return e+t}):this.attributes.width||18},display:function(){var e=this.record,t=(this.field,"any");e&&(e=this.digits)&&(t=Math.pow(10,-e[1]).toFixed(e[1])),this.input.attr("step",t),Sao.View.Form.Float._super.display.call(this)}}),Sao.View.Form.Selection=Sao.class_(Sao.View.Form.Widget,{class_:"form-selection",init:function(e,t){Sao.View.Form.Selection._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_}),this.select=this.labelled=jQuery("<select/>",{class:"form-control input-sm mousetrap",name:t.name}),this.el.append(this.select),this.select.change(this.focus_out.bind(this)),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e,this.set_selection.bind(this))},update_selection:function(e,t,i){Sao.common.selection_mixin.update_selection.call(this,e,t,(e,t)=>{this.set_selection(e,t),i&&i(t)})},set_selection:function(e,t){var i=this.select;i.empty();for(const n of e)i.append(jQuery("<option/>",{value:JSON.stringify(n[0]),text:n[1],title:t[n[0]]}))},display_update_selection:function(){var s=this.record,a=this.field;this.update_selection(s,a,t=>{if(a){var e,i=a.get(s),n=!1;for(const o of this.selection)if(o[0]===i){n=!0;break}n?e=jQuery.when():(e=Sao.common.selection_mixin.get_inactive_selection.call(this,i)).done(e=>{this.select.append(jQuery("<option/>",{value:JSON.stringify(e[0]),text:e[1],disabled:!0}))}),e.done(()=>{this.select.val(JSON.stringify(i));var e=t[i]||null;this.attributes.help&&(e=e&&this.attributes.help+"\n"+e),this.select.attr("title",e)})}else this.select.val("")})},display:function(){Sao.View.Form.Selection._super.display.call(this),this.display_update_selection()},focus:function(){this.select.focus()},get_value:function(){return JSON.parse(this.select.val())},get modified(){return!(!this.record||!this.field)&&this.field.get(this.record)!=this.get_value()},set_value:function(){var e=this.get_value();this.field.set_client(this.record,e)},set_readonly:function(e){Sao.View.Form.Selection._super.set_readonly.call(this,e),this.select.prop("disabled",e)}}),Sao.View.Form.Boolean=Sao.class_(Sao.View.Form.Widget,{class_:"form-boolean",init:function(e,t){Sao.View.Form.Boolean._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_}),this.input=this.labelled=jQuery("<input/>",{type:"checkbox",class:"form-control input-sm mousetrap",name:t.name}).appendTo(this.el),this.input.change(this.focus_out.bind(this)),this.input.click(function(){return!jQuery(this).prop("readonly")})},display:function(){Sao.View.Form.Boolean._super.display.call(this);var e=this.record;e?this.input.prop("checked",e.field_get(this.field_name)):this.input.prop("checked",!1)},focus:function(){this.input.focus()},set_value:function(){var e=this.input.prop("checked");this.field.set_client(this.record,e)},set_readonly:function(e){Sao.View.Form.Boolean._super.set_readonly.call(this,e),this.input.prop("readonly",e)}}),Sao.View.Form.Text=Sao.class_(Sao.View.Form.Widget,{class_:"form-text",expand:!0,init:function(e,t){Sao.View.Form.Text._super.init.call(this,e,t),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_}),this.group=jQuery("<div/>",{class:"input-group"}).appendTo(this.el),this.input=this.labelled=jQuery("<textarea/>",{class:"form-control input-sm mousetrap",name:t.name}).appendTo(this.group),this.input.change(this.focus_out.bind(this)),this.input.on("keydown",this.send_modified.bind(this)),this.attributes.translate&&((e=jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button","aria-label":Sao.i18n.gettext("Translate"),title:Sao.i18n.gettext("Translate")}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group))).append(Sao.common.ICONFACTORY.get_icon_img("tryton-translate")),e.click(this.translate.bind(this)))},display:function(){Sao.View.Form.Text._super.display.call(this);var e,t=this.record;t?(e=t.field_get_client(this.field_name),this.input.val(e),this.attributes.spell&&(this.input.attr("lang",Sao.i18n.BC47(t.expr_eval(this.attributes.spell))),this.input.attr("spellcheck","true"))):this.input.val("")},focus:function(){this.input.focus()},get modified(){return!(!this.record||!this.field)&&this._normalize_newline(this.field.get_client(this.record))!=this.get_value()},get_value:function(){return this._normalize_newline(this.input.val()||"")},set_value:function(){var e=this.get_value(),t=this.field.get_client(this.record);e==this._normalize_newline(t)&&(e=t),this.field.set_client(this.record,e)},_normalize_newline:function(e){return e.replace(/\r\n/g,"\n").replace(/\r/g,"\n")},set_readonly:function(e){Sao.View.Form.Text._super.set_readonly.call(this,e),this.input.prop("readonly",e)},translate_widget:function(){var e=jQuery("<textarea/>",{class:"form-control",readonly:"readonly"});return e.css("min-height",this.el.height()),e}}),Sao.View.Form.RichText=Sao.class_(Sao.View.Form.Widget,{class_:"form-richtext",expand:!0,init:function(e,t){Sao.View.Form.RichText._super.init.call(this,e,t),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"}),parseInt(t.toolbar||"1",10)&&(this.toolbar=Sao.common.richtext_toolbar().appendTo(jQuery("<div/>",{class:"panel-heading"}).appendTo(this.el))),this.group=jQuery("<div/>",{class:"input-group"}).appendTo(jQuery("<div/>",{class:"panel-body"}).appendTo(this.el)),this.input=this.labelled=jQuery("<div/>",{class:"richtext mousetrap",contenteditable:!0}).appendTo(this.group),this.group.focusout(this.focus_out.bind(this)),this.attributes.translate&&((e=jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button","aria-label":Sao.i18n.gettext("Translate"),title:Sao.i18n.gettext("Translate")}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group))).append(Sao.common.ICONFACTORY.get_icon_img("tryton-translate")),e.click(this.translate.bind(this)))},focus_out:function(){window.setTimeout(()=>{0===this.el.find(":focus").length&&Sao.View.Form.RichText._super.focus_out.call(this)},0)},display:function(){Sao.View.Form.RichText._super.display.call(this);var e="",t=this.record;t&&(e=t.field_get_client(this.field_name),this.attributes.spell)&&(this.input.attr("lang",Sao.i18n.BC47(t.expr_eval(this.attributes.spell))),this.input.attr("spellcheck","true")),this.input.html(Sao.HtmlSanitizer.sanitize(e||""))},focus:function(){this.input.focus()},get_value:function(){return this._normalize_markup(this.input.html())},set_value:function(){var e=this.get_value(),t=this.field.get_client(this.record);e==this._normalize_markup(t)&&(e=t),this.field.set_client(this.record,e)},_normalize_markup:function(e){return Sao.common.richtext_normalize(Sao.HtmlSanitizer.sanitize(e||""))},get modified(){return!(!this.record||!this.field)&&this._normalize_markup(this.field.get_client(this.record))!=this.get_value()},set_readonly:function(e){Sao.View.Form.RichText._super.set_readonly.call(this,e),this.input.prop("contenteditable",!e),this.toolbar&&this.toolbar.find("button,input,select").prop("disabled",e)},translate_widget:function(){var e=jQuery("<div/>",{class:this.class_+" panel panel-default"});parseInt(this.attributes.toolbar||"1",10)&&Sao.common.richtext_toolbar().appendTo(jQuery("<div/>",{class:"panel-heading"}).appendTo(e)),jQuery("<div/>",{class:"richtext mousetrap",contenteditable:!0}).appendTo(jQuery("<div/>",{class:"panel-body"}).appendTo(e));return e},translate_widget_set_readonly:function(e,t){Sao.View.Form.TranslateMixin.translate_widget_set_readonly.call(this,e,t),e.find("button,input,select").prop("disabled",t),e.find("div[contenteditable]").prop("contenteditable",!t)},translate_widget_set:function(e,t){e.find("div[contenteditable]").html(Sao.HtmlSanitizer.sanitize(t||""))},translate_widget_get:function(e){return this._normalize_markup(e.find("div[contenteditable]").html())}}),Sao.View.Form.Many2One=Sao.class_(Sao.View.Form.Widget,{class_:"form-many2one",init:function(e,t){Sao.View.Form.Many2One._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_});e=jQuery("<div/>",{class:"input-group input-group-sm input-icon"}).appendTo(this.el);this.entry=this.labelled=jQuery("<input/>",{type:"input",class:"form-control input-sm mousetrap",name:t.name}).appendTo(e),this.but_primary=jQuery("<img/>",{class:"icon"}).appendTo(jQuery("<div/>",{class:"icon-input icon-primary"}).appendTo(e)),this.but_secondary=jQuery("<img/>",{class:"icon"}).appendTo(jQuery("<div/>",{class:"icon-input icon-secondary"}).appendTo(e)),this.but_primary.click("primary",this.edit.bind(this)),this.but_secondary.click("secondary",this.edit.bind(this)),this.entry.on("keydown",this.send_modified.bind(this)),this.entry.on("keydown",this.key_press.bind(this)),t.completion&&"1"!=t.completion||(this.wid_completion=Sao.common.get_completion(e,this._update_completion.bind(this),this._completion_match_selected.bind(this)),this.entry.completion=this.wid_completion),this.el.change(this.focus_out.bind(this)),this._readonly=!1},get_screen:function(e){var t=this.field.get_domain(this.record),e=e?this.field.get_search_context(this.record):this.field.get_context(this.record),i=(this.attributes.view_ids||"").split(","),n=(jQuery.isEmptyObject(i)||i.shift(),this.get_model()),o=jQuery.extend([],this.view.screen.breadcrumb);return o.push(this.attributes.string||Sao.common.MODELNAME.get(n)),new Sao.Screen(this.get_model(),{context:e,domain:t,mode:["form"],view_ids:i,views_preload:this.attributes.views,readonly:this._readonly,exclude_field:this.attributes.relation_field,breadcrumb:o})},set_text:function(e){jQuery.isEmptyObject(e)&&(e=""),this.entry.val(e)},get_text:function(){var e=this.record;return e?s(e.field_get_client(this.field_name)):""},focus_out:function(){(this.attributes.completion&&"1"!=this.attributes.completion||!this.el.find(".dropdown").hasClass("open"))&&Sao.View.Form.Many2One._super.focus_out.call(this)},set_value:function(){var e=this.record,t=this.field;this.get_text()!=this.entry.val()&&(t.set_client(e,this.value_from_id(null,"")),this.entry.val(""))},display:function(){var e,t,i,n=this.record,o=this.field;Sao.View.Form.Many2One._super.display.call(this),this._set_button_sensitive(),this._set_completion(),n?(this.set_text(o.get_client(n)),o=o.get(n),n=this.has_target(o)?(e="tryton-open",t=Sao.i18n.gettext("Open the record"),i="tryton-clear",Sao.i18n.gettext("Clear the field")):(e=null,t="",i="tryton-search",Sao.i18n.gettext("Search a record")),this.entry.prop("readonly")&&(i=null),[[e,t,this.but_primary,"primary"],[i,n,this.but_secondary,"secondary"]].forEach(function(e){var t=e[0],i=e[1],n=e[2],o=n.parent(),e="input-icon-"+e[3];t?(o.show(),o.parent().addClass(e),Sao.common.ICONFACTORY.get_icon_url(t).then(function(e){n.attr("src",e)})):(o.hide(),o.parent().removeClass(e)),n.attr("aria-label",i),n.attr("title",i)})):this.entry.val("")},focus:function(){this.entry.focus()},set_readonly:function(e){Sao.View.Form.Many2One._super.set_readonly.call(this,e),this._readonly=e,this._set_button_sensitive()},_set_button_sensitive:function(){this.entry.prop("readonly",this._readonly),this.but_primary.prop("disabled",!this.read_access),this.but_secondary.prop("disabled",this._readonly)},get_access:function(e){var t=this.get_model();return!t||Sao.common.MODELACCESS.get(t)[e]},get read_access(){return this.get_access("read")},get create_access(){var e=this.attributes.create;return void 0===e?e=!0:"string"==typeof e&&(e=Boolean(parseInt(e,10))),e&&this.get_access("create")},get modified(){var e;return!(!this.record||!this.field)&&(e=this.entry.val(),this.get_text()!=e)},id_from_value:function(e){return e},value_from_id:function(e,t=""){return[e,t]},get_model:function(){return this.attributes.relation},has_target:function(e=null){return null!==e},edit:function(t){var e=this.get_model();if(e&&Sao.common.MODELACCESS.get(e).read){var i,n,o=this.record,s=o.field_get(this.field_name);if(t&&"secondary"==t.data&&!this._readonly&&this.has_target(s))this.record.field_set_client(this.field_name,this.value_from_id(null,"")),this.entry.val(""),this.focus();else if(this.has_target(s)){var a=this.id_from_value(o.field_get(this.field_name));if(t&&(t.ctrlKey||t.metaKey))return(s={}).model=this.get_model(),s.res_id=a,s.mode=["form"],s.name=this.attributes.string,s.context=this.field.get_context(this.record),void Sao.Tab.create(s);var r=this.get_screen();let e=e=>{e&&r.current_record.rec_name().done(e=>{e=this.value_from_id(r.current_record.id,e);this.record.field_set_client(this.field_name,e,!0)})};void r.switch_view().done(()=>{r.load([a]),r.current_record=r.group.get(a),new Sao.Window.Form(r,e,{save_current:!0})})}else e&&(t=this.field.get_domain(o),s=this.field.get_search_context(o),o=this.field.get_search_order(o),i=this.entry.val(),n=new Sao.common.DomainParser,new Sao.Window.Search(e,e=>{jQuery.isEmptyObject(e)||(e=this.value_from_id(e[0][0],e[0][1]),this.record.field_set_client(this.field_name,e,!0))},{sel_multi:!1,context:s,domain:t,order:o,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:this.create_access,search_filter:n.quote(i),title:this.attributes.string,exclude_field:this.attributes.relation_field}))}},new_:function(e=null){var t=this.get_model();if(t&&Sao.common.MODELACCESS.get(t).create){var i=this.get_screen(!0);(e=e?jQuery.extend({},e):{}).rec_name=this.entry.val();const n=e=>{e&&i.current_record.rec_name().done(e=>{e=this.value_from_id(i.current_record.id,e);this.record.field_set_client(this.field_name,e)})};i.switch_view().done(()=>{new Sao.Window.Form(i,n,{new_:!0,save_current:!0,defaults:e})})}},key_press:function(e){var t=!this.entry.prop("readonly"),i=[Sao.common.TAB_KEYCODE],n=[Sao.common.BACKSPACE_KEYCODE,Sao.common.DELETE_KEYCODE];this.wid_completion||i.push(Sao.common.RETURN_KEYCODE),e.which==Sao.common.F3_KEYCODE&&t&&this.create_access?(e.preventDefault(),this.new_()):e.which==Sao.common.F2_KEYCODE&&this.read_access?(e.preventDefault(),this.edit()):~i.indexOf(e.which)&&t?(this.attributes.completion&&"1"!=this.attributes.completion||!this.el.find(".dropdown").hasClass("open"))&&this.activate():this.has_target(this.record.field_get(this.field_name))&&t&&(this.get_text()==this.entry.val()&&!~n.indexOf(e.which)||(this.entry.val(""),this.record.field_set_client(this.field_name,this.value_from_id(null,""))))},activate:function(){var e,t,i,n,o,s=this.get_model();s&&Sao.common.MODELACCESS.get(s).read&&(e=(n=this.record).field_get(this.field_name),new Sao.Model(s),s)&&!this.has_target(e)&&(e=this.entry.val(),this._readonly||!e&&!this.field.get_state_attrs(this.record).required||(t=this.field.get_domain(n),i=this.field.get_search_context(n),n=this.field.get_search_order(n),o=new Sao.common.DomainParser,new Sao.Window.Search(s,e=>{jQuery.isEmptyObject(e)?this.entry.val(""):(e=this.value_from_id(e[0][0],e[0][1]),this.record.field_set_client(this.field_name,e,!0))},{sel_multi:!1,context:i,domain:t,order:n,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:this.create_access,search_filter:o.quote(e),title:this.attributes.string,exclude_field:this.attributes.relation_field})))},_set_completion:function(){this.wid_completion&&this.wid_completion.set_actions(this._completion_action_activated.bind(this),this.read_access,this.create_access)},_update_completion:function(e){var t=this.record;if(!t)return jQuery.when();var i=this.field,n=i.get(t);if(this.has_target(n)){n=this.id_from_value(n);if(void 0!==n&&0<=n)return jQuery.when()}n=this.get_model();return Sao.common.update_completion(this.entry,t,i,n)},_completion_match_selected:function(e){null!==e.id?this.record.field_set_client(this.field_name,this.value_from_id(e.id,e.rec_name),!0):this.new_(e.defaults)},_completion_action_activated:function(e){"search"==e?this.edit():"create"==e&&this.new_()}}),Sao.View.Form.One2One=Sao.class_(Sao.View.Form.Many2One,{class_:"form-one2one"}),Sao.View.Form.Reference=Sao.class_(Sao.View.Form.Many2One,{class_:"form-reference",init:function(e,t){Sao.View.Form.Reference._super.init.call(this,e,t),this.el.addClass("form-inline"),this.select=jQuery("<select/>",{class:"form-control input-sm","aria-label":t.string,title:t.string}),this.el.prepend(this.select),this.select.change(this.select_changed.bind(this)),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e,this.set_selection.bind(this))},update_selection:function(e,t,i){Sao.common.selection_mixin.update_selection.call(this,e,t,(e,t)=>{this.set_selection(e,t),i&&i()})},set_selection:function(e,t){var i=this.select;i.empty();for(const n of e)i.append(jQuery("<option/>",{value:n[0],text:n[1],title:t[n[0]]}))},get modified(){var e,t,i;return!(!this.record||!this.field)&&(i=t="",(e=this.field.get_client(this.record))&&(t=e[0],i=s(e[1])),t!=this.get_model()||i!=this.entry.val())},id_from_value:function(e){return parseInt(e.split(",")[1],10)},value_from_id:function(e,t){return t=t||"",[this.get_model(),[e,t]]},get_text:function(){var e=this.record;return e?s(e.field_get_client(this.field_name)[1]):""},get_model:function(){return this.select.val()},has_target:function(e){var t;return null!==e&&(t=e.split(",")[0],e=e.split(",")[1],(jQuery.isEmptyObject(e)||(e=parseInt(e,10),isNaN(e)))&&(e=null),t==this.get_model())&&0<=e},_set_button_sensitive:function(){Sao.View.Form.Reference._super._set_button_sensitive.call(this),this.select.prop("disabled",this.entry.prop("readonly"))},select_changed:function(){this.entry.val("");var e=this.get_model(),e=e?[e,[-1,""]]:["",""];this.record.field_set_client(this.field_name,e)},set_value:function(){var e,t,i,n=this.record,o=this.field;this.get_model()?(i=(t=o.get_client(n,this.field_name))instanceof Array?(e=t[0],s(t[1])):e="",e==this.get_model()&&i==this.entry.val()||(o.set_client(n,null),this.entry.val(""))):(t=this.entry.val(),jQuery.isEmptyObject(t)?o.set_client(n,null):o.set_client(n,["",t]))},set_text:function(e){var t;e=e?(t=e[0],e[1]):t=null,Sao.View.Form.Reference._super.set_text.call(this,e),t?this.select.val(t):this.select.val("")},display:function(){this.update_selection(this.record,this.field,()=>{Sao.View.Form.Reference._super.display.call(this)})},set_readonly:function(e){Sao.View.Form.Reference._super.set_readonly.call(this,e),this.select.prop("disabled",e)}}),Sao.View.Form.One2Many=Sao.class_(Sao.View.Form.Widget,{class_:"form-one2many",expand:!0,init:function(e,t){Sao.View.Form.One2Many._super.init.call(this,e,t),this._readonly=!0,this._required=!1,this._position=0,this._length=0,this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"}),this.menu=jQuery("<div/>",{class:this.class_+"-menu panel-heading"}),this.el.append(this.menu),this.title=jQuery("<label/>",{class:this.class_+"-string",text:t.string}),this.menu.append(this.title),this.title.uniqueId(),this.el.uniqueId(),this.el.attr("aria-labelledby",this.title.attr("id")),this.title.attr("for",this.el.attr("id"));function i(i){return function(e){var t=jQuery(e.target);t.prop("disabled",!0),(i(e)||jQuery.when()).always(function(){t.prop("disabled",!1)})}}var e=jQuery("<div/>",{class:this.class_+"-toolbar"}),e=(this.menu.append(e),jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(e)),n=jQuery("<div/>",{class:"input-group-btn"}).appendTo(e),e=(this.but_switch=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Switch"),title:Sao.i18n.gettext("Switch")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-switch")).appendTo(n),this.but_switch.click(i(this.switch_.bind(this))),this.but_previous=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Previous"),title:Sao.i18n.gettext("Previous")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-back")).appendTo(n),this.but_previous.click(i(this.previous.bind(this))),this.label=jQuery("<span/>",{class:"badge"}).text("_ / 0").appendTo(jQuery("<span/>",{class:"btn hidden-xs"}).appendTo(n)),this.but_next=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Next"),title:Sao.i18n.gettext("Next")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-forward")).appendTo(n),this.but_next.click(i(this.next.bind(this))),t.add_remove&&(this.wid_text=jQuery("<input/>",{type:"text",class:"form-control input-sm",name:t.name}).appendTo(e),t.completion&&"1"!=t.completion||(this.wid_completion=Sao.common.get_completion(this.wid_text,this._update_completion.bind(this),this._completion_match_selected.bind(this),this._completion_action_activated.bind(this),this.read_access,this.create_access),this.wid_text.completion=this.wid_completion),n=jQuery("<div/>",{class:"input-group-btn"}).appendTo(e),this.but_add=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Add"),title:Sao.i18n.gettext("Add")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).appendTo(n),this.but_add.click(i(this.add.bind(this))),this.but_remove=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Remove"),title:Sao.i18n.gettext("Remove")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).appendTo(n),this.but_remove.click(i(this.remove.bind(this)))),this.but_new=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("New"),title:Sao.i18n.gettext("New")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-create")).appendTo(n),this.but_new.click(i(()=>this.new_())),this.but_open=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Open"),title:Sao.i18n.gettext("Open")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-open")).appendTo(n),this.but_open.click(i(this.open.bind(this))),this.but_del=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Delete"),title:Sao.i18n.gettext("Delete")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-delete")).appendTo(n),this.but_del.click(i(this.delete_.bind(this))),this.but_undel=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Undelete"),title:Sao.i18n.gettext("Undelete")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-undo")).appendTo(n),this.but_undel.click(i(this.undelete.bind(this))),this.content=jQuery("<div/>",{class:this.class_+"-content panel-body"}),this.el.append(this.content),(t.mode||"tree,form").split(",")),n=t.relation,o=jQuery.extend([],this.view.screen.breadcrumb);o.push(t.string||Sao.common.MODELNAME.get(n)),this.screen=new Sao.Screen(n,{mode:e,view_ids:(t.view_ids||"").split(","),views_preload:t.views||{},order:t.order,row_activate:this.activate.bind(this),exclude_field:t.relation_field||null,limit:null,context:this.view.screen.context,pre_validate:t.pre_validate,breadcrumb:o}),this.screen.pre_validate=1==t.pre_validate,this.screen.windows.push(this),this.prm=this.screen.switch_view().done(()=>{this.content.append(this.screen.screen_container.el)}),t.add_remove&&this.wid_text.on("keydown",this.key_press.bind(this))},get_access:function(e){var t=this.attributes.relation;return!t||Sao.common.MODELACCESS.get(t)[e]},get read_access(){return this.get_access("read")},get create_access(){var e=this.attributes.create;return void 0===e?e=!0:"string"==typeof e&&(e=Boolean(parseInt(e,10))),e&&this.get_access("create")},get write_access(){return this.get_access("write")},get delete_access(){var e=this.attributes.delete;return void 0===e?e=!0:"string"==typeof e&&(e=Boolean(parseInt(e,10))),e&&this.get_access("delete")},get modified(){return this.screen.current_view.modified},set_readonly:function(e){Sao.View.Form.One2Many._super.set_readonly.call(this,e),this.prm.done(()=>this._set_button_sensitive()),this._set_label_state()},set_required:function(e){this._required=e,this._set_label_state()},_set_label_state:function(){Sao.common.apply_label_attributes(this.title,this._readonly,this._required)},_set_button_sensitive:function(){var e=this.record,t=this.field,e=(t=e&&t?(i=e.expr_eval(this.attributes.size),n=t.get_eval(e).length,null!=i&&i<=n&&0<=i):(n=null,!1),this.screen.deletable),i=this.screen.current_view.view_type,n=1<this.screen.number_of_views;this.but_switch.prop("disabled",!((this._position||"form"==i)&&n)),this.but_new.prop("disabled",this._readonly||!this.create_access||t),this.but_del.prop("disabled",this._readonly||!this.delete_access||!this._position||!e),this.but_undel.prop("disabled",this._readonly||t||!this._position),this.but_open.prop("disabled",!this._position||!this.read_access),this.but_next.prop("disabled",0<this.position&&this._position>=this._length),this.but_previous.prop("disabled",this._position<=1),this.attributes.add_remove&&(this.but_add.prop("disabled",this._readonly||t||!this.write_access||!this.read_access),this.wid_text.prop("disabled",this.but_add.prop("disabled")),this.but_remove.prop("disabled",this._readonly||!this.position||!this.write_access||!this.read_access))},_sequence:function(){for(const t of this.screen.views)if("tree"==t.view_type){var e=t.attributes.sequence;if(e)return e}},display:function(){Sao.View.Form.One2Many._super.display.call(this),this.prm.done(()=>{this._set_button_sensitive();var e,t,i=this.record,n=this.field;n?((e=i.field_get_client(this.field_name))!=this.screen.group&&(this.screen.set_group(e),"form"==this.screen.current_view.view_type)&&this.screen.group.length&&(this.screen.current_record=this.screen.group[0]),e=[],t=null,i&&(e=n.get_domain(i),t=i.expr_eval(this.attributes.size)),!this._readonly&&this.create_access||(t=null==t?this.screen.group.length:Math.min(t,this.screen.group.length)),Sao.common.compare(this.screen.domain,e)||(this.screen.domain=e),this.screen.size_limit=t,this.screen.display(),void 0!==this.attributes.height&&this.screen.current_view.el.find(".treeview,.list-form").first().css("min-height",this.attributes.height+"px").css("max-height",this.attributes.height+"px")):(this.screen.new_group(),this.screen.current_record=null,this.screen.group.parent=null,this.screen.display())})},focus:function(){this.attributes.add_remove&&this.wid_text.focus()},activate:function(e){this.edit()},add:function(e){var t,i,n,s,o,a;this.write_access&&this.read_access&&(this.view.set_value(),i=this.field.get_domain(this.record),t=this.field.get_search_context(this.record),i=["OR",i=[i,this.record.expr_eval(this.attributes.add_remove)],["id","in",this.field.get_removed_ids(this.record)]],n=this.wid_text.val(),s=this._sequence(),o=new Sao.common.DomainParser,a=this.field.get_search_order(this.record),new Sao.Window.Search(this.attributes.relation,e=>{var t=jQuery.when();if(!jQuery.isEmptyObject(e)){for(var i=[],n=0,o=e.length;n<o;n++)i.push(e[n][0]);this.screen.group.load(i,!0),t=this.screen.display(),s&&this.screen.group.set_sequence(s,this.screen.new_position)}t.done(()=>{this.screen.set_cursor()}),this.wid_text.val("")},{sel_multi:!0,context:t,domain:i,order:a,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:!this.but_new.prop("disabled"),search_filter:o.quote(n),title:this.attributes.string,exclude_field:this.attributes.relation_field}))},remove:function(e){var t=!this.screen.readonly;this.write_access&&this.read_access&&t&&this.screen.remove(!1,!0,!1)},new_:function(e=null){Sao.common.MODELACCESS.get(this.screen.model_name).create&&(this.attributes.add_remove&&((e=e?jQuery.extend({},e):{}).rec_name=this.wid_text.val()),this.validate().done(()=>{this.attributes.product?this.new_product(e):this.new_single(e)}))},new_single:function(e=null){var t,i,n=this._sequence(),o=()=>{n&&this.screen.group.set_sequence(n,this.screen.new_position)};this.screen.current_view.creatable?(this.screen.new_().then(o),this.screen.current_view.el.prop("disabled",!1)):(i=(t=this.record).expr_eval(this.attributes.size)||-1,i-=this.field.get_eval(t).length,new Sao.Window.Form(this.screen,o,{new_:!0,defaults:e,many:i}))},new_product:function(e=null){var l=this.attributes.product.split(","),c={},d=this.screen;d.new_(!1).then(r=>{r.default_get(e).then(o=>{r.set_default(o);const s=()=>{if(jQuery.isEmptyObject(l))return a();var t=d.model.fields[l.pop()],e=t.description.relation,i=(e||s(),t.get_domain(r)),n=t.get_search_context(r),o=t.get_search_order(r);new Sao.Window.Search(e,function(e){jQuery.isEmptyObject(e)||(c[t.name]=e),s()},{sel_multi:!0,context:n,domain:i,order:o,search_filter:"",title:this.attributes.string})},a=()=>{var t,e;d.group.remove(r,!0),!jQuery.isEmptyObject(c)&&(e=(t=Object.keys(c)).map(function(e){return c[e]}),Sao.common.product(e).forEach(function(n){d.new_(!1).then(function(e){var i=jQuery.extend({},o);t.forEach(function(e,t){i[e]=n[t][0],i[e+".rec_name"]=n[t][1]}),e.set_default(i)})}),e=this._sequence())&&d.group.set_sequence(e,d.new_position)};s()})})},open:function(e){return this.edit()},delete_:function(e){Sao.common.MODELACCESS.get(this.screen.model_name).delete&&this.screen.deletable&&this.screen.remove(!1,!1,!1)},undelete:function(e){this.screen.unremove()},previous:function(e){return this.validate().then(()=>this.screen.display_previous())},next:function(e){return this.validate().then(()=>this.screen.display_next())},switch_:function(e){return this.screen.switch_view()},edit:function(){if(Sao.common.MODELACCESS.get(this.screen.model_name).read)return this.validate().then(()=>{this.screen.current_record&&new Sao.Window.Form(this.screen,function(){})})},key_press:function(e){var t;e.which==Sao.common.F3_KEYCODE?(e.preventDefault(),this.new_()):e.which==Sao.common.F2_KEYCODE&&(e.preventDefault(),this.add(e)),this.attributes.add_remove&&(t=[Sao.common.TAB_KEYCODE],this.wid_completion||t.push(Sao.common.RETURN_KEYCODE),~t.indexOf(e.which))&&this.wid_text.val()&&this.add(e)},record_message:function(e,t){this._position=e,this._length=t;var i="_",e=(e&&(i=" "+e,1<(e=this.screen.selected_records.length))&&(i+="#"+e),i+" / "+Sao.common.humanize(t));this.label.text(e).attr("title",e),this.prm.done(()=>this._set_button_sensitive())},validate:function(){var e,t=jQuery.Deferred(),i=(this.view.set_value(),this.screen.current_record);return i?(e=this.screen.current_view.get_fields(),i.validate(e).then(e=>{if(e)return this.screen.pre_validate?i.pre_validate().then(t.resolve,t.reject):void t.resolve();this.screen.display(!0),t.reject()})):t.resolve(),t},set_value:function(){this.screen.save_tree_state(),this.screen.modified()&&this.view.screen.record_modified(!1)},_update_completion:function(e){var t,i,n;return this.record?(t=this.attributes.relation,i=[i=this.field.get_domain(this.record),this.record.expr_eval(this.attributes.add_remove)],n=this.field.get_removed_ids(this.record),Sao.common.update_completion(this.wid_text,this.record,this.field,t,i=["OR",i,["id","in",n]])):jQuery.when()},_completion_match_selected:function(e){null!==e.id?(this.screen.group.load([e.id],!0),this.wid_text.val("")):this.new_(e.defaults)},_completion_action_activated:function(e){"search"==e?this.add():"create"==e&&this.new_()}}),Sao.View.Form.Many2Many=Sao.class_(Sao.View.Form.Widget,{class_:"form-many2many",expand:!0,init:function(e,t){Sao.View.Form.Many2Many._super.init.call(this,e,t),this._readonly=!0,this._required=!1,this._position=0,this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"}),this.menu=jQuery("<div/>",{class:this.class_+"-menu panel-heading"}),this.el.append(this.menu),this.title=jQuery("<label/>",{class:this.class_+"-string",text:t.string}),this.menu.append(this.title),this.title.uniqueId(),this.el.uniqueId(),this.el.attr("aria-labelledby",this.title.attr("id")),this.title.attr("for",this.el.attr("id"));var e=jQuery("<div/>",{class:this.class_+"-toolbar"}),e=(this.menu.append(e),jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(e)),e=(this.entry=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:t.name}).appendTo(e),this.entry.on("keydown",this.key_press.bind(this)),t.completion&&"1"!=t.completion||(this.wid_completion=Sao.common.get_completion(e,this._update_completion.bind(this),this._completion_match_selected.bind(this),this._completion_action_activated.bind(this),this.read_access,this.create_access),this.entry.completion=this.wid_completion),jQuery("<div/>",{class:"input-group-btn"}).appendTo(e)),e=(this.but_add=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Add"),title:Sao.i18n.gettext("Add")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).appendTo(e),this.but_add.click(this.add.bind(this)),this.label=jQuery("<span/>",{class:"badge"}).text("_ / 0").appendTo(jQuery("<span/>",{class:"btn hidden-xs"}).appendTo(e)),this.but_remove=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",tabindex:-1,"aria-label":Sao.i18n.gettext("Remove"),title:Sao.i18n.gettext("Remove")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).appendTo(e),this.but_remove.click(this.remove.bind(this)),this.content=jQuery("<div/>",{class:this.class_+"-content panel-body"}),this.el.append(this.content),t.relation),i=jQuery.extend([],this.view.screen.breadcrumb);i.push(t.string||Sao.common.MODELNAME.get(e)),this.screen=new Sao.Screen(t.relation,{mode:["tree"],view_ids:(t.view_ids||"").split(","),views_preload:t.views||{},order:t.order,row_activate:this.activate.bind(this),readonly:!0,limit:null,context:this.view.screen.context,breadcrumb:i}),this.screen.windows.push(this),this.prm=this.screen.switch_view("tree").done(()=>{this.content.append(this.screen.screen_container.el)})},get_access:function(e){var t=this.attributes.relation;return!t||Sao.common.MODELACCESS.get(t)[e]},get read_access(){return this.get_access("read")},get create_access(){var e=this.attributes.create;return void 0===e?e=!0:"string"==typeof e&&(e=Boolean(parseInt(e,10))),e&&this.get_access("create")},set_readonly:function(e){Sao.View.Form.Many2Many._super.set_readonly.call(this,e),this._set_button_sensitive(),this._set_label_state()},set_required:function(e){this._required=e,this._set_label_state()},_set_label_state:function(){Sao.common.apply_label_attributes(this.title,this._readonly,this._required)},_set_button_sensitive:function(){var e,t=!1,i=this.record,n=this.field;i&&n&&(e=i.expr_eval(this.attributes.size),n=n.get_eval(i).length,t=null!=e&&e<=n&&0<=e),this.entry.prop("disabled",this._readonly),this.but_add.prop("disabled",this._readonly||t),this.but_remove.prop("disabled",this._readonly||0===this._position)},record_message:function(e,t){var i="_",e=((this._position=e)&&(i=" "+e,1<(e=this.screen.selected_records.length))&&(i+="#"+e),i+" / "+Sao.common.humanize(t));this.label.text(e).attr("title",e),this._set_button_sensitive()},display:function(){Sao.View.Form.Many2Many._super.display.call(this),this.prm.done(()=>{var e=this.record;this.field?((e=e.field_get_client(this.field_name))!=this.screen.group&&this.screen.set_group(e),this.screen.display(),void 0!==this.attributes.height&&this.screen.current_view.el.find(".treeview,.list-form").first().css("min-height",this.attributes.height+"px").css("max-height",this.attributes.height+"px")):(this.screen.new_group(),this.screen.current_record=null,this.screen.group.parent=null,this.screen.display())})},focus:function(){this.entry.focus()},activate:function(){this.edit()},add:function(){var e=this.field.get_domain(this.record),t=this.record.expr_eval(this.attributes.add_remove),t=(jQuery.isEmptyObject(t)||(e=[e,t]),this.field.get_search_context(this.record)),i=this.field.get_search_order(this.record),n=this.entry.val(),o=new Sao.common.DomainParser;new Sao.Window.Search(this.attributes.relation,e=>{if(!jQuery.isEmptyObject(e)){for(var t=[],i=0,n=e.length;i<n;i++)t.push(e[i][0]);this.screen.group.load(t,!0),this.screen.display()}this.entry.val("")},{sel_multi:!0,context:t,domain:e,order:i,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:this.create_access,search_filter:o.quote(n),title:this.attributes.string})},remove:function(){this.screen.remove(!1,!0,!1)},key_press:function(e){var t=[Sao.common.TAB_KEYCODE];this.wid_completion||t.push(Sao.common.RETURN_KEYCODE),e.which==Sao.common.F3_KEYCODE?(e.preventDefault(),this.new_()):e.which==Sao.common.F2_KEYCODE?(e.preventDefault(),this.add()):~t.indexOf(e.which)&&this.entry.val()&&this.add()},_get_screen_form:function(){var e=this.field.get_domain(this.record),t=this.record.expr_eval(this.attributes.add_remove),t=(jQuery.isEmptyObject(t)||(e=[e,t]),this.field.get_context(this.record)),i=(this.attributes.view_ids||"").split(","),n=(jQuery.isEmptyObject(i)||i.shift(),this.attributes.relation),o=jQuery.extend([],this.view.screen.breadcrumb);return o.push(this.attributes.string||Sao.common.MODELNAME.get(n)),new Sao.Screen(n,{domain:e,view_ids:i,mode:["form"],views_preload:this.attributes.views,context:t,breadcrumb:o})},edit:function(){if(!jQuery.isEmptyObject(this.screen.current_record)){var t=this._get_screen_form();const e=e=>{e&&t.current_record.save().done(()=>{var e="id"in this.screen.current_record.modified_fields;this.screen.current_record.cancel(),e&&(this.screen.current_record.modified_fields.id=!0)})};t.switch_view().done(()=>{t.load([this.screen.current_record.id]),t.current_record=t.group.get(this.screen.current_record.id),new Sao.Window.Form(t,e)})}},new_:function(e=null){var t=this._get_screen_form();(e=e?jQuery.extend({},e):{}).rec_name=this.entry.val();const i=e=>{e&&(e=t.current_record,this.screen.group.load([e.id],!0)),this.entry.val("")};t.switch_view().done(()=>{new Sao.Window.Form(t,i,{new_:!0,save_current:!0,defaults:e})})},_update_completion:function(e){var t,i,n;return this.record?(t=this.attributes.relation,i=this.field.get_domain(this.record),n=this.record.expr_eval(this.attributes.add_remove),jQuery.isEmptyObject(n)||(i=[i,n]),Sao.common.update_completion(this.entry,this.record,this.field,t,i)):jQuery.when()},_completion_match_selected:function(e){null!==e.id?(this.screen.group.load([e.id],!0),this.entry.val("")):this.new_(e.defaults)},_completion_action_activated:function(e){"search"==e?this.add():"create"==e&&this.new_()}}),Sao.View.Form.BinaryMixin=Sao.class_(Sao.View.Form.Widget,{init:function(e,t){Sao.View.Form.BinaryMixin._super.init.call(this,e,t),this.filename=t.filename||null},toolbar:function(e){e=jQuery("<div/>",{class:e,role:"group"});return this.but_save_as=jQuery("<button/>",{class:"btn btn-default",type:"button","aria-label":Sao.i18n.gettext("Save As"),title:Sao.i18n.gettext("Save As...")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-download")).appendTo(e),this.but_save_as.click(this.save_as.bind(this)),this.input_select=jQuery("<input/>",{type:"file"}).change(this.select.bind(this)),this.but_select=jQuery("<div/>",{class:"btn btn-default input-file",type:"button","aria-label":Sao.i18n.gettext("Select"),title:Sao.i18n.gettext("Select...")}).append(this.input_select).append(Sao.common.ICONFACTORY.get_icon_img("tryton-search")).appendTo(e),this.but_clear=jQuery("<button/>",{class:"btn btn-default",type:"button","aria-label":Sao.i18n.gettext("Clear"),title:Sao.i18n.gettext("Clear")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-clear")).appendTo(e),this.but_clear.click(this.clear.bind(this)),e},get filename_field(){if(this.filename){var e=this.record;if(e)return e.model.fields[this.filename]}},update_buttons:function(e){e?(this.but_save_as.show(),this.but_select.hide(),this.but_clear.show()):(this.but_save_as.hide(),this.but_select.show(),this.but_clear.hide())},select:function(){var i=this.record,n=this.field,o=this.filename_field;Sao.common.get_input_data(this.input_select,function(e,t){n.set_client(i,e),o&&o.set_client(i,t)},!n.get_size)},open:function(){this.save_as()},save_as:function(){var e=this.field,t=this.record,e=e.get_data?e.get_data(t):jQuery.when(e.get(t));e.done(e=>{var t,i=this.filename_field;i&&(t=i.get(this.record)),Sao.common.download_file(e,t)})},clear:function(){this.input_select.val(null);var e=this.filename_field;e&&e.set_client(this.record,null),this.field.set_client(this.record,null)}}),Sao.View.Form.Binary=Sao.class_(Sao.View.Form.BinaryMixin,{class_:"form-binary",blob_url:"",init:function(e,t){Sao.View.Form.Binary._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_});e=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el);this.size=jQuery("<input/>",{type:"input",class:"form-control input-sm",readonly:!0,name:t.name}).appendTo(e),this.filename&&t.filename_visible&&(this.text=jQuery("<input/>",{type:"input",class:"form-control input-sm"}).prependTo(e),this.text.change(this.focus_out.bind(this)),this.text.on("keydown",this.key_press.bind(this)),this.text.css("width","50%"),this.size.css("width","50%"),this.but_open=jQuery("<button/>",{class:"btn btn-default",type:"button","aria-label":Sao.i18n.gettext("Open..."),title:Sao.i18n.gettext("Open...")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-open")).appendTo(jQuery("<span/>",{class:"input-group-btn"}).prependTo(e)),this.but_open.click(this.open.bind(this))),this.toolbar("input-group-btn").appendTo(e)},display:function(){Sao.View.Form.Binary._super.display.call(this);var e=this.record,t=this.field;t?(t=t.get_size?t.get_size(e):t.get(e).length,this.size.val(Sao.common.humanize(t,"B")),this.text&&(this.text.val(this.filename_field.get(e)||""),t?this.but_open.parent().show():this.but_open.parent().hide()),this.update_buttons(Boolean(t))):(this.text&&this.text.val(""),this.size.val(""),this.but_save_as.hide())},key_press:function(e){var t=!this.text.prop("readonly");e.which==Sao.common.F3_KEYCODE&&t?(e.preventDefault(),this.new_()):e.which==Sao.common.F2_KEYCODE&&(e.preventDefault(),this.open())},set_value:function(){this.text&&this.filename_field.set_client(this.record,this.text.val()||"")},set_readonly:function(e){Sao.View.Form.Binary._super.set_readonly.call(this,e),this.but_select.toggleClass("disabled",e),this.input_select.toggle(!e),this.but_clear.prop("disabled",e),this.text&&this.text.prop("readonly",e)}}),Sao.View.Form.MultiSelection=Sao.class_(Sao.View.Form.Selection,{class_:"form-multiselection",expand:!0,init:function(e,t){this.nullable_widget=!1,Sao.View.Form.MultiSelection._super.init.call(this,e,t),this.select.prop("multiple",!0)},set_selection:function(e,t){Sao.View.Form.MultiSelection._super.set_selection.call(this,e,t);var i=this.attributes.help;i&&this.select.children().each(function(){var e=jQuery(this),t=e.attr("title");t&&e.attr("title",i+"\n"+t)})},get modified(){var e,t;return!(!this.record||!this.field||(e=new Set(this.field.get_eval(this.record)),t=new Set(this.get_value()),Sao.common.compare(t,e)))},display_update_selection:function(){var t=this.record,i=this.field;this.update_selection(t,i,()=>{var e=this.attributes.yexpand;(e=void 0===e?this.expand:e)||this.select.prop("size",this.select.children().length),i&&(e=(e=i.get_eval(t)).map(function(e){return JSON.stringify(e)}),this.select.val(e))})},get_value:function(){var e=this.select.val();return e?e.map(function(e){return JSON.parse(e)}):[]}}),Sao.View.Form.Image=Sao.class_(Sao.View.Form.BinaryMixin,{class_:"form-image",init:function(e,t){switch(Sao.View.Form.Image._super.init.call(this,e,t),this.height=parseInt(t.height||100,10),this.width=parseInt(t.width||300,10),this.el=jQuery("<div/>",{class:this.class_+" thumbnail"}),this.image=jQuery("<img/>",{class:"center-block"}).appendTo(this.el),this.image.css("max-height",this.height),this.image.css("max-width",this.width),this.image.css("height","auto"),this.image.css("width","auto"),t.border){case"rounded":this.image.addClass("img-rounded");break;case"circle":this.image.addClass("img-circle")}e=this.toolbar("btn-group");t.readonly||jQuery("<div/>",{class:"text-center caption"}).append(e).appendTo(this.el)},set_readonly:function(e){Sao.View.Form.Image._super.set_readonly.call(this,e),this.but_select.prop("disabled",e),this.but_clear.prop("disabled",e)},clear:function(){Sao.View.Form.Image._super.clear.call(this),this.update_img()},update_img:function(){var e,t=this.record;(e=!(e=t?t.field_get_client(this.field_name):e)||e>Sao.config.image_max_size?jQuery.when(null):t.model.fields[this.field_name].get_data(t)).done(e=>{t===this.record&&(this.image.attr("src",Sao.common.image_url(e)),this.update_buttons(Boolean(e)))})},display:function(){Sao.View.Form.Image._super.display.call(this),this.update_img()}}),Sao.View.Form.Document=Sao.class_(Sao.View.Form.BinaryMixin,{class_:"form-document",expand:!0,init:function(e,t){Sao.View.Form.Document._super.init.call(this,e,t),this._blob_url=null,this.el=jQuery("<div/>",{class:this.class_}),this.object=jQuery("<object/>",{class:"center-block"}).appendTo(this.el),t.height&&this.object.css("height",parseInt(t.height,10)),t.width&&this.object.css("width",parseInt(t.width,10))},display:function(){Sao.View.Form.Document._super.display.call(this);var n,o=this.record,e=o?o.model.fields[this.field_name].get_data(o):jQuery.when(null),t=this.filename_field;t&&(n=t.get_client(o)),e.done(e=>{var t,i;o===this.record&&(window.URL.revokeObjectURL(this.object.attr("data")),t=e?("application/octet-binary"==(i=Sao.common.guess_mimetype(n))&&(i=null),e=new Blob([e],{type:i}),window.URL.createObjectURL(e)):null,(i=this.object.clone()).get(0).onload=function(){this.onload=null,window.URL.revokeObjectURL(t)},i.attr("data",t),this.object.replaceWith(i),this.object=i)})}}),Sao.View.Form.URL=Sao.class_(Sao.View.Form.Char,{class_:"form-url",_type:"url",init:function(e,t){Sao.View.Form.URL._super.init.call(this,e,t),this.input.attr("type",this._type),this.button=this.labelled=jQuery("<a/>",{class:"btn btn-default",target:"_blank",rel:"noreferrer noopener"}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group)),this.icon=jQuery("<img/>").appendTo(this.button),this.set_icon()},display:function(){Sao.View.Form.URL._super.display.call(this);var e="",t=this.record;this.field;t&&(e=t.field_get_client(this.field_name)),this.set_url(e),t&this.attributes.icon&&(t=(e=this.attributes.icon)in t.model.fields?t.field_get_client(e):e,this.set_icon(t))},set_icon:function(e){Sao.common.ICONFACTORY.get_icon_url(e=e||"tryton-public").done(e=>{this.icon.attr("src",e)})},set_url:function(e){this.button.attr("href",e),this.button.toggle(Boolean(e))},set_invisible:function(e){Sao.View.Form.URL._super.set_invisible.call(this,e),e?this.input.attr("type",""):this.input.attr("type",this._type)}}),Sao.View.Form.Email=Sao.class_(Sao.View.Form.URL,{class_:"form-email",_type:"email",set_url:function(e){Sao.View.Form.Email._super.set_url.call(this,"mailto:"+e)}}),Sao.View.Form.CallTo=Sao.class_(Sao.View.Form.URL,{class_:"form-callto",set_url:function(e){Sao.View.Form.CallTo._super.set_url.call(this,"callto:"+e)}}),Sao.View.Form.SIP=Sao.class_(Sao.View.Form.URL,{class_:"form-sip",set_url:function(e){Sao.View.Form.SIP._super.set_url.call(this,"sip:"+e)}}),Sao.View.Form.HTML=Sao.class_(Sao.View.Form.Widget,{class_:"form-html",init:function(e,t){Sao.View.Form.HTML._super.init.call(this,e,t),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_}),this.button=jQuery("<a/>",{class:"btn btn-lnk",target:"_blank",rel:"noreferrer noopener"}).text(t.string).appendTo(this.el),t.translate&&((e=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Translate"),title:Sao.i18n.gettext("Translate")}).appendTo(this.el)).append(Sao.common.ICONFACTORY.get_icon_img("tryton-translate")),e.click(this.translate.bind(this)))},uri:function(e){var t=this.record,i=!t||t.id<0?"":(i="/"+t.model.session.database+"/ir/html/"+t.model.name+"/"+t.id+"/"+this.field_name,(i+="?language="+encodeURIComponent(e||Sao.i18n.getlang()))+"&title="+encodeURIComponent(Sao.config.title));return i},display:function(){Sao.View.Form.HTML._super.display.call(this),this.button.attr("href",this.uri())},set_readonly:function(e){Sao.View.Form.HTML._super.set_readonly.call(this,e),this.el.find("button").prop("disabled",e),e?this.el.find("a").hide():this.el.find("a").show()},translate_dialog:function(e){var t={};for(const i of e)t[i.name]=i.code;Sao.common.selection(Sao.i18n.gettext("Choose a language"),t).done(e=>{window.open(this.uri(e),"_blank","noreferrer,noopener")})}}),Sao.View.Form.ProgressBar=Sao.class_(Sao.View.Form.Widget,{class_:"form-char",init:function(e,t){Sao.View.Form.ProgressBar._super.init.call(this,e,t),this.el=jQuery("<div/>",{class:this.class_+" progress"}),this.progressbar=jQuery("<div/>",{class:"progress-bar",role:"progressbar","aria-valuemin":0,"aria-valuemax":100}).appendTo(this.el),this.progressbar.css("min-width: 2em")},display:function(){Sao.View.Form.ProgressBar._super.display.call(this);var e,t=this.record,i=this.field,n=i?(e=i.get(t),(n=i.get_client(t,100))&&Sao.i18n.gettext("%1%",n)):(e=0,"");this.progressbar.attr("aria-valuenow",100*e),this.progressbar.css("width",100*e+"%"),this.progressbar.text(n)}}),Sao.View.Form.Dict=Sao.class_(Sao.View.Form.Widget,{class_:"form-dict",expand:!0,init:function(e,t){Sao.View.Form.Dict._super.init.call(this,e,t),this.schema_model=t.schema_model,this.fields={},this.rows={},this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"});e=jQuery("<div/>",{class:this.class_+"-heading panel-heading"}).appendTo(this.el),e=jQuery("<label/>",{class:this.class_+"-string",text:t.string}).appendTo(e),e.uniqueId(),this.el.uniqueId(),this.el.attr("aria-labelledby",e.attr("id")),e.attr("for",this.el.attr("id")),e=jQuery("<div/>",{class:this.class_+"-body panel-body form-horizontal"}).appendTo(this.el),this.container=jQuery("<div/>",{class:this.class_+"-container"}).appendTo(e),e=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(jQuery("<div>",{class:"col-sm-10 col-sm-offset-2"}).appendTo(jQuery("<div/>",{class:"form-group"}).appendTo(e)));this.wid_text=jQuery("<input/>",{type:"text",class:"form-control input-sm",placeholder:Sao.i18n.gettext("Search"),name:t.name}).appendTo(e),t.completion&&"1"!=t.completion||(this.wid_completion=Sao.common.get_completion(e,this._update_completion.bind(this),this._completion_match_selected.bind(this)),this.wid_text.completion=this.wid_completion),this.but_add=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Add"),title:Sao.i18n.gettext("Add")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).appendTo(jQuery("<div/>",{class:"input-group-btn"}).appendTo(e)),this.but_add.click(this.add.bind(this)),this._readonly=!1,this._record_id=null},_required_el:function(){return this.wid_text},_invalid_el:function(){return this.wid_text},add:function(){var e=this.field.get_context(this.record),t=this.wid_text.val(),i=this.field.get_domain(this.record),n=new Sao.common.DomainParser;new Sao.Window.Search(this.schema_model,e=>{jQuery.isEmptyObject(e)||(e=e.map(function(e){return e[0]}),this.add_new_keys(e)),this.wid_text.val("")},{sel_multi:!0,context:e,domain:i,new_:!1,search_filter:n.quote(t),title:this.attributes.string})},add_new_keys:function(e){this.field.add_new_keys(e,this.record).then(e=>{this.send_modified();var t=!1;for(const i of e)i in this.fields||(this.add_line(i),t)||(this.fields[i].input.focus(),t=!0)})},remove:function(e,t=!0){delete this.fields[e],this.rows[e].remove(),delete this.rows[e],t&&(this.send_modified(),this.set_value(this.record,this.field))},set_value:function(){this.field.set_client(this.record,this.get_value())},get_value:function(){var e,t={};for(e in this.fields){var i=this.fields[e];t[e]=i.get_value()}return t},get modified(){if(this.record&&this.field){var e,t=this.field.get_client(this.record);for(e in this.fields)if(this.fields[e].modified(t))return!0}return!1},set_readonly:function(e){for(var t in Sao.View.Form.Dict._super.set_readonly.call(this,e),this._set_button_sensitive(),this.fields)this.fields[t].set_readonly(e);this.wid_text.prop("disabled",e)},_set_button_sensitive:function(){var e,t=this.attributes.create,i=(void 0===t?t=1:"string"==typeof t&&(t=Boolean(parseInt(t,10))),this.attributes.delete);for(e in void 0===i?i=1:"string"==typeof i&&(i=Boolean(parseInt(i,10))),this.but_add.prop("disabled",this._readonly||!t),this.fields)this.fields[e].button.prop("disabled",this._readonly||!i)},add_line:function(e){var t,i,n=this.field.keys[e],n=(this.fields[e]=t=new(this.get_entries(n.type))(e,this),this.rows[e]=i=jQuery("<div/>",{class:"form-group"}),n.string+Sao.i18n.gettext(":")),n=jQuery("<label/>",{text:n}).appendTo(jQuery("<div/>",{class:"dict-label col-sm-2 control-label"}).appendTo(i));t.el.addClass("col-sm-10").appendTo(i),n.uniqueId(),t.labelled.uniqueId(),t.labelled.attr("aria-labelledby",n.attr("id")),n.attr("for",t.labelled.attr("id")),t.button.click(()=>{this.remove(e,!0)}),i.appendTo(this.container)},display:function(){Sao.View.Form.Dict._super.display.call(this);var e=this.record,c=this.field;if(c){var t,i=e?e.id:null;if(i!=this._record_id){for(t in this.fields)this.remove(t,!1);this._record_id=i}var d=c.get_client(e),i=Object.keys(d).filter(e=>!this.fields[e]),i=jQuery.isEmptyObject(i)?jQuery.when():c.add_keys(i,e);i.then(()=>{for(var e=Object.keys(d).filter(function(e){return c.keys[e]}).sort(function(e,t){e=c.keys[e].sequence,t=c.keys[t].sequence;return e<t?-1:t<e?1:0}),t=new Sao.PYSON.Decoder,i=new Sao.common.DomainInversion,n=0,o=e.length;n<o;n++){var s=e[n],a=d[s],r=(this.fields[s]||this.add_line(s),this.fields[s]),a=(r.set_value(a),r.set_readonly(this._readonly),t.decode(c.keys[s].domain||"null"));null!==a&&(i.eval_domain(a,d)?r.el.removeClass("has-error"):r.el.addClass("has-error"))}var l=Object.keys(this.fields).filter(function(e){return!(e in d)});for(n=0,o=l.length;n<o;n++)s=l[n],this.remove(s,!1)}),this._set_button_sensitive()}},_update_completion:function(e){return!this.wid_text.prop("disabled")&&this.record?Sao.common.update_completion(this.wid_text,this.record,this.field,this.schema_model):jQuery.when()},_completion_match_selected:function(e){this.add_new_keys([e.id]),this.wid_text.val("")},get_entries:function(e){switch(e){case"char":return Sao.View.Form.Dict.Entry;case"boolean":return Sao.View.Form.Dict.Boolean;case"selection":return Sao.View.Form.Dict.Selection;case"multiselection":return Sao.View.Form.Dict.MultiSelection;case"integer":return Sao.View.Form.Dict.Integer;case"float":return Sao.View.Form.Dict.Float;case"numeric":return Sao.View.Form.Dict.Numeric;case"date":return Sao.View.Form.Dict.Date;case"datetime":return Sao.View.Form.Dict.DateTime}}}),Sao.View.Form.Dict.Entry=Sao.class_(Object,{init:function(e,t){this.name=e,this.definition=t.field.keys[e],this.parent_widget=t,this.create_widget(),this.definition.help&&this.el.attr("title",this.definition.help)},create_widget:function(){this.el=jQuery("<div/>",{class:this.class_});var e=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el);this.input=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap",name:this.name}).appendTo(e),this.button=jQuery("<button/>",{class:"btn btn-default",type:"button","arial-label":Sao.i18n.gettext("Remove"),title:Sao.i18n.gettext("Remove")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).appendTo(jQuery("<div/>",{class:"input-group-btn"}).appendTo(e)),this.el.on("keydown",this.parent_widget.send_modified.bind(this.parent_widget)),this.el.change(this.parent_widget.focus_out.bind(this.parent_widget))},modified:function(e){return JSON.stringify(this.get_value())!=JSON.stringify(e[this.name])},get_value:function(){return this.input.val()},set_value:function(e){this.input.val(e||"")},set_readonly:function(e){this._readonly=e,this.input.prop("readonly",e)}}),Sao.View.Form.Dict.Char=Sao.class_(Sao.View.Form.Dict.Entry,{class_:"dict-char",modified:function(e){return JSON.stringify(this.get_value())!=JSON.stringify(e[this.name]||"")}}),Sao.View.Form.Dict.Boolean=Sao.class_(Sao.View.Form.Dict.Entry,{class_:"dict-boolean",create_widget:function(){Sao.View.Form.Dict.Boolean._super.create_widget.call(this),this.input.attr("type","checkbox"),this.input.change(this.parent_widget.focus_out.bind(this.parent_widget))},get_value:function(){return this.input.prop("checked")},set_readonly:function(e){this._readonly=e,this.input.prop("disabled",e)},set_value:function(e){this.input.prop("checked",Boolean(e))}}),Sao.View.Form.Dict.SelectionEntry=Sao.class_(Sao.View.Form.Dict.Entry,{create_widget:function(){Sao.View.Form.Dict.SelectionEntry._super.create_widget.call(this);var e=jQuery("<select/>",{class:"form-control input-sm mousetrap",name:this.name}),t=(e.change(this.parent_widget.focus_out.bind(this.parent_widget)),this.input.replaceWith(e),this.input=this.labelled=e,jQuery.extend([],this.definition.selection));void 0!==this.definition.sort&&!this.definition.sort||t.sort(function(e,t){return e[1].localeCompare(t[1])});for(const i of t)e.append(jQuery("<option/>",{value:JSON.stringify(i[0]),text:i[1],title:this.definition.help_selection[i[0]]}))},set_readonly:function(e){this._readonly=e,this.input.prop("disabled",e)}}),Sao.View.Form.Dict.Selection=Sao.class_(Sao.View.Form.Dict.SelectionEntry,{class_:"dict-selection",create_widget:function(){Sao.View.Form.Dict.Selection._super.create_widget.call(this),this.input.prepend(jQuery("<option/>",{value:JSON.stringify(null),text:""}))},get_value:function(){return JSON.parse(this.input.val())},set_value:function(e){this.input.val(JSON.stringify(e));e=this.definition.help_selection[e]||null;this.definition.help&&(e=e&&this.definition.help+"\n"+e),this.input.attr("title",e)}}),Sao.View.Form.Dict.MultiSelection=Sao.class_(Sao.View.Form.Dict.SelectionEntry,{class_:"dict-multiselection",create_widget:function(){Sao.View.Form.Dict.MultiSelection._super.create_widget.call(this),this.input.prop("multiple",!0);var i=this.definition.help;i&&this.input.children().each(function(){var e=jQuery(this),t=e.attr("title");t&&e.attr("title",i+"\n"+t)})},get_value:function(){return this.input.val().map(function(e){return JSON.parse(e)})},set_value:function(e){e=e&&e.map(function(e){return JSON.stringify(e)}),this.input.val(e)}}),Sao.View.Form.Dict.Integer=Sao.class_(Sao.View.Form.Dict.Entry,{class_:"dict-integer",create_widget:function(){Sao.View.Form.Dict.Integer._super.create_widget.call(this),this.input_text=this.labelled=n(this.input)},get_value:function(){var e=parseInt(this.input.val(),10);return isNaN(e)?null:e},set_value:function(e,t){"number"==typeof e||e instanceof Sao.Decimal?(this.input.val(e),this.input_text.val(e.toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),t))):(this.input.val(""),this.input_text.val(""))},set_readonly:function(e){Sao.View.Form.Dict.Integer._super.set_readonly.call(this,e),this.input_text.prop("readonly",e)}}),Sao.View.Form.Dict.Float=Sao.class_(Sao.View.Form.Dict.Integer,{class_:"dict-float",get digits(){var e=this.parent_widget.record;if(e){e=e.expr_eval(this.definition.digits);if(e&&e.every(function(e){return null!==e}))return e}},get_value:function(){var e=this.input.val();return!e&&0!==e||(e=Number(e),isNaN(e))?null:e},set_value:function(e){var t="any",i={},n=this.digits;n&&(t=Math.pow(10,-n[1]).toFixed(n[1]),i.minimumFractionDigits=n[1],i.maximumFractionDigits=n[1]),this.input.attr("step",t),Sao.View.Form.Dict.Float._super.set_value.call(this,e,i)}}),Sao.View.Form.Dict.Numeric=Sao.class_(Sao.View.Form.Dict.Float,{class_:"dict-numeric",get_value:function(){var e=this.input.val();return!e&&0!==e||(e=new Sao.Decimal(e),isNaN(e.valueOf()))?null:e}}),Sao.View.Form.Dict.Date=Sao.class_(Sao.View.Form.Dict.Entry,{class_:"dict-date",format:"%x",_input:"date",_input_format:"%Y-%m-%d",_format:Sao.common.format_date,_parse:Sao.common.parse_date,create_widget:function(){Sao.View.Form.Dict.Date._super.create_widget.call(this);var e=this.input.parent().find(".input-group-btn"),t=(this.input_date=jQuery("<input/>",{type:this._input,role:"button",tabindex:-1}),this.input_date.click(()=>{var e=this.get_value(),e=this._format(this._input_format,e);this.input_date.val(e)}),this.input_date.change(()=>{var e=this.input_date.val();e&&(e=this._parse(this._input_format,e),e=this._format(this.format,e),this.input.val(e).change(),this.input.focus())}),this.input_date[0].type==this._input&&(e=jQuery("<div/>",{class:"btn btn-default","aria-label":Sao.i18n.gettext("Open the calendar"),title:Sao.i18n.gettext("Open the calendar")}).prependTo(e),this.input_date.appendTo(e),Sao.common.ICONFACTORY.get_icon_img("tryton-date").appendTo(e)),new Mousetrap(this.el[0]));t.bind("enter",(e,t)=>{var i=this._parse(this.format,this.input.val()),i=this._format(this.format,i);this.input.val(i).change()}),t.bind("=",(e,t)=>{e.preventDefault(),this.input.val(this._format(this.format,moment())).change()}),Sao.common.DATE_OPERATORS.forEach(i=>{t.bind(i[0],(e,t)=>{e.preventDefault();e=this.get_value()||Sao.DateTime();e.add(i[1]),this.input.val(this._format(this.format,e)).change()})})},get_value:function(){return this._parse(this.format,this.input.val())},set_value:function(e){e=e instanceof Sao.DateTime||e instanceof Sao.Date?this._format(this.format,e):"",this.input.val(e)}}),Sao.View.Form.Dict.DateTime=Sao.class_(Sao.View.Form.Dict.Date,{class_:"dict-datetime",format:"%x %X",_input:"datetime-local",_input_format:"%Y-%m-%dT%H:%M:%S",_format:Sao.common.format_datetime,_parse:Sao.common.parse_datetime}),Sao.View.Form.PYSON=Sao.class_(Sao.View.Form.Char,{class_:"form-pyson",init:function(e,t){Sao.View.Form.PYSON._super.init.call(this,e,t),this.encoder=new Sao.PYSON.Encoder({}),this.decoder=new Sao.PYSON.Decoder({},!0),this.el.keyup(this.validate_pyson.bind(this)),this.icon=jQuery("<img/>",{class:"icon form-control-feedback"}).appendTo(this.group),this.group.addClass("has-feedback")},display:function(){Sao.View.Form.PYSON._super.display.call(this),this.validate_pyson()},get_encoded_value:function(){var e=this.input.val();if(!e)return e;try{return this.encoder.encode(eval_pyson(e))}catch(e){return null}},set_value:function(){var e=this.get_encoded_value(),t=this.record,i=this.field,n=i.get_client(t);e&&n&&Sao.common.compare(e,this.encoder.encode(this.decoder.decode(n)))&&(e=n),i.set_client(t,e)},get_client_value:function(){var e=Sao.View.Form.PYSON._super.get_client_value.call(this);return e=e&&Sao.PYSON.toString(this.decoder.decode(e))},validate_pyson:function(){var e="ok";null===this.get_encoded_value()&&(e="error"),Sao.common.ICONFACTORY.get_icon_url("tryton-"+e).then(e=>{this.icon.attr("src",e)})},focus_out:function(){this.validate_pyson(),Sao.View.Form.PYSON._super.focus_out.call(this)}}),Sao.View.FormXMLViewParser.WIDGETS={binary:Sao.View.Form.Binary,boolean:Sao.View.Form.Boolean,callto:Sao.View.Form.CallTo,char:Sao.View.Form.Char,date:Sao.View.Form.Date,datetime:Sao.View.Form.DateTime,dict:Sao.View.Form.Dict,document:Sao.View.Form.Document,email:Sao.View.Form.Email,float:Sao.View.Form.Float,html:Sao.View.Form.HTML,image:Sao.View.Form.Image,integer:Sao.View.Form.Integer,many2many:Sao.View.Form.Many2Many,many2one:Sao.View.Form.Many2One,multiselection:Sao.View.Form.MultiSelection,numeric:Sao.View.Form.Float,one2many:Sao.View.Form.One2Many,one2one:Sao.View.Form.One2One,password:Sao.View.Form.Password,progressbar:Sao.View.Form.ProgressBar,pyson:Sao.View.Form.PYSON,reference:Sao.View.Form.Reference,richtext:Sao.View.Form.RichText,selection:Sao.View.Form.Selection,sip:Sao.View.Form.SIP,text:Sao.View.Form.Text,time:Sao.View.Form.Time,timedelta:Sao.View.Form.TimeDelta,timestamp:Sao.View.Form.DateTime,url:Sao.View.Form.URL}}(),!function(){"use strict";var g;function v(e){var t,i,n,o="";e.parents(".form").length||e.parents("#menu").length||(t="100vh",e.parents(".modal-body").length&&(t=e.parents(".modal-body").css("max-height")),i=" ",e.parents(".panel-body").each(function(e,t){t=jQuery(t),i=(i+="- "+t.css("padding-top"))+" - "+t.css("padding-bottom")}),n=" ",e.parents(".panel").each(function(e,t){t=(t=jQuery(t)).css("box-shadow").match(/\d+px/g);t&&t.length&&(t=t.map(function(e){return e.replace("px","")}),n+="- "+Math.max.apply(null,t)+"px")}),o="calc("+t+" - "+e[0].getBoundingClientRect().y+"px"+i+n+")"),e.css("height",o)}function i(s,a,r){function l(){for(;d<s.length;d++){for(var e,t=s[d],i=t.record,n=0;n<t.tree.columns.length;n++){var o=t.tree.columns[n];if("field"==o.type){e=o.attributes.name;break}}if(e&&!i.is_loaded(e))return void i.load(e,!0,!1).done(l);t.redraw(a,r)}c.resolve()}var c=jQuery.Deferred(),d=0;return l(),c.promise()}"IntersectionObserver"in window&&(g=new IntersectionObserver(function(e,t){for(const i of e)i.isIntersecting&&jQuery(i.target).trigger("click")},{rootMargin:"0px 0px 50px 0px"})),jQuery(window).resize(function(){jQuery(".treeview").each(function(e,t){v(jQuery(t))})}),Sao.View.TreeXMLViewParser=Sao.class_(Sao.View.XMLViewParser,{_parse_tree:function(e,t){for(const i of e.childNodes)this.parse(i)},_parse_field:function(e,t){var i=t.name,n=new Sao.View.TreeXMLViewParser.WIDGETS[t.widget](this.view.screen.model,t);this.view.widgets[i]||(this.view.widgets[i]=[]),n.tree=this.view,this.view.widgets[i].push(n);"symbol"in t&&n.suffixes.push(new Sao.View.Tree.Symbol(t,1)),~["url","email","callto","sip"].indexOf(t.widget)&&n.prefixes.push(new Sao.View.Tree.Affix(t,t.widget)),"icon"in t&&n.prefixes.push(new Sao.View.Tree.Affix(t));for(const s of e.childNodes){var o={};for(const a of s.attributes)o[a.name]=a.value;o.name||(o.name=i);let e;(e="prefix"==s.tagName?n.prefixes:n.suffixes).push(new Sao.View.Tree.Affix(o))}"symbol"in t&&n.prefixes.push(new Sao.View.Tree.Symbol(t,0)),this.view.attributes.sequence||this.view.children_field||!1===this.field_attrs[i].sortable||(n.sortable=!0),this.view.columns.push(n),t.optional&&i!==this.exclude_field&&this.view.optionals.push(n),Boolean(parseInt(t.sum||"0",10))&&(e=jQuery("<label/>",{text:t.string}),t=jQuery("<div/>",{class:"value"}),this.view.sum_widgets.set(n,[e,t]))},_parse_button:function(e,t){t=new Sao.View.Tree.ButtonColumn(this.view,t);this.view.columns.push(t)}}),Sao.View.Tree=Sao.class_(Sao.View,{view_type:"tree",xml_parser:Sao.View.TreeXMLViewParser,draggable:!1,display_size:Sao.config.display_size,init:function(e,t,i,n){this.children_field=n,this.optionals=[],this.sum_widgets=new Map,this.columns=[],this.selection_mode=t.attributes.selection_mode||Sao.common.SELECTION_MULTIPLE,this.el=jQuery("<div/>").css("display","grid"),this.scrollbar=jQuery("<div/>").appendTo(jQuery("<div/>",{class:"scrollbar responsive"}).appendTo(this.el)),this.treeview=jQuery("<div/>",{class:"treeview responsive"}).appendTo(this.el),this.treeview.scroll(()=>{this.scrollbar.parent().scrollLeft(this.treeview.scrollLeft())}),this.scrollbar.parent().scroll(()=>{this.treeview.scrollLeft(this.scrollbar.parent().scrollLeft())}),this.expanded=new Set,Sao.View.Tree._super.init.call(this,e,t,i),this.rows=[],this.edited_row=null,this.table=jQuery("<table/>",{class:"tree table table-hover table-condensed"}),this.editable&&this.table.addClass("table-bordered"),this.treeview.append(this.table),this.colgroup=jQuery("<colgroup/>").appendTo(this.table);var o,s=jQuery("<col/>",{class:"selection-state"}).appendTo(this.colgroup),a=(this.selection_mode==Sao.common.SELECTION_NONE&&s.css("width",0),this.thead=jQuery("<thead/>").appendTo(this.table),jQuery("<tr/>")),r=jQuery("<th/>",{class:"selection-state"});this.selection=jQuery("<input/>",{type:"checkbox"}),this.selection.change(this.selection_changed.bind(this)),r.append(this.selection),a.append(r),this.thead.append(a),this.tfoot=null,this.sum_widgets.size&&((o=jQuery("<tr/>")).append(jQuery("<th/>")),this.tfoot=jQuery("<tfoot/>"),this.tfoot.append(o),this.table.prepend(this.tfoot)),this.children_field&&(this.expander=jQuery("<span/>",{class:"expander"}).append(jQuery("<img/>",{tabindex:0,class:"icon"})),this.update_expander("more"),this.expander.on("click keypress",Sao.common.click_press(this.unfold.bind(this))),Sao.common.ICONFACTORY.get_icon_url("tryton-unfold-"+this.expander.action).then(e=>{this.expander.children().attr("src",e)}));for(const h of this.columns){s=jQuery("<col/>",{class:h.attributes.widget}).appendTo(this.colgroup),(r=jQuery("<th/>",{class:h.attributes.widget})).uniqueId();var l,c,d=jQuery("<label/>").text(h.attributes.string).attr("title",h.attributes.string);this.editable&&(h.attributes.required&&d.addClass("required"),h.attributes.readonly||d.addClass("editable")),h.attributes.help&&d.attr("title",h.attributes.help),h.sortable&&(l=jQuery("<img/>",{class:"icon"}),d.append(l),h.arrow=l,r.click(h,this.sort_model.bind(this)),d.addClass("sortable")),a.append(r.append(d)),h.header=r,h.col=s,h.footers=[],this.sum_widgets.size&&(h.attributes.name,l=jQuery("<th/>",{class:h.class_}),this.sum_widgets.has(h)&&(d=this.sum_widgets.get(h)[0],c=this.sum_widgets.get(h)[1],l.append(d),l.append(c)),o.append(l),h.footers.push(l))}this.tbody=jQuery("<tbody/>"),this.table.append(this.tbody),this.colgroup.prepend(jQuery("<col/>",{class:"tree-menu"})),this.thead.children().prepend(jQuery("<th/>",{class:"tree-menu"})),this.tfoot&&this.tfoot.children().prepend(jQuery("<th/>")),this.set_drag_and_drop(),r=this.thead.find("th").first(),this.optionals.length&&r.addClass("optional");n=jQuery("<ul/>",{class:"dropdown-menu"}).click(function(e){e.stopImmediatePropagation()}),e=jQuery("<div/>",{class:"dropdown"}).append(jQuery("<a/>",{"data-toggle":"dropdown","aria-haspopup":!0,"aria-expanded":!1,title:Sao.i18n.gettext("Menu")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-menu")).click(n,this.tree_menu.bind(this))).append(n);e.on("hide.bs.dropdown",()=>{this.save_optional(!0),Sao.common.set_overflow(r,"hide")}),e.on("show.bs.dropdown",()=>{Sao.common.set_overflow(r,"show")}),r.append(e)},tree_menu:function(e){var t=e=>{e.data.set_visible(jQuery(e.delegateTarget).prop("checked")),this.save_optional(),this.display();for(const t of this.rows)t.update_visible()},i=e.data;i.empty();for(const n of this.optionals)i.append(jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem"}).append(jQuery("<label/>",{class:"checkbox"}).append(jQuery("<input/>",{type:"checkbox",checked:n.get_visible()}).change(n,t)).append(" "+n.attributes.string))));this.optionals.length&&i.append(jQuery("<li/>",{role:"separator",class:"divider hidden-xs"})),i.append(jQuery("<li/>",{role:"presentation",class:this.selected_records.length||!navigator.clipboard?"":"disabled"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).text(" "+Sao.i18n.gettext("Copy")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-copy",{"aria-hidden":"true"})).click(e=>{e.preventDefault(),this.on_copy(),i.dropdown("toggle")})))},save_optional:function(e=!0){if(this.optionals.length){var t={};for(const i of this.optionals)t[i.attributes.name]=!i.get_visible();e&&new Sao.Model("ir.ui.view_tree_optional").execute("set_optional",[this.view_id,t],{}),Sao.Screen.tree_column_optional[this.view_id]=t}},reset:function(){this.display_size=Sao.config.display_size},get editable(){return parseInt(this.attributes.editable||0,10)&&!this.screen.attributes.readonly},get creatable(){return!!this.editable&&(!this.attributes.creatable||Boolean(parseInt(this.attributes.creatable,10)))},unfold:function(){var t,e;this.expander&&(e="more"==this.expander.action?(t=function(e){e.is_selected()&&!e.is_expanded()&&e.expand_row(),e.rows.forEach(t)},"less"):(t=function(e){e.is_selected()&&e.is_expanded()&&e.collapse_row(),e.rows.forEach(t)},"more"),this.rows.forEach(t),this.update_expander(e))},update_expander:function(e){this.expander&&(e&&(this.expander.action=e),Sao.common.ICONFACTORY.get_icon_url("tryton-unfold-"+this.expander.action).then(e=>{this.expander.children().attr("src",e)}),jQuery.isEmptyObject(this.selected_records)?this.expander.css("visibility","hidden"):this.expander.css("visibility","visible"))},sort_model:function(e){var t=e.data,i=t.arrow;for(const o of this.columns)o.arrow&&o!=t&&o.arrow.attr("src")&&o.arrow.attr("src","");this.screen.order=this.screen.default_order,"ASC"==i.data("order")?(i.data("order","DESC"),Sao.common.ICONFACTORY.get_icon_url("tryton-arrow-up").then(function(e){i.attr("src",e)}),this.screen.order=[[t.attributes.name,"DESC"]]):"DESC"==i.data("order")?(i.data("order",""),i.attr("src","")):(i.data("order","ASC"),Sao.common.ICONFACTORY.get_icon_url("tryton-arrow-down").then(function(e){i.attr("src",e)}),this.screen.order=[[t.attributes.name,"ASC"]]);var n=[];for(const s of this.group)s.id<0&&(n=s.group);e=this.screen.screen_container.get_text();!jQuery.isEmptyObject(n)||this.screen.search_count==this.group.length||this.group.parent?this.screen.search_filter(e,!0).then(i=>{this.group.sort(function(e,t){return(e=(e=i.indexOf(e.id))<0?i.length:e)<(t=(t=i.indexOf(t.id))<0?i.length:t)?-1:t<e?1:0}),this.screen.display()}):this.screen.search_filter(e)},update_arrow:function(){var e=this.screen.order,i=null,n=null,o="";e&&1==e.length&&(i=e[0][0],n=e[0][1])&&(n=n.trim().split(" ",1)[0],o={ASC:"tryton-arrow-down",DESC:"tryton-arrow-up"}[n]),this.columns.forEach(function(e){var t=e.arrow;t&&(e.attributes.name!=i?(t.data("order",""),t.attr("src","")):(t.data("order",n),Sao.common.ICONFACTORY.get_icon_url(o).then(function(e){t.attr("src",e)})))})},on_copy:function(){var e=[];this.selected_records.forEach(i=>{var n=[];this.columns.forEach(e=>{if(e.get_visible()&&e.attributes.name&&!(e instanceof Sao.View.Tree.ButtonColumn)){var t;if(i.is_loaded(e.attributes.name))t=e.get_textual_value(i);else try{i.load(e.attributes.name,!1,!1),t=e.get_textual_value(i)}catch(e){Sao.Logger.error("Error loading "+this.attributes.name+" for "+i),t=Sao.i18n.gettext("#ERROR")}n.push('"'+String(t).replace('"','""')+'"')}}),e.push(n.join("\t"))}),navigator.clipboard.writeText(e.join("\n"))},_add_drag_n_drop:function(){Sortable.create(this.tbody[0],{handle:".draggable-handle",ghostClass:"dragged-row"}),this.tbody.on("dragstart",this.drag_data_get.bind(this)),this.tbody.on("drop",this.drag_data_received.bind(this))},set_drag_and_drop:function(){var e,t=!1;this.children_field?(e=this.screen.model.fields[this.children_field])&&(e=e.description.relation_field,t=Boolean(this.widgets[e])):this.attributes.sequence&&(t=!0),this.screen.readonly&&(t=!1),(this.draggable=t)&&(this.thead.find("th").first().addClass("draggable-handle"),this._add_drag_n_drop())},drag_data_get:function(t){function i(e){e.el[0]===t.target&&(t.originalEvent.dataTransfer.setData("path",e.path),t.originalEvent.dataTransfer.setData("position",n)),0===e.rows.length&&o.push(e),n+=1,e.rows.forEach(i.bind(this))}var n=0,o=[];this.rows.forEach(i.bind(this))},drag_data_received:function(e){var t=e.originalEvent.dataTransfer,i=t.getData("path").split(".");if(0!==i.length){for(var r=this;0<i.length;)r=r.rows[i[0]],i=i.slice(1);for(var n,l,o,s,c,d,h=r.record,u=null,a=(l=(e.ctrlKey||e.metaKey)&&this.children_field?((u=this._find_row(r.el.prev()))||this).rows.length:e.shiftKey?(n=this._find_row(r.el.prev()))?((u=n.parent_)||this).rows.indexOf(n)+1:(u=null,0):(n=this._find_row(r.el.next()))?((u=n.parent_)||this).rows.indexOf(n):(u=null,this.rows.length),u);a&&a!=r;)a=a.parent_;a?(e=t.getData("position"),jQuery(this.tbody.children()[e]).before(r.el)):(s=function(e){o.el.after(e.el),(o=e).rows.forEach(s)},(o=r).rows.forEach(s),c=h.group,d=r.group_position,(u?u.record.children_group(this.children_field):jQuery.Deferred().resolve(this.group)).then(e=>{var t=(r.parent_||this).rows,i=(u||this).rows;c===e?(d<l&&--l,c.splice(d,1),c.splice(l,0,h),c.record_modified()):(c.remove(h,!0,!0),c.record_removed.splice(c.record_removed.indexOf(h)),e.add(h,l),h.parent_name?h.modified_fields[c.parent_name]=!0:(h.modified_fields[c.parent_name]=!0,h._values[c.parent_name]=null)),i.splice(l,0,r),t.splice(d,1),r.parent_=u,r.record.group=e;for(const s of i.slice(l))s.reset_path();for(const a of t.slice(d))a.reset_path();function n(e){e.redraw(o),e.rows.forEach(n)}var o=this.get_selected_paths();r.redraw(o);r.rows.forEach(n),this.attributes.sequence&&r.record.group.set_sequence(this.attributes.sequence,this.screen.new_position)}))}},get_fields:function(){return Object.keys(this.widgets)},get_buttons:function(){var e=[];for(const t of this.columns)t instanceof Sao.View.Tree.ButtonColumn&&e.push(t);return e},display:function(e,a){v(this.treeview);this.tbody;var t=this.record;if(jQuery.isEmptyObject(e)&&t)if(e=this.get_selected_paths(),this.selection.prop("checked")&&!this.selection.prop("indeterminate"))for(const p of this.screen.group.slice(this.rows.length,this.display_size))e.push([p.id]);else{t=(t=t.get_path(this.group)).map(function(e){return e[1]});Sao.common.contains(e,t)||(e=[t])}a=a||this.get_expanded_paths(),this.selection_mode==Sao.common.SELECTION_MULTIPLE?this.selection.show():this.selection.hide();const r=(e,t)=>{var i=[];for(const s of e){i.push(s);var n,o=t.concat([s.id]);Sao.common.contains(a,o)&&(n=s.field_get_client(this.children_field),Array.prototype.push.apply(i,r(n,o)))}return i},n=e=>{var t=[];for(const i of e)t.push(i.record),i.is_expanded()&&Array.prototype.push.apply(t,n(i.rows));return t};var t=Math.min(this.group.length,this.display_size),o=(this.children_field?Sao.common.compare(r(this.group.slice(0,t),[]),n(this.rows))||this.construct():t>this.rows.length&&Sao.common.compare(this.group.slice(0,this.rows.length),n(this.rows))?this.construct(!0):t==this.rows.length&&Sao.common.compare(this.group.slice(0,this.rows.length),n(this.rows))||this.construct(),2),i=[],t=(jQuery.isEmptyObject(this.screen.domain)||i.push(this.screen.domain),this.screen.screen_container.get_tab_domain()),s=(jQuery.isEmptyObject(t)||i.push(t),new Sao.common.DomainInversion),i=s.simplify(i),l=new Sao.PYSON.Decoder(this.screen.context),c=[],d=Sao.Screen.tree_column_optional[this.view_id]||{};for(const f of this.columns){o+=1;var h=f.attributes.name;if(!h)return;var u,_,m=d.hasOwnProperty(h)?d[h]:Boolean(parseInt(f.attributes.optional||"0",10));l.decode(f.attributes.tree_invisible||"0")||m||h===this.screen.exclude_field?(--o,f.set_visible(!1)):h in this.screen.model.fields&&(m=this.screen.model.fields[h],"boolean"!=typeof(h=s.domain_inversion(i,h))&&(h=s.simplify(h)),s.unique_value(h,m._single_value)[0]&&jQuery.isEmptyObject(this.children_field)?(--o,f.set_visible(!1)):f.set_visible(!0)),f.get_visible()?f.col.hasClass("draggable-handle")||f.col.hasClass("optional")||f.col.hasClass("selection-state")||f.col.hasClass("favorite")||(f.attributes.width?(u=_=f.attributes.width,c.push(u+"px")):(u={integer:8,selection:9,reference:20,one2many:5,many2many:5,boolean:3,binary:20}[f.attributes.widget]||10,f.attributes.symbol&&(u+=2),h=1,f.attributes.expand&&(h+=parseInt(f.attributes.expand,10)),_=100*u*h+"%",c.push(u+"em")),f.col.css("width",_),f.col.show()):(f.col.css("width",0),f.col.hide())}return this.children_field&&this.columns.every(e=>!(!e.col.hasClass("draggable-handle")&&!e.header.hasClass("invisible")&&(this.expander.parent()[0]!==e.header[0]&&e.header.prepend(this.expander),1))),this.table.css("min-width","calc("+c.join(" + ")+")"),this.scrollbar.css("min-width",this.table.css("min-width")),!this.table.hasClass("no-responsive")&1<this.columns.filter(function(e){return e.get_visible()}).length?(this.table.addClass("responsive"),this.table.addClass("responsive-header")):(this.table.removeClass("responsive"),this.table.removeClass("responsive-header")),this.update_arrow(),this.redraw(e,a).then(()=>{var e,t,i=this.table.children("tbody");i.length?i!==this.tbody&&i.replaceWith(this.tbody):this.table.append(this.tbody),this.tbody.append(this.rows.filter(function(e){return!e.el.parent().length}).map(function(e){return e.el})),this.update_selection(),this.display_size<this.group.length&&!this.tbody.children().last().hasClass("more-row")&&(i=jQuery("<tr/>",{class:"more-row"}),e=jQuery("<td/>",{colspan:o}),t=jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("More")}).text(Sao.i18n.gettext("More")).click(()=>{var e=this.table.height();this.display_size+=Sao.config.display_size,this.display(),e=e-this.treeview.height()-50,this.tfoot&&(e-=this.tfoot.height()),this.treeview[0].scroll({top:e})}),e.append(t),i.append(e),this.tbody.append(i),g)&&g.observe(t[0])}).done(Sao.common.debounce(this.update_sum.bind(this),250))},construct:function(e){e?this.tbody.find("tr.more-row").remove():(this.rows=[],this.tbody=jQuery("<tbody/>"),this.draggable&&this._add_drag_n_drop(),this.edited_row=null);for(const i of this.group.slice(this.rows.length,this.display_size)){var t=this.editable?Sao.View.Tree.RowEditable:Sao.View.Tree.Row;this.rows.push(new t(this,i,this.rows.length))}},redraw:function(e,t){return i(this.rows,e,t)},switch_:function(e){this.screen.row_activate()},select_changed:function(e){this.edited_row&&(e=this.edited_row.record,this.edited_row.set_selection(!0)),this.record=e},update_sum:function(){for(var[e,t]of this.sum_widgets){for(var i,n,o=e.attributes.name,s=this.selected_records,e="-",a=t[0],t=t[1],r=null,l=null,c=!0,d=0,h=this.screen.model.fields[o],u=s.map(function(e){return e.id}),_=0;_<this.group.length;_++){if(!(i=this.group[_]).get_loaded([o])&&0<=i.id){c=!1;break}var m=h.get(i);null!==(m=m&&m.isTimeDelta?m.asSeconds():m)&&(null===r?r=m:r+=m,!~u.indexOf(i.id)&&s||(null===l?l=m:l+=m),h.digits)&&(d=(m=h.digits(i))&&null!==d?Math.max(m[1],d):null)}c&&(r="timedelta"==h.description.type?(n=h.converter(this.group),l=Sao.common.timedelta.format(Sao.TimeDelta(null,l),n),Sao.common.timedelta.format(Sao.TimeDelta(null,r),n)):null!==d?((n={}).minimumFractionDigits=d,n.maximumFractionDigits=d,l=(l||0).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),n),(r||0).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),n)):(l=(l||0).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang())),(r||0).toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()))),e=l+"\n"+r),t.text(e),t.parent().attr("title",a.text()+"\n"+t.text())}},get selected_records(){if(this.selection_mode==Sao.common.SELECTION_NONE)return[];function t(e){e.is_selected()&&i.push(e.record),e.rows.forEach(t)}var i=[];if(this.rows.forEach(t),this.selection.prop("checked")&&!this.selection.prop("indeterminate"))for(const e of this.group.slice(this.rows.length))i.push(e);return i},get listed_records(){if(!this.children_field)return this.group.slice();const l=e=>{for(var t=[],i=((a=this.find_row(e))||this).rows,n=0,o=this.n_children(a);n<o;n++){var s,a,r=e.concat([n]);(a=i[n])&&(s=a.record,t.push(s),a.is_expanded())&&(t=t.concat(l(r)))}return t};return l([]).concat(this.group.slice(this.rows.length))},get_listed_paths:function(){if(!this.children_field)return this.group.map(function(e){return[e.id]});const c=(e,t)=>{for(var i=[],n=((r=this.find_row(e))||this).rows,o=0,s=this.n_children(r);o<s;o++){var a,r,l=e.concat([o]);(r=n[o])&&(a=r.record,a=t.concat([a.id]),i.push(a),r.is_expanded())&&(i=i.concat(c(l,a)))}return i};return c([],[]).concat(this.group.slice(this.rows.length).map(function(e){return[e.id]}))},select_records:function(i,n){if((i=!i&&n?this.rows[0].record:i)&&n){for(var e,t=i.get_index_path(this.screen.group),o=n.get_index_path(this.screen.group),s=Math.min(t.length,o.length),a=0;a<s;a++)if(t[a]>o[a]){e=i,i=n,n=e;break}!e&&t.length>o.length&&(e=i,i=n,n=e)}var r=this.rows[0].record===i,l=function(e){var t=e.record;t===i&&(r=!0),e.set_selection(r),t===n&&(r=!1),e.rows.forEach(l)};this.rows.forEach(l)},selection_changed:function(){var t=this.selection.prop("checked"),i=function(e){e.set_selection(t),e.rows.forEach(i)};this.rows.forEach(i),t&&this.rows[0]?this.select_changed(this.rows[0].record):this.select_changed(null),this.update_expander(t?"more":null),this.update_sum()},update_selection:function(){this.update_sum();var e=this.selected_records;this.selection.prop("indeterminate",!1),jQuery.isEmptyObject(e)?this.selection.prop("checked",!1):(this.rows.every(e=>e.is_selected())&&e.length>=this.tbody.children().length||this.selection.prop("indeterminate",!0),this.selection.prop("checked",!0)),this.update_expander()},get_selected_paths:function(){var r=[];return function e(t,i){for(var n,o,s=0,a=t.rows.length;s<a;s++)n=t.rows[s],o=i.concat([n.record.id]),n.is_selected()&&r.push(o),e(n,o)}(this,[]),r},get_expanded_paths:function(e=[],t=[]){for(var i,n,o=[],s=this.find_row(e),a=(s||this).rows,r=0,l=this.n_children(s);r<l;r++)n=e.concat([r]),(s=a[r])&&s.is_expanded()&&(i=t.concat(s.record.id),o.push(i),o=o.concat(this.get_expanded_paths(n,i)));return o},find_row:function(e){for(var t,i=null,n=this.rows,o=0,s=e.length;o<s;o++){if(t=e[o],!n||t>=n.length)return null;if(n=(i=n[t]).rows,!this.children_field)break}return i},n_children:function(e){return e&&this.children_field?e.record.is_loaded(this.children_field)?e.record.field_get_client(this.children_field).length:0:this.rows.length},set_cursor:function(t,e){var i,n,o,s,a;this.record&&(i=this.record.get_index_path(this.group),this.rows.length<=i[0]&&(this.display_size=this.group.length,this.display()),a=()=>{var e;(o=this.find_row(i))&&null!==(n=o.next_column(null,t))&&(o=o._get_column_td(n),this.editable&&t&&o.trigger("click"),e=Sao.common.find_focusable_child(o))&&e.focus()},(s=1<i.length?this.rows[i[0]].expand_to_path(i.slice(1),[this.record.get_path(this.group).map(function(e){return e[1]})]):s)?s.then(a):a())},save_row:function(){var e,t=this.edited_row;if(!this.editable||!this.edited_row)return jQuery.when();if(this.edited_row.record.validate(this.get_fields(),!1,!1,!0))return(e=this.group.parent?this.screen.attributes.pre_validate?this.record.pre_validate():jQuery.when():this.edited_row.record.save()).fail(()=>{this.edited_row!=t&&(this.edit_row(null),t.set_selection(!0),t.selection_changed(),this.edit_row(t))}),e;for(var i=!1,n=this.edited_row.record.invalid_fields(),o=0;o<this.columns.length;o++){var s,a=this.columns[o];a.attributes.name in n&&(s=this.edited_row._get_column_td(o),(s=this.edited_row.get_editable_el(s).data("widget")).display(this.edited_row.record,a.field),i||(s.focus(),i=!0))}},edit_row:function(e){this.editable&&this.edited_row!=e&&(this.edited_row&&this.edited_row.unset_editable(),e&&e.set_editable(),this.edited_row=e)},_find_row:function(t){function i(e){e.el[0]==t[0]?n=e:e.rows.forEach(i)}var n=null;return this.rows.forEach(i),n}}),Sao.View.Tree.Row=Sao.class_(Object,{init:function(e,t,i,n){this.tree=e,this.current_column=null,this.rows=[],this.record=t,this.parent_=n,this.children_field=e.children_field,this.expander=null,this._group_position=null,this._path=null,this._drawed_record=null,this.el=jQuery("<tr/>"),this.el.on("click",this.select_row.bind(this)),this._construct()},get group_position(){return null===this._group_position&&(this._group_position=this.record.group.indexOf(this.record)),this._group_position},get path(){var e;return this._path||((e=this.parent_?jQuery.extend([],this.parent_.path.split(".")):[]).push(this.group_position),this._path=e.join(".")),this._path},reset_path:function(){this._group_position=null,this._path=null;for(const e of this.rows)e.reset_path()},is_expanded:function(){return this.tree.expanded.has(this)},get_id_path:function(){return this.parent_?this.parent_.get_id_path().concat([this.record.id]):[this.record.id]},_construct:function(){this.tree.el.uniqueId(),i=jQuery("<td/>"),this.tree.draggable&&(i.addClass("draggable-handle"),i.append(Sao.common.ICONFACTORY.get_icon_img("tryton-drag"))),this.tree.optionals.length&&i.addClass("optional"),this.el.append(i),i=jQuery("<td/>",{class:"selection-state"}).click(e=>{e.stopPropagation(),this.selection.click()}),this.el.append(i),this.selection=jQuery("<input/>",{type:"checkbox",name:"tree-selection-"+this.tree.el.attr("id")}),this.selection.click(function(e){e.stopPropagation()}),this.selection.change(this.selection_changed.bind(this)),i.append(this.selection);var e=e=>{this.expander&&!this.is_expanded()&&this.tree.n_children(this)<=Sao.config.limit&&this.toggle_row(),this.select_column(e.data.index)};this.children_field&&(this.expander=jQuery("<span/>",{class:"expander"}).append("<img/>",{tabindex:0,class:"icon"}),this.expander.children().html(" "),this.expander.on("click keypress",Sao.common.click_press(this.toggle_row.bind(this))),this.expander.dblclick(e=>{e.preventDefault(),e.stopImmediatePropagation()}));for(var t=0;t<this.tree.columns.length;t++){var i,n,o=this.tree.columns[t],s=((i=o instanceof Sao.View.Tree.ButtonColumn?jQuery("<td>"):jQuery("<td/>",{"data-title":o.attributes.string+Sao.i18n.gettext(": ")}).append(jQuery("<span/>",{"aria-hidden":!0}))).attr("headers",o.header.attr("id")),i.on("click keypress",{index:t},e),this.tree.editable?(o.attributes.required&&i.addClass("required"),o.attributes.readonly||i.addClass("editable")):i.dblclick(this.switch_row.bind(this)),jQuery("<div>",{class:"cell"}));if(i.append(s),o.prefixes)for(n=0;n<o.prefixes.length;n++){o.prefixes[n];s.append(jQuery("<span/>",{class:"prefix"}))}if(s.append(jQuery("<span/>",{class:"widget"})),o.suffixes)for(n=0;n<o.suffixes.length;n++){o.suffixes[n];s.append(jQuery("<span/>",{class:"suffix"}))}this.el.append(i)}},_get_column_td:function(e,t){return t=t||this.el,jQuery(t.children()[e+2])},redraw:function(t,i){switch(t=t||[],i=i||[],this.tree.selection_mode){case Sao.common.SELECTION_NONE:this.selection.hide();break;case Sao.common.SELECTION_SINGLE:this.selection.attr("type","radio"),this.selection.show();break;case Sao.common.SELECTION_MULTIPLE:this.selection.attr("type","checkbox"),this.selection.show()}function n(e,t){for(const n of["muted","success","warning","danger"]){var i="muted"==n?"text-muted":n;n==t?e.addClass(i):e.removeClass(i)}}if(this._drawed_record!==this.record.identity){for(var o=0;o<this.tree.columns.length;o++){var s=this.tree.columns[o],a=this._get_column_td(o),r=a.find(".cell");if(s.prefixes)for(var l=0;l<s.prefixes.length;l++){var c,d=s.prefixes[l],h=jQuery(r.children(".prefix")[l]);(c=h.children()).length?d.render(this.record,c):h.empty().append(d.render(this.record))}var u=r.children(".widget");if((c=u.children()).length?s.render(this.record,c):u.empty().append(s.render(this.record)),s.suffixes)for(var _=0;_<s.suffixes.length;_++){var m=s.suffixes[_],p=jQuery(r.children(".suffix")[_]);(c=p.children()).length?m.render(this.record,c):p.empty().append(m.render(this.record))}let e=this.record.expr_eval(s.attributes.visual);n(a,e=this.record.deleted||this.record.removed?"muted":e)}this.update_visible()}this.children_field&&this.tree.columns.every((e,t)=>{return!(!e.col.hasClass("draggable-handle")&&!e.header.hasClass("invisible")&&(e=this._get_column_td(t).find(".cell"),this.expander.parent()[0]!==e[0]&&e.prepend(this.expander),1))}),this._drawed_record=this.record.identity;var e,f,g=this.get_id_path();this.set_selection(Sao.common.contains(t,g)),this.children_field&&(e=this.path.split(".").length,f="margin-left",Sao.i18n.rtl&&(f="margin-right"),this.expander.children().css(f,e-1+"em"),f=()=>{var e=this.record.field_get_client(this.children_field).length;e&&(this.is_expanded()||Sao.common.contains(i,g))?(this.expander.css("visibility","visible"),this.tree.expanded.add(this),this.expand_children(t,i),this.update_expander(!0)):(this.expander.css("visibility",e?"visible":"hidden"),this.update_expander(!1))},this.record.is_loaded(this.children_field)?f():this.record.load(this.children_field,!0,!1).done(f));let v=this.record.expr_eval(this.tree.attributes.visual);this.record.deleted||this.record.removed?(this.record.deleted&&this.el.css("text-decoration","line-through"),v="muted"):this.el.css("text-decoration","inherit"),n(this.el,v)},update_visible:function(){for(var e=this.tree.thead.is(":visible"),t=0;t<this.tree.columns.length;t++){var i=this.tree.columns[t],n=this._get_column_td(t);i.header.is(":hidden")&&e||"none"==i.header.css("display")?(n.hide(),n.addClass("invisible")):(n.show(),n.removeClass("invisible"))}},toggle_row:function(){return this.is_expanded()?this.collapse_row():this.expand_row(),!1},expand_row:function(){this.tree.n_children(this)>Sao.config.limit?(this.tree.record=this.record,this.tree.screen.switch_view("form")):(this.update_expander(!0),this.tree.expanded.add(this),this.expand_children())},collapse_row:function(){for(const e of this.rows)e.exception&&e.record.cancel();this.update_expander(!1),this.tree.expanded.delete(this),this.collapse_children()},update_expander:function(e){e=e?"tryton-arrow-down":"tryton-arrow-right";Sao.common.ICONFACTORY.get_icon_url(e).then(e=>{this.expander.children().attr("src",e)})},collapse_children:function(){for(const e of this.rows)e.collapse_children(),e.el.remove();this.rows=[]},expand_children:function(e,t){return this.record.load(this.children_field,!0,!1).done(()=>{0===this.rows.length&&this.record.field_get_client(this.children_field).forEach((e,t,i)=>{this.rows.push(new this.Class(this.tree,e,t,this))}),i(this.rows,e,t).then(()=>{this.el.after(this.rows.filter(function(e){return!e.el.parent().length}).map(function(e){return e.el})),this.tree.update_selection()})})},switch_row:function(){window.getSelection?window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges():document.selection&&document.selection.empty(),this.tree.selection_mode!=Sao.common.SELECTION_NONE&&(this.set_selection(!0),this.selection_changed(),!this.is_selected())||this.tree.switch_(this.path)},select_column:function(e){},select_row:function(e){var t;this.tree.selection_mode==Sao.common.SELECTION_NONE?(this.tree.select_changed(this.record),this.switch_row()):(e.shiftKey&&this.tree.selection_mode!=Sao.common.SELECTION_SINGLE?(t=this.tree.screen.current_record,this.tree.select_records(t,this.record)):((e.ctrlKey||e.metaKey)&&this.tree.selection_mode!=Sao.common.SELECTION_SINGLE||this.tree.select_records(null,null),this.set_selection(!this.is_selected())),this.selection_changed(),t&&(this.tree.screen.current_record=t))},is_selected:function(){return this.tree.selection_mode!=Sao.common.SELECTION_NONE&&this.selection.prop("checked")},set_selection:function(e){this.tree.selection_mode==Sao.common.SELECTION_NONE||(this.selection.prop("checked",e),e?this.el.addClass("selected"):this.el.removeClass("selected"),e)||this.tree.selection.prop("checked",!1)},selection_changed:function(){var e=this.is_selected();this.set_selection(e),e?(this.tree.select_changed(this.record),this.expander&&(this.is_expanded()?this.tree.update_expander("less"):"visible"==this.expander.css("visibility")&&this.tree.update_expander("more"))):this.tree.select_changed(this.tree.selected_records[0]||null),this.tree.update_selection()},expand_to_path:function(e,t){if(e.length&&this.record.field_get_client(this.children_field).length)return this.expander.css("visibility","visible"),this.tree.expanded.add(this),this.update_expander(!0),this.expand_children(t).done(()=>this.rows[e[0]].expand_to_path(e.slice(1),t))},next_column:function(e,t,i){var n,o;for(i=i||1,null===e&&0<i?e=-1:null===e&&(e=0),n=o=0;n<this.tree.columns.length;n++)if((o=(e+i*(n+1))%this.tree.columns.length)<0&&(o+=this.tree.columns.length),(a=this.tree.columns[o]).field){var s,a,r,l=(r=a.field.get_state_attrs(this.record)).invisible;if(a.header.is(":hidden")&&(l=!0),a=!!t&&(s=Sao.View.EditableTree.WIDGETS[a.attributes.widget],a.attributes.readonly||r.readonly||!s),!l&&!a)return o}}}),Sao.View.Tree.RowEditable=Sao.class_(Sao.View.Tree.Row,{init:function(e,t,i,n){Sao.View.Tree.RowEditable._super.init.call(this,e,t,i,n),this.edited_column=null,this.el.on("keypress",e=>{e.which==Sao.common.RETURN_KEYCODE&&this.tree.edited_row!=this&&(e.preventDefault(),this.tree.edit_row(this))})},redraw:function(e,t){Sao.View.Tree.RowEditable._super.redraw.call(this,e,t);for(var i=t=>{var i=this.record;return function(){var e=i.model.fields[t.field_name];e.set_state(i),t.display(i,e)}},n=0;n<this.tree.columns.length;n++){var o=this.tree.columns[n],s=this._get_column_td(n).children(".cell");(s=jQuery(s.children(".widget-editable")).data("widget"))&&(s=i(s),this.record.is_loaded(o.attributes.name)?s():this.record.load(o.attributes.name,!0,!1).done(s))}},select_column:function(e){this.edited_column=e},select_row:function(e){var t,i,n;e.stopPropagation(),this.tree.edited_row&&e.currentTarget==this.tree.edited_row.el[0]||(i=this.tree.screen.current_record,this.record!=i&&i&&!i.validate(this.tree.get_fields(),!1,!1,!0))||((t=i=jQuery(document.body)).hasClass("modal-open")&&(i=this.tree.el.parents(".modal").last()),(n=e=>{if(e.currentTarget!=t[0]||!t.hasClass("modal-open")){if(this.tree.save_row())return t.off("click.sao.editabletree"),this.tree.edit_row(null),!0;e.preventDefault(),e.stopPropagation()}})(e)&&(i.on("click.sao.editabletree",n),Sao.View.Tree.RowEditable._super.select_row.call(this,e),e.shiftKey||e.ctrlKey||e.metaKey||this.tree.edit_row(this)))},unset_editable:function(){this.tree.columns.forEach((e,t)=>{t=this._get_column_td(t);this.get_static_el(t).empty().append(e.render(this.record)).show(),this.get_editable_el(t).empty().data("widget",null).hide().parents(".treeview td").addBack().removeClass("edited")})},set_editable:function(){for(var e=null,t=0,i=this.tree.columns.length;t<i;t++){var n,o,s=this._get_column_td(t),a=this.tree.columns[t];a.field&&(n=Sao.View.EditableTree.WIDGETS[a.attributes.widget],!a.attributes.readonly)&&n&&((n=new n(this.tree,a.attributes)).el.on("keydown",this.key_press.bind(this)),(o=this.get_editable_el(s)).append(n.el),o.data("widget",n),n.display(this.record,a.field),this.get_static_el(s).hide(),o.show(),o.parents(".treeview td").addBack().addClass("edited"),this.edited_column==t)&&(e=n)}e&&e.focus()},get_static_el:function(e){return(e=e||this.get_active_td()).find(".widget")},get_editable_el:function(e){var t=(e=e||this.get_active_td()).find(".widget-editable");return t=t.length?t:jQuery("<span/>",{class:"widget-editable"}).insertAfter(e.find(".widget"))},get_active_td:function(){return this._get_column_td(this.edited_column)},key_press:function(s){var a,r,e,t,l,i,n;s.which!=Sao.common.TAB_KEYCODE&&s.which!=Sao.common.UP_KEYCODE&&s.which!=Sao.common.DOWN_KEYCODE&&s.which!=Sao.common.ESC_KEYCODE&&s.which!=Sao.common.RETURN_KEYCODE||jQuery(s.currentTarget).find(".dropdown-menu:visible").length||(s.preventDefault(),e=this._get_column_td(this.edited_column),t=this.get_editable_el(e),(l=t.data("widget")).focus_out(),(i=this.tree.columns[this.edited_column]).field.validate(this.record)?s.which==Sao.common.TAB_KEYCODE?(n=1,s.shiftKey&&(n=-1),null!==(n=this.next_column(this.edited_column,!0,n))&&(this.edited_column=n,e=this._get_column_td(n),t=this.get_editable_el(e),(l=t.data("widget")).focus())):s.which==Sao.common.UP_KEYCODE||s.which==Sao.common.DOWN_KEYCODE||s.which==Sao.common.RETURN_KEYCODE?(a=this.edited_column,this.record.validate(this.tree.get_fields()).then(e=>{if(e){var t,i,n,e=jQuery.when();this.tree.screen.group.parent?this.tree.screen.attributes.pre_validate&&(e=this.record.pre_validate()):e=this.record.save(),e.fail(function(){l.focus()}),!(t=s.which!=Sao.common.UP_KEYCODE&&(s.which==Sao.common.DOWN_KEYCODE||-1==this.tree.screen.new_position)?this.el.next("tr"):this.el.prev("tr")).length&&(s.which==Sao.common.RETURN_KEYCODE||s.which==Sao.common.UP_KEYCODE&&0==this.tree.screen.new_position||s.which==Sao.common.DOWN_KEYCODE&&-1==this.tree.screen.new_position)?(n=this.tree.screen.group,i=Sao.common.MODELACCESS.get(this.tree.screen.model_name),n=null!==this.tree.screen.size_limit&&n.length>=this.tree.screen.size_limit,this.tree.creatable&&i.create&&!n&&e.then(()=>this.tree.screen.new_()).then(e=>{var t=this.tree.attributes.sequence;t&&e.group.set_sequence(t,this.tree.screen.new_position)})):e.then(()=>{this._get_column_td(a,t).trigger("click").find(":input,[tabindex=0]").focus()})}else{var o=this.record.invalid_fields();for(r=0;r<this.tree.columns.length;r++)if(this.tree.columns[r].attributes.name in o){a=r;break}this._get_column_td(a).find(":input,[tabindex=0]").focus()}})):s.which==Sao.common.ESC_KEYCODE&&(this.tree.edit_row(null),this.get_static_el().show().find("[tabindex=0]").focus()):l.display(this.record,i.field))}}),Sao.View.Tree.Affix=Sao.class_(Object,{init:function(e,t){this.attributes=e,this.protocol=t||null,this.icon=e.icon,this.protocol&&!this.icon&&(this.icon="tryton-public")},get_cell:function(){var e;return this.protocol?((e=jQuery("<a/>",{target:"_blank",rel:"noreferrer noopener"})).append(jQuery("<img/>")),e.click({cell:e},this.clicked.bind(this))):this.icon?e=jQuery("<img/>"):(e=jQuery("<span/>")).attr("tabindex",0),e.addClass("column-affix"),e},render:function(o,s){s=s||this.get_cell();var e=()=>{var e,t,i,n=o.model.fields[this.attributes.name];if(n.set_state(o,["invisible"]),n.get_state_attrs(o).invisible?s.hide():s.show(),this.protocol){if(e=n.get(o),!jQuery.isEmptyObject(e))switch(this.protocol){case"email":e="mailto:"+e;break;case"callto":e="callto:"+e;break;case"sip":e="sip:"+e}s.attr("href",e)}if(this.icon)switch(e=this.icon in o.model.fields?o.model.fields[this.icon].get_client(o):this.icon,t=s.children("img").length?s.children("img"):s,"url"==this.attributes.icon_type?e?(this.attributes.url_size&&((i=new URL(e,window.location)).searchParams.set(this.attributes.url_size,20),e=i.href),t.attr("src",e)):t.removeAttr("src"):Sao.common.ICONFACTORY.get_icon_url(e).done(e=>{e?t.attr("src",e):t.removeAttr("src")}),this.attributes.border){case"rounded":t.addClass("img-rounded");break;case"circle":t.addClass("img-circle")}else e=(e=this.attributes.string||"")||n.get_client(o)||"",s.text(e)};return o.is_loaded(this.attributes.name)?e():o.load(this.attributes.name,!0,!1).done(e),s},clicked:function(e){e.stopPropagation()}}),Sao.View.Tree.Symbol=Sao.class_(Object,{class_:"column-symbol",init:function(e,t){this.attributes=e,this.position=t},get_cell:function(){return jQuery("<span/>",{class:this.class_,tabindex:0})},render:function(i,n){n=n||this.get_cell();var e=()=>{var e,t=i.model.fields[this.attributes.name];t.set_state(i,["invisible"]),!t.get_state_attrs(i).invisible&&(e=(t=t.get_symbol(i,this.attributes.symbol))[0],t=t[1],Math.round(t)===this.position)?(n.text(e),n.show()):(n.text(""),n.hide())};return i.is_loaded(this.attributes.name)?e():i.load(this.attributes.name,!0,!1).done(e),n}}),Sao.View.Tree.CharColumn=Sao.class_(Object,{class_:"column-char",init:function(e,t){this.type="field",this.model=e,this.field=e.fields[t.name],this.tree=null,this.attributes=t,this.prefixes=[],this.suffixes=[],this.header=null,this.footers=[]},get field_name(){return this.attributes.name},get model_name(){return this.model.name},get_cell:function(){return jQuery("<div/>",{class:this.class_,tabindex:0})},get_textual_value:function(e){return this.field.get_client(e)},update_text:function(e,t){t=this.get_textual_value(t);e.text(t).attr("title",t)},render:function(e,t){t=t||this.get_cell();var i=()=>{this.update_text(t,e),this.field.set_state(e),this.field.get_state_attrs(e).invisible?t.hide():t.show()},n=()=>{var e=Sao.i18n.gettext("#ERROR");t.text(e).attr("title",e)};return e.is_loaded(this.attributes.name)?(e.exception?n:i)():e.load(this.attributes.name,!0,!1).done(i).fail(n),t},set_visible:function(e){var t=this.footers.slice();t.push(this.header);for(const i of t)e?(i.show(),i.removeClass("invisible")):(i.hide(),i.addClass("invisible"))},get_visible:function(){return!this.header.hasClass("invisible")}}),Sao.View.Tree.TextColum=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-text"}),Sao.View.Tree.IntegerColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-integer",init:function(e,t){Sao.View.Tree.IntegerColumn._super.init.call(this,e,t),this.factor=Number(t.factor||1),this.grouping=Boolean(Number(t.grouping||1))},get_cell:function(){return Sao.View.Tree.IntegerColumn._super.get_cell.call(this)},get_textual_value:function(e){return this.field.get_client(e,this.factor,this.grouping)}}),Sao.View.Tree.FloatColumn=Sao.class_(Sao.View.Tree.IntegerColumn,{class_:"column-float"}),Sao.View.Tree.BooleanColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-boolean",get_cell:function(){return jQuery("<input/>",{type:"checkbox",class:this.class_,tabindex:0})},update_text:function(e,t){e.prop("checked",this.field.get(t))},render:function(e,t){var i=!t,n=(t=Sao.View.Tree.BooleanColumn._super.render.call(this,e,t),!0);return this.tree.editable&&(i&&t.on("click",null,{record:e,cell:t},this.clicked.bind(this)),i=this.field.get_state_attrs(e),n=this.attributes.readonly||i.readonly),t.prop("disabled",n),t},clicked:function(e){var t=e.data.record,i=e.data.cell,n=this.tree.screen.current_record,o=this.tree.get_fields();!n||n.validate(o,!1,!1,!0)?(n=i.prop("checked"),this.field.set_client(t,n)):e.preventDefault()}}),Sao.View.Tree.Many2OneColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-many2one",get_cell:function(){var e=Sao.View.Tree.Many2OneColumn._super.get_cell.call(this);return e.append(jQuery("<a/>",{href:"#"})),e},update_text:function(e,t){(e=e.children("a")).unbind("click"),Sao.View.Tree.Many2OneColumn._super.update_text.call(this,e,t),e.click(e=>{e.stopPropagation();e={};e.model=this.attributes.relation,e.res_id=this.field.get(t),e.mode=["form"],e.name=this.attributes.string,e.context=this.field.get_context(t),Sao.Tab.create(e)})}}),Sao.View.Tree.One2OneColumn=Sao.class_(Sao.View.Tree.Many2OneColumn,{class_:"column-one2one"}),Sao.View.Tree.SelectionColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-selection",init:function(e,t){Sao.View.Tree.SelectionColumn._super.init.call(this,e,t),Sao.common.selection_mixin.init.call(this),this.tree&&!this.tree.editable||this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e)},update_selection:function(e,t){this.selection||this.init_selection(),Sao.common.selection_mixin.update_selection.call(this,e,this.field,t)},get_textual_value:function(e){var t=this.field.name+":string";if(!this.tree.editable&&t in e._values)return e._values[t];var i=this.field.get(e);for(const n of this.selection)if(n[0]===i)return n[1];return i},update_text:function(o,s){var e;!this.tree.editable&&this.field.name+":string"in s._values?(e=this.get_textual_value(s),o.text(e).attr("title",e)):this.update_selection(s,()=>{var e,t=this.field.get(s),i=!1;for(const n of this.selection)if(n[0]===t){i=!0,e=n[1];break}(i?jQuery.when(e):Sao.common.selection_mixin.get_inactive_selection.call(this,t).then(function(e){return e[1]})).done(e=>{o.text(e).attr("title",e)})})}}),Sao.View.Tree.MultiSelectionColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-multiselection",init:function(e,t){Sao.View.Tree.MultiSelectionColumn._super.init.call(this,e,t),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e)},update_selection:function(e,t){Sao.common.selection_mixin.update_selection.call(this,e,this.field,t)},get_textual_value:function(e){var t=this.field.name+":string";return!this.tree.editable&&t in e._values?e._values[t]:this.field.get_eval(e).map(e=>{for(const t of this.selection)if(t[0]===e)return t[1];return""}).join(";")},update_text:function(t,i){var e;!this.tree.editable&&this.field_name+":string"in i._values?(e=this.get_textual_value(i),t.text(e).attr("title",e)):this.update_selection(i,()=>{var e=this.get_textual_value(i);t.text(e).attr("title",e)})}}),Sao.View.Tree.ReferenceColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-reference",init:function(e,t){Sao.View.Tree.ReferenceColumn._super.init.call(this,e,t),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(e){Sao.common.selection_mixin.init_selection.call(this,e)},update_selection:function(e,t){Sao.common.selection_mixin.update_selection.call(this,e,this.field,t)},get_cell:function(){var e=Sao.View.Tree.ReferenceColumn._super.get_cell.call(this);return e.append(jQuery("<a/>",{href:"#"})),e},get_textual_value:function(e){var t,i,e=Sao.View.Tree.ReferenceColumn._super.get_textual_value.call(this,e),e=e?(t=e[0],e[1]):t="";if(t){for(const n of this.selection)if(n[0]===t){t=n[1];break}i=t+","+e}else i=e;return i},update_text:function(t,i){(t=t.children("a")).unbind("click"),this.update_selection(i,()=>{var e=this.get_textual_value(i);t.text(e).attr("title",e),t.click(e=>{e.stopPropagation();var e=this.field.get(i);e&&(e={model:e.split(",")[0],res_id:parseInt(e.split(",")[1],10),mode:["form"],name:this.attributes.string,context:this.field.get_context(i)},Sao.Tab.create(e))})})}}),Sao.View.Tree.DictColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-dict",get_textual_value:function(e){return"("+Object.keys(this.field.get_client(e)).length+")"}}),Sao.View.Tree.DateColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-date",get_textual_value:function(e){var t=this.field.get_client(e),e=this.field.date_format(e);return Sao.common.format_date(e,t)}}),Sao.View.Tree.TimeColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-time",get_textual_value:function(e){var t=this.field.get_client(e);return Sao.common.format_time(this.field.time_format(e),t)}}),Sao.View.Tree.TimeDeltaColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-timedelta"}),Sao.View.Tree.One2ManyColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-one2many",get_textual_value:function(e){return"( "+this.field.get_client(e).length+" )"}}),Sao.View.Tree.Many2ManyColumn=Sao.class_(Sao.View.Tree.One2ManyColumn,{class_:"column-many2many"}),Sao.View.Tree.BinaryColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-binary",init:function(e,t){Sao.View.Tree.BinaryColumn._super.init.call(this,e,t),this.filename=t.filename||null},get_cell:function(){var e=Sao.View.Tree.BinaryColumn._super.get_cell.call(this);return jQuery("<span/>").appendTo(e),e},get_textual_value:function(e){e=this.field.get_size?this.field.get_size(e):this.field.get(e).length;return e?Sao.common.humanize(e,"B"):""},update_text:function(e,t){var i=this.get_textual_value(t),n=(e.children("span").text(i).attr("title",i),e.children("button"));n.length||(n=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button",title:Sao.i18n.gettext("Save As...")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-download")).appendTo(e).click(t,e=>{e.stopPropagation(),this.save_as(e.data)})),i?n.show():n.hide()},save_as:function(e){var t,i=e.model.fields[this.filename];i&&(t=i.get_client(e),Sao.common.guess_mimetype(t)),(this.field.get_data?this.field.get_data(e):jQuery.when(this.field.get(e))).done(e=>{Sao.common.download_file(e,t)})}}),Sao.View.Tree.ImageColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-image",get_cell:function(){var e=jQuery("<img/>",{class:this.class_+" center-block",tabindex:0});return this.height=parseInt(this.attributes.height||100,10),this.width=parseInt(this.attributes.width||300,10),e.css("max-height",this.height),e.css("max-width",this.width),e.css("height","auto"),e.css("width","auto"),e},render:function(i,n){n=n||this.get_cell();var e=()=>{var e=e=>{n.attr("src",Sao.common.image_url(e))},t=this.field.get_client(i);!t||t>Sao.config.image_max_size?e(null):this.field.get_data(i).done(e)},t=()=>{n.attr("src",null)};return i.is_loaded(this.attributes.name)?(e.exception?t:e)():i.load(this.attributes.name,!0,!1).done(e).fail(t),n}}),Sao.View.Tree.URLColumn=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-url",render:function(e,t){return t=Sao.View.Tree.URLColumn._super.render.call(this,e,t),this.field.set_state(e),this.field.get_state_attrs(e).readonly?t.hide():t.show(),t}}),Sao.View.Tree.ProgressBar=Sao.class_(Sao.View.Tree.CharColumn,{class_:"column-progressbar",get_cell:function(){var e=jQuery("<div/>",{class:this.class_+" progress",tabindex:0});return jQuery("<div/>",{class:"progress-bar",role:"progressbar","aria-valuemin":0,"aria-valuemax":100}).appendTo(e).css("min-width: 2em"),e},get_textual_value:function(e){e=this.field.get_client(e,100);return e=e&&Sao.i18n.gettext("%1%",e)},update_text:function(e,t){var i=this.get_textual_value(t),t=this.field.get(t)||0,e=e.find(".progress-bar");e.attr("aria-valuenow",100*t),e.css("width",100*t+"%"),e.text(i).attr("title",i)}}),Sao.View.Tree.ButtonColumn=Sao.class_(Object,{init:function(e,t){this.view=e,this.type="button",this.attributes=t,this.footers=[]},render:function(e,t){var i=new Sao.common.Button(this.attributes,t,"btn-sm");t||i.el.click([e,i],this.button_clicked.bind(this)),jQuery.map(this.view.screen.model.fields,function(e,t){if("eager"==(e.description.loading||"eager"))return t});return i.set_state(e),i.el},set_visible:function(e){var t=this.footers.slice();t.push(this.header);for(const i of t)e?(i.show(),i.removeClass("invisible")):(i.hide(),i.addClass("invisible"))},get_visible:function(){return!this.header.hasClass("invisible")},button_clicked:function(e){var t=e.data[0],e=e.data[1];if(t!=this.view.screen.current_record)return!0;var i=t.expr_eval(this.attributes.states||{});i.invisible||i.readonly||(e.el.prop("disabled",!0),(i=this.view.rows.find(function(e){return e.record==t}))&&(i._drawed_record=null),this.view.screen.button(this.attributes))}}),Sao.View.TreeXMLViewParser.WIDGETS={binary:Sao.View.Tree.BinaryColumn,boolean:Sao.View.Tree.BooleanColumn,callto:Sao.View.Tree.URLColumn,char:Sao.View.Tree.CharColumn,date:Sao.View.Tree.DateColumn,dict:Sao.View.Tree.DictColumn,email:Sao.View.Tree.URLColumn,float:Sao.View.Tree.FloatColumn,image:Sao.View.Tree.ImageColumn,integer:Sao.View.Tree.IntegerColumn,many2many:Sao.View.Tree.Many2ManyColumn,many2one:Sao.View.Tree.Many2OneColumn,numeric:Sao.View.Tree.FloatColumn,one2many:Sao.View.Tree.One2ManyColumn,one2one:Sao.View.Tree.One2OneColumn,progressbar:Sao.View.Tree.ProgressBar,reference:Sao.View.Tree.ReferenceColumn,selection:Sao.View.Tree.SelectionColumn,multiselection:Sao.View.Tree.MultiSelectionColumn,sip:Sao.View.Tree.URLColumn,text:Sao.View.Tree.TextColum,time:Sao.View.Tree.TimeColumn,timedelta:Sao.View.Tree.TimeDeltaColumn,url:Sao.View.Tree.URLColumn},Sao.View.EditableTree={},Sao.View.EditableTree.editable_mixin=function(e){e.el.on("keydown",function(e){e.which!=Sao.common.TAB_KEYCODE&&e.which!=Sao.common.UP_KEYCODE&&e.which!=Sao.common.DOWN_KEYCODE&&e.which!=Sao.common.ESC_KEYCODE&&e.which!=Sao.common.RETURN_KEYCODE||this.focus_out()}.bind(e))},Sao.View.EditableTree.Char=Sao.class_(Sao.View.Form.Char,{class_:"editabletree-char",init:function(e,t){Sao.View.EditableTree.Char._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.URL=Sao.class_(Sao.View.EditableTree.Char,{class_:"editable-url",set_readonly:function(e){Sao.View.EditableTree.URL._super.set_readonly.call(this,e),e?this.input.hide():this.input.show()}}),Sao.View.EditableTree.Date=Sao.class_(Sao.View.Form.Date,{class_:"editabletree-date",init:function(e,t){Sao.View.EditableTree.Date._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.Time=Sao.class_(Sao.View.Form.Time,{class_:"editabletree-time",init:function(e,t){Sao.View.EditableTree.Time._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.TimeDelta=Sao.class_(Sao.View.Form.TimeDelta,{class_:"editabletree-timedelta",init:function(e,t){Sao.View.EditableTree.TimeDelta._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.Integer=Sao.class_(Sao.View.Form.Integer,{class_:"editabletree-integer",init:function(e,t){delete(t=jQuery.extend({},t)).symbol,Sao.View.EditableTree.Integer._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)},get width(){}}),Sao.View.EditableTree.Float=Sao.class_(Sao.View.Form.Float,{class_:"editabletree-float",init:function(e,t){delete(t=jQuery.extend({},t)).symbol,Sao.View.EditableTree.Float._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)},get width(){}}),Sao.View.EditableTree.Selection=Sao.class_(Sao.View.Form.Selection,{class_:"editabletree-selection",init:function(e,t){Sao.View.EditableTree.Selection._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.Boolean=Sao.class_(Sao.View.Form.Boolean,{class_:"editabletree-boolean",init:function(e,t){Sao.View.EditableTree.Boolean._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.Many2One=Sao.class_(Sao.View.Form.Many2One,{class_:"editabletree-many2one",init:function(e,t){Sao.View.EditableTree.Many2One._super.init.call(this,e,t)}}),Sao.View.EditableTree.Reference=Sao.class_(Sao.View.Form.Reference,{class_:"editabletree-reference",init:function(e,t){Sao.View.EditableTree.Reference._super.init.call(this,e,t)}}),Sao.View.EditableTree.One2One=Sao.class_(Sao.View.Form.One2One,{class_:"editabletree-one2one",init:function(e,t){Sao.View.EditableTree.One2One._super.init.call(this,e,t)}}),Sao.View.EditableTree.One2Many=Sao.class_(Sao.View.EditableTree.Char,{class_:"editabletree-one2many",init:function(e,t){Sao.View.EditableTree.One2Many._super.init.call(this,e,t)},display:function(e,t){e?this.el.val("("+t.get_client(e).length+")"):this.el.val("")},key_press:function(e){e.which==Sao.common.TAB_KEYCODE&&this.focus_out()},set_value:function(e,t){}}),Sao.View.EditableTree.Binary=Sao.class_(Sao.View.Form.Binary,{class_:"editabletree-binary",init:function(e,t){Sao.View.EditableTree.Binary._super.init.call(this,e,t),Sao.View.EditableTree.editable_mixin(this)}}),Sao.View.EditableTree.WIDGETS={binary:Sao.View.EditableTree.Binary,boolean:Sao.View.EditableTree.Boolean,callto:Sao.View.EditableTree.URL,char:Sao.View.EditableTree.Char,date:Sao.View.EditableTree.Date,email:Sao.View.EditableTree.URL,float:Sao.View.EditableTree.Float,integer:Sao.View.EditableTree.Integer,many2many:Sao.View.EditableTree.Many2Many,many2one:Sao.View.EditableTree.Many2One,numeric:Sao.View.EditableTree.Float,one2many:Sao.View.EditableTree.One2Many,one2one:Sao.View.EditableTree.One2One,reference:Sao.View.EditableTree.Reference,selection:Sao.View.EditableTree.Selection,sip:Sao.View.EditableTree.URL,text:Sao.View.EditableTree.Char,time:Sao.View.EditableTree.Time,timedelta:Sao.View.EditableTree.TimeDelta,url:Sao.View.EditableTree.URL}}(),!function(){"use strict";Sao.View.GraphXMLViewParser=Sao.class_(Sao.View.XMLViewParser,{init:function(e,t,i){Sao.View.GraphXMLViewParser._super.init.call(this,e,t,i),this._xfield=null,this._yfields=[]},_node_attributes:function(e){var t={};for(const i of e.attributes)t[i.name]=i.value;return t.name&&!t.string&&"#"!=t.name&&(e=this.field_attrs[t.name],t.string=e.string),t},_parse_graph:function(e,t){for(const i of e.childNodes)this.parse(i);e=new Sao.View.GraphXMLViewParser.WIDGETS[t.type||"vbar"](this.view,this._xfield,this._yfields);this.view.el.append(e.el),this.view.widgets.root=e},_parse_x:function(e,t){for(const i of e.children)this._xfield=this._node_attributes(i)},_parse_y:function(e,t){for(const i of e.children)this._yfields.push(this._node_attributes(i))}}),Sao.View.Graph=Sao.class_(Sao.View,{editable:!1,view_type:"graph",xml_parser:Sao.View.GraphXMLViewParser,init:function(e,t,i,n){this.el=jQuery("<div/>",{class:"graph"}),Sao.View.Graph._super.init.call(this,e,t,i)},display:function(){return this.widgets.root.display(this.group)}}),Sao.View.Graph.Chart=Sao.class_(Object,{_chart_type:void 0,init:function(e,t,i){this.view=e,this.xfield=t,this.yfields=i,this.el=jQuery("<div/>"),this.el.uniqueId()},update_data:function(r){for(var l,c,d,h,u,_={},m=(this.ids={},_.columns=[["labels"]],_.names={},{}),e=[this.xfield.name],t=0,i=this.yfields.length;t<i;t++)c=this.yfields[t],d=c.key||c.name,_.columns.push([d]),_.names[d]=c.string,m[d]=t+1,e.push(c.name);var n=[],o=a=>()=>{var e,t,i=(l=r[a]).field_get_client(this.xfield.name),n=(i&&(i.isDate||i.isDateTime)&&(i=i.toString()),_.columns[0].indexOf(i));for(n<0&&(n=_.columns[0].push(i)-1),this._add_id(i,l.id),h=0,u=this.yfields.length;h<u;h++){if(c=this.yfields[h],d=c.key||c.name,void 0===(e=_.columns[m[d]])[n]&&(e[n]=null),c.domain){var o,s=jQuery.extend({},Sao.Session.current_session.context);for(o in(s.context=s)._user=Sao.Session.current_session.user_id,r.model.fields)s[o]=l.field_get(o);if(!new Sao.PYSON.Decoder(s).decode(c.domain))continue}e[n]||(e[n]=0),"#"==c.name?e[n]+=1:((t=l.field_get(c.name))&&t.isTimeDelta&&(t=t.asSeconds()),e[n]+=t||0)}},s=[];for(t=0,i=r.length;t<i;t++){l=r[t];for(const a of e)n.push(l.load(a));s.push(jQuery.when.apply(jQuery,n).then(o(t)))}return jQuery.when.apply(jQuery,s).then(function(){return _})},_add_id:function(e,t){e in this.ids||(this.ids[e]=[]),this.ids[e].push(t)},display:function(e){e=this.update_data(e);return e.done(e=>{c3.generate(this._c3_config(e))}),e},_c3_config:function(e){for(var t,i,n,o={},e=(o.bindto="#"+this.el.attr("id"),o.data=e,o.data.type=this._chart_type,o.data.x="labels",o.data.onclick=this.action.bind(this),this.view.screen.model.fields[this.xfield.name].description.type),e=("date"==e||"datetime"==e?(t=Sao.common.date_format(this.view.screen.context.date_format),i="%X",e="datetime"==e?(o.data.xFormat="%Y-%m-%d %H:%M:%S",function(e){return Sao.common.format_datetime(t+" "+i,moment(e))}):(o.data.xFormat="%Y-%m-%d",function(e){return Sao.common.format_date(t,moment(e))}),o.axis={x:{type:"timeseries",tick:{format:e}}}):o.axis={x:{type:"category"}},this.view.attributes.color||Sao.config.graph_color),s=Sao.common.hex2rgb(Sao.common.COLOR_SCHEMES[e]||e),s=Math.max.apply(null,s),a=[],r=0;r<this.yfields.length;r++)n=this.yfields[r],a.push(n.key||n.name);var l=Sao.common.generateColorscheme(e,a,s/(a.length||1));for(r=0;r<this.yfields.length;r++)(n=this.yfields[r]).color&&(l[n.key||n.name]=n.color);return o.data.color=function(e,t){t=t.id||t;return l[t]||e},o},action:function(e,t){var e=this.ids[this._action_key(e)],i=jQuery.extend({},this.view.screen.group._context);delete i.active_ids,delete i.active_id,Sao.Action.exec_keyword("graph_open",{model:this.view.screen.model_name,id:e[0],ids:e},i,!1)},_action_key:function(e){var e=e.x,t=this.view.screen.model.fields[this.xfield.name].description.type;return e&&"datetime"==t?e=Sao.DateTime(e).toString():e&&"date"==t&&(e=Sao.Date(e).toString()),e}}),Sao.View.Graph.VerticalBar=Sao.class_(Sao.View.Graph.Chart,{_chart_type:"bar"}),Sao.View.Graph.HorizontalBar=Sao.class_(Sao.View.Graph.Chart,{_chart_type:"bar",_c3_config:function(e){e=Sao.View.Graph.HorizontalBar._super._c3_config.call(this,e);return e.axis.rotated=!0,e}}),Sao.View.Graph.Line=Sao.class_(Sao.View.Graph.Chart,{_chart_type:"line",_c3_config:function(e){e=Sao.View.Graph.Line._super._c3_config.call(this,e);return e.line={connectNull:!0},e}}),Sao.View.Graph.Pie=Sao.class_(Sao.View.Graph.Chart,{_chart_type:"pie",_c3_config:function(e){for(var t,i,n=Sao.View.Graph.Pie._super._c3_config.call(this,e),o=[],s={},a=0,r=e.columns.length;a<r;a++)"labels"==e.columns[a][0]?t=e.columns[a].slice(1):i=e.columns[a].slice(1);delete n.axis,delete n.data.x;var l,c,d,h,u=this.view.screen.model.fields[this.xfield.name].description.type;for("date"!=u&&"datetime"!=u||(l=Sao.common.date_format(this.view.screen.context.date_format),c=l+" %X",d="datetime"==u?function(e){return Sao.common.format_datetime(c,e)}:function(e){return Sao.common.format_date(l,e)}),a=0,r=t.length;a<r;a++)h=t[a],d&&(h=d(h)),o.push([a,i[a]]),s[a]=h;return n.data.columns=o,n.data.names=s,n},_add_id:function(e,t){var i,n=this.xfield.type;"date"!=n&&"datetime"!=n||(i=Sao.common.date_format(this.view.screen.context.date_format),e="datetime"==n?Sao.common.format_datetime(i+" %X",e):Sao.common.format_date(i,e)),Sao.View.Graph.Pie._super._add_id.call(this,e,t)},_action_key:function(e){return e.id}}),Sao.View.GraphXMLViewParser.WIDGETS={hbar:Sao.View.Graph.HorizontalBar,line:Sao.View.Graph.Line,pie:Sao.View.Graph.Pie,vbar:Sao.View.Graph.VerticalBar}}(),!function(){"use strict";function i(e){var t,i=window.innerHeight-15;e.parents(".modal-body").length&&(t=parseInt(e.parents(".modal-body").css("max-height"),10),isNaN(t)?i-=200:i=t),i-=e.find(".fc-toolbar").height(),e.parents(".panel-body").each(function(e,t){t=jQuery(t),i=(i-=parseInt(t.css("padding-top"),10))-parseInt(t.css("padding-bottom"),10)}),e.parents(".panel").each(function(e,t){t=(t=jQuery(t)).css("box-shadow").match(/\d+px/g);t&&t.length&&(t=t.map(function(e){return e=parseInt(e,10),isNaN(e)?0:e}),i-=Math.max.apply(null,t))}),i-=e[0].getBoundingClientRect().y,e.fullCalendar("option","contentHeight",i)}jQuery(window).resize(function(){jQuery(".calendar").each(function(e,t){i(jQuery(t))})}),Sao.View.CalendarXMLViewParser=Sao.class_(Sao.View.XMLViewParser,{_parse_calendar:function(e,t){for(const o of e.childNodes)this.parse(o);var e="datetime"==this.view.screen.model.fields[t.dtstart].description.type?"agendaWeek":"basicWeek",i="datetime"==this.view.screen.model.fields[t.dtstart].description.type?"agendaDay":"basicDay",n="month",e=("week"==t.mode&&(n=e),"day"==t.mode&&(n=i),{left:"today prev,next",center:"title",right:"month,"+e+","+i});Sao.i18n.rtl&&((i=jQuery.extend({},e)).left=e.right,i.right=e.left,e=i),this.view.el.fullCalendar({defaultView:n,header:e,timeFormat:"H:mm",scrollTime:(this.view.screen.context.calendar_scroll_time||Sao.Time(6)).toString(),events:this.view.get_events.bind(this.view),locale:Sao.i18n.getlang().slice(0,2),isRTL:Sao.i18n.rtl,themeSystem:"bootstrap3",bootstrapGlyphicons:{prev:"chevron-"+(Sao.i18n.rtl?"right":"left"),next:"chevron-"+(Sao.i18n.rtl?"left":"right")},buttonTextOverride:{today:Sao.i18n.gettext("Today"),month:Sao.i18n.gettext("Month"),week:Sao.i18n.gettext("Week"),day:Sao.i18n.gettext("Day")},eventRender:this.view.event_render.bind(this.view),eventResize:this.view.event_resize.bind(this.view),eventDrop:this.view.event_drop.bind(this.view),eventClick:this.view.event_click.bind(this.view),dayClick:this.view.day_click.bind(this.view)}),void 0!==t.height&&this.view.el.css("min-height",t.height+"px"),void 0!==t.width&&this.view.el.css("min-width",t.width+"px")},_parse_field:function(e,t){this.view.fields.push(t.name)}}),Sao.View.Calendar=Sao.class_(Sao.View,{editable:!1,creatable:!1,view_type:"calendar",xml_parser:Sao.View.CalendarXMLViewParser,init:function(e,t,i){this.processing=!0,this.fields=[],this.el=jQuery("<div/>",{class:"calendar"}),Sao.View.Calendar._super.init.call(this,e,t,i)},get_colors:function(e){var t={};return t.text_color=Sao.config.calendar_colors[0],this.attributes.color&&(t.text_color=e.field_get(this.attributes.color)),t.background_color=Sao.config.calendar_colors[1],this.attributes.background_color&&(t.background_color=e.field_get(this.attributes.background_color)),t},display:function(){this.el.fullCalendar("render"),i(this.el),this.processing||this.el.fullCalendar("refetchEvents")},insert_event:function(e){var t,i=jQuery.extend([],this.fields),n=i.shift(),n=this.screen.model.fields[n].get_client(e),o=e.model.fields[this.attributes.dtstart],s=o.get_client(e),a=(o.set_state(e),null),r=(this.attributes.dtend&&(a=(t=e.model.fields[this.attributes.dtend]).get_client(e),t.set_state(e)),Sao.common.MODELACCESS.get(this.screen.model_name)),r=parseInt(this.attributes.editable||1,10)&&r.write,l=[];for(const c of i)l.push(this.screen.model.fields[c].get_client(e));l=l.join("\n"),s&&((i=s.isDate&&(!a||a.isDate))&&a&&!a.isSame(s)&&"calendar"==this.screen.current_view.view_type&&a.add(1,"day"),a&&a<s||(s={title:n,start:s,end:a,allDay:i,editable:r&&!o.get_state_attrs(e).readonly&&(!a||!t.get_state_attrs(e).readonly),color:(n=this.get_colors(e)).background_color,textColor:n.text_color,record:e,description:l},this.events.push(s)))},get_events:function(e,t,i,n){this.processing=!0,this.start=Sao.DateTime(e.utc()),this.end=Sao.DateTime(t.utc());var e=jQuery.when(),o=(this.screen.current_view&&"form"!=this.screen.current_view.view_type&&(t=this.screen.screen_container.get_text(),e=this.screen.search_filter(t)),this.events=[],[]);e.then(()=>(this.group.forEach(e=>{var t=[];for(const n of this.fields)t.push(e.load(n));var i=jQuery.when.apply(jQuery,t).then(()=>{this.insert_event(e)});o.push(i)}),jQuery.when.apply(jQuery,o).then(()=>{n(this.events)}).always(()=>{this.processing=!1})))},event_click:function(e,t,i){this.clicked_event||(this.clicked_event=!0,this.screen.current_record=e.record,this.screen.switch_view().always(()=>{this.clicked_event=!1}))},event_drop:function(e,t,i,n,o,s){var a=this.attributes.dtstart,r=this.attributes.dtend,l=e.record,c=(l.group,l.field_get(a)),d=c,h=(r&&(d=l.field_get(r)),e.start),e=e.end;e!=c&&e||(e=h),c.isDateTime?(e=Sao.DateTime(e.format()).utc(),h=Sao.DateTime(h.format()).utc()):c.isSame(d)||(e.subtract(1,"day"),this.el.fullCalendar("refetchEvents")),c<=h?(r&&l.field_set_client(r,e),l.field_set_client(a,h)):(l.field_set_client(a,h),r&&l.field_set_client(r,e)),l.save()},event_resize:function(e,t,i,n,o,s){var a=this.attributes.dtend,r=e.record,l=(r.group,r.field_get(a)),e=e.end;!0===l.isDateTime?e=Sao.DateTime(e.format()).utc():(e.subtract(1,"day"),this.el.fullCalendar("refetchEvents")),r.field_set_client(a,e=e!=l&&e?e:l),r.save()},event_render:function(e,t,i){this.screen.model.fields.date&&"calendar"==this.screen.view_name&&t.find(".fc-time").remove(),t.find(".fc-content").append(jQuery("<div/>",{class:"fc-description"}).text(e.description)),t.css("white-space","pre").css("overflow","hidden").css("text-overflow","ellipsis").attr("title",[e.title,e.description].filter(function(e){return e}).join("\n"))},day_click:function(e,t,i){var n=Sao.common.MODELACCESS.get(this.screen.model_name);parseInt(this.attributes.editable||1,10)&&n.create&&(this.el.fullCalendar("gotoDate",e),this.screen.current_record=null,this.screen.new_())},current_domain:function(){var e,t,i,n;return this.start||this.end?(e=Sao.DateTime(this.start),t=Sao.DateTime(this.end),[[i=this.attributes.dtstart,"!=",null],[n=this.attributes.dtend||i,"!=",null],["OR",["AND",[i,">=",e],[i,"<",t]],["AND",[n,">=",e],[n,"<",t]],["AND",[i,"<",e],[n,">",t]]]]):[["id","=",-1]]},get_displayed_period:function(){var e=[];return this.start&&this.end&&e.push(this.start,this.end),e},set_default_date:function(e,t){var i=this.attributes.dtstart,n=e.model.fields[i];n instanceof Sao.field.DateTime?t=Sao.DateTime(t):n instanceof Sao.field.Date&&(t=Sao.Date(t)),n.set(e,t),e.on_change([i]),e.on_change_with([i])},get_selected_date:function(){return this.el.fullCalendar("getDate")},get listed_records(){return this.events.map(e=>e.record)}})}(),!function(){"use strict";Sao.View.ListGroupViewForm=Sao.class_(Sao.View.Form,{get record(){return this._record},set record(e){this._record=e},button_clicked:function(e){Sao.common.compare(this.screen.selected_records,[this.record])&&Sao.View.ListGroupViewForm._super.button_clicked.call(this,e)}}),Sao.View.ListForm=Sao.class_(Sao.View,{editable:!0,creatable:!0,view_type:"list-form",init:function(e,t,i){Sao.View.ListForm._super.init.call(this,e,t,i),this.attributes.creatable&&(this.creatable=Boolean(parseInt(this.attributes.creatable,10))),this.form_xml=i,this.el=jQuery("<ul/>",{class:"list-group list-form"}),this._view_forms=[]},display:function(e){var t,i,n,o=[],s=[],a=new Set;if(!jQuery.isEmptyObject(e))for(const l of e)a.add(l[0]);for(var r=0;r<this.group.length;r++)t=this.group[r],(i=this._view_forms[r])?(n=i.el.parent(),i.record=t):(n=this._create_form(t),s.push(n),i=this._view_forms[this._view_forms.length-1]),~this.group.record_deleted.indexOf(t)||~this.group.record_removed.indexOf(t)?n.addClass("disabled"):n.removeClass("disabled"),this.record===t||a.has(t.id)?n.addClass("list-group-item-selected"):n.removeClass("list-group-item-selected"),o.push(i.display());return 0<s.length&&this.el.append(s),e=this._view_forms.splice(this.group.length),jQuery(e.map(function(e){return e.el[0]})).parent().detach(),jQuery.when.apply(jQuery,o)},get_selected_paths:function(){var e=[];for(const t of this._view_forms)t.el.parent().hasClass("list-group-item-selected")&&e.push([t.record.id]);return e},_create_form:function(e){var t=new Sao.View.ListGroupViewForm(this.view_id,this.screen,this.form_xml),e=(t.record=e,this._view_forms.push(t),jQuery("<li/>",{class:"list-group-item list-form-item"}));return e.append(t.el),e.click(this._view_forms.length-1,this._select_row.bind(this)),e},get selected_records(){var e=[];for(const t of this._view_forms)t.el.parent().hasClass("list-group-item-selected")&&e.push(t.record);return e},get listed_records(){return this.group.slice()},set_cursor:function(e,t){e&&this.el.animate({scrollTop:this.el[0].scrollHeight})},select_records:function(e,t){if(jQuery(this._view_forms.map(function(e){return e.el[0]})).parent().removeClass("list-group-item-selected"),null!==e||null!==t){var i;(t=t||0)<(e=e||0)&&(i=e,e=t,t=i);for(const n of this._view_forms.slice(e,t+1))n.el.parent().addClass("list-group-item-selected")}},_select_row:function(e){var n=e.data,o=this._view_forms[n],t=jQuery.when();this.record&&o.record!=this.record&&(this.screen.group.parent?this.screen.attributes.pre_validate&&(t=this.record.pre_validate()):t=this.record.validate(this.get_fields(),!1,!1,!1)?this.record.save():jQuery.Deferred().reject()),t.done(()=>{var t;if(e.shiftKey){let e=0;for(const i of this._view_forms){if(i.record===this.record){t=i;break}e++}this.select_records(e,n)}else e.ctrlKey||e.metaKey||this.select_records(null,null),this.record=o.record,o.el.parent().toggleClass("list-group-item-selected");t&&(this.record=t.record)})}})}(),!function(){"use strict";Sao.Action={report_blob_url:void 0},Sao.Action.exec_action=function(e,n,t){t=t?jQuery.extend({},t):{};var i=Sao.Session.current_session;function o(t,e){var i;return n.model&&n.ids&&(i=n.ids.filter(function(e){return 0<=e}).slice(0,5)).length?Sao.rpc({method:"model."+n.model+".read",params:[i,["rec_name"],e]},Sao.Session.current_session).then(function(e){e=e.map(function(e){return e.rec_name}).join(Sao.i18n.gettext(", "));return n.ids.length>i.length&&(e+=Sao.i18n.gettext(",...")),e?Sao.i18n.gettext("%1 (%2)",t,e):t}):jQuery.when(t)}n=void 0===n?{}:jQuery.extend({},n),delete t.active_id,delete t.active_ids,delete t.active_model,n.action_id=e.id;var s={icon:e["icon.rec_name"]||""};switch(e.type){case"ir.action.act_window":if(jQuery.isEmptyObject(e.views))jQuery.isEmptyObject(e.view_id)||(s.view_ids=[e.view_id[0]]);else{s.view_ids=[],s.mode=[];for(const l of e.views)s.view_ids.push(l[0]),s.mode.push(l[1])}void 0===e.pyson_domain&&(e.pyson_domain="[]");var a={active_model:n.model||null,active_id:n.id||null,active_ids:n.ids||[]},r=((a=jQuery.extend(a,i.context))._user=i.user_id,new Sao.PYSON.Decoder(a));s.context=jQuery.extend({},t,r.decode(e.pyson_context||"{}")),(a=jQuery.extend(a,s.context)).context=a,r=new Sao.PYSON.Decoder(a),s.domain=r.decode(e.pyson_domain),s.order=r.decode(e.pyson_order),s.search_value=r.decode(e.pyson_search_value||"[]"),s.tab_domain=[];for(const c of e.domains)s.tab_domain.push([c[0],r.decode(c[1]),c[2]]);return a=jQuery.when(e.name),s.model=e.res_model||n.res_model,s.res_id=e.res_id||n.res_id,s.context_model=e.context_model,s.context_domain=e.context_domain,void 0!==e.limit&&null!==e.limit&&(s.limit=e.limit),void(a=e.keyword?o(e.name,s.context):a).then(function(e){s.name=e,Sao.Tab.create(s)});case"ir.action.wizard":return s.action=e.wiz_name,s.data=n,s.context=t,s.window=e.window,a=jQuery.when(e.name),void(a="form_action"===(e.keyword||"form_action")?o(e.name,t):a).done(function(e){s.name=e,Sao.Wizard.create(s)});case"ir.action.report":return s.name=e.report_name,s.data=n,s.direct_print=e.direct_print,s.context=t,void Sao.Action.exec_report(s);case"ir.action.url":return void window.open(e.url,"_blank","noreferrer,noopener")}},Sao.Action.exec_keyword=function(e,o,s,a=!0,r=!1){var t=o.id,e={method:"model.ir.action.keyword.get_keyword",params:[e,[o.model,t],{}]};return Sao.rpc(e,Sao.Session.current_session).pipe(function(e){var t,i={};for(t in e){var n=e[t];i[n.name.split(" / ").pop()]=n}return Sao.common.selection(Sao.i18n.gettext("Select your action"),i,r).then(function(e){Sao.Action.exec_action(e,o,s)},function(){jQuery.isEmptyObject(i)&&a&&alert(Sao.i18n.gettext("No action defined."))})})},Sao.Action.exec_report=function(e){e.context||(e.context={});var t=jQuery.extend({},e.data),i=jQuery.extend({},Sao.Session.current_session.context);jQuery.extend(i,e.context),i.direct_print=e.direct_print,Sao.rpc({method:"report."+e.name+".execute",params:[t.ids||[],t,i]},Sao.Session.current_session).done(function(e){var t=e[0],i=e[1],e=(e[2],e[3]);Sao.common.download_file(i,e+"."+t)})},Sao.Action.execute=function(e,t,i,n){"number"==typeof e&&(e=Sao.rpc({method:"model.ir.action.get_action_value",params:[e,i]},Sao.Session.current_session,!1)),n&&!e.keyword&&(e.keyword={"ir.action.report":"form_report","ir.action.wizard":"form_action","ir.action.act_window":"form_relate"}[e.type]),Sao.Action.exec_action(e,t,i)},Sao.Action.evaluate=function(e,t,i){var n={};return"subject"in(n="pyson_email"in(e=jQuery.extend({},e))&&(n=i.expr_eval(e.pyson_email),jQuery.isEmptyObject(n))?{}:n)||(n.subject=e.name.replace(/_/g,"")),e.email=n,e}}(),!function(){"use strict";var n=["866","ansi_x3.4-1968","arabic","ascii","asmo-708","big5","big5-hkscs","chinese","cn-big5","cp1250","cp1251","cp1252","cp1253","cp1254","cp1255","cp1256","cp1257","cp1258","cp819","cp866","csbig5","cseuckr","cseucpkdfmtjapanese","csgb2312","csibm866","csiso2022jp","csiso2022kr","csiso58gb231280","csiso88596e","csiso88596i","csiso88598e","csiso88598i","csisolatin1","csisolatin2","csisolatin3","csisolatin4","csisolatin5","csisolatin6","csisolatin9","csisolatinarabic","csisolatincyrillic","csisolatingreek","csisolatinhebrew","cskoi8r","csksc56011987","csmacintosh","csshiftjis","cyrillic","dos-874","ecma-114","ecma-118","elot_928","euc-jp","euc-kr","gb18030","gb2312","gb_2312","gb_2312-80","gbk","greek","greek8","hebrew","hz-gb-2312","ibm819","ibm866","iso-2022-cn","iso-2022-cn-ext","iso-2022-jp","iso-2022-kr","iso-8859-1","iso-8859-10","iso-8859-11","iso-8859-13","iso-8859-14","iso-8859-15","iso-8859-16","iso-8859-2","iso-8859-3","iso-8859-4","iso-8859-5","iso-8859-6","iso-8859-6-e","iso-8859-6-i","iso-8859-7","iso-8859-8","iso-8859-8-e","iso-8859-8-i","iso-8859-9","iso-ir-100","iso-ir-101","iso-ir-109","iso-ir-110","iso-ir-126","iso-ir-127","iso-ir-138","iso-ir-144","iso-ir-148","iso-ir-149","iso-ir-157","iso-ir-58","iso8859-1","iso8859-10","iso8859-11","iso8859-13","iso8859-14","iso8859-15","iso8859-2","iso8859-3","iso8859-4","iso8859-5","iso8859-6","iso8859-7","iso8859-8","iso8859-9","iso88591","iso885910","iso885911","iso885913","iso885914","iso885915","iso88592","iso88593","iso88594","iso88595","iso88596","iso88597","iso88598","iso88599","iso_8859-1","iso_8859-15","iso_8859-1:1987","iso_8859-2","iso_8859-2:1987","iso_8859-3","iso_8859-3:1988","iso_8859-4","iso_8859-4:1988","iso_8859-5","iso_8859-5:1988","iso_8859-6","iso_8859-6:1987","iso_8859-7","iso_8859-7:1987","iso_8859-8","iso_8859-8:1988","iso_8859-9","iso_8859-9:1989","koi","koi8","koi8-r","koi8-ru","koi8-u","koi8_r","korean","ks_c_5601-1987","ks_c_5601-1989","ksc5601","ksc_5601","l1","l2","l3","l4","l5","l6","l9","latin1","latin2","latin3","latin4","latin5","latin6","logical","mac","macintosh","ms932","ms_kanji","shift-jis","shift_jis","sjis","sun_eu_greek","tis-620","unicode-1-1-utf-8","us-ascii","utf-16","utf-16be","utf-16le","utf-8","utf8","visual","windows-1250","windows-1251","windows-1252","windows-1253","windows-1254","windows-1255","windows-1256","windows-1257","windows-1258","windows-31j","windows-874","windows-949","x-cp1250","x-cp1251","x-cp1252","x-cp1253","x-cp1254","x-cp1255","x-cp1256","x-cp1257","x-cp1258","x-euc-jp","x-gbk","x-mac-cyrillic","x-mac-roman","x-mac-ukrainian","x-sjis","x-user-defined","x-x-big5"];Sao.Window={},Sao.Window.InfoBar=Sao.class_(Object,{init:function(){this.el=jQuery("<div/>",{class:"infobar"}),this.__messages=new Set},add:function(e,t,i){var n;i=i||null,e&&(n=JSON.stringify([e,t]),this.__messages.has(n)||(t=jQuery("<div/>",{class:"alert alert-dismissible alert-"+(t||"error"),role:"alert"}).append(jQuery("<button/>",{type:"button",class:"close","aria-label":Sao.i18n.gettext("Close"),title:Sao.i18n.gettext("Close"),"data-dismiss":"alert"}).append(jQuery("<span/>",{"aria-hidden":!0}).append("×"))).append(jQuery("<span/>").css("white-space","pre-wrap").text(e)).on("close.bs.alert",null,n,this.__response.bind(this)),this.el.append(t),t.data("kind",i)))},__response:function(e){this.__messages.add(e.data)},refresh:function(i){i=i||null,this.el.children().each((e,t)=>{(t=jQuery(t)).data("kind")===i&&t.remove()})},clear:function(){var e=this.el.children().each((e,t)=>jQuery(t).data("kind"));new Set(e).forEach(e=>{this.refresh(e)}),this.__messages.clear()}}),Sao.Window.Form=Sao.class_(Object,{init:function(o,t,i){i=i||{},this.screen=o,this.callback=t,this.many=i.many||0,this.domain=i.domain||null,this.context=i.context||null,this.save_current=i.save_current;var n,e,s=jQuery.when(i.title||"").then(e=>{o.breadcrumb.length?(n=jQuery.extend([],o.breadcrumb),e&&n.push(e),this.title=n.slice(-3,-1).map(function(e){return Sao.common.ellipsize(e,30)}).concat(n.slice(-1)).join(" › "),3<n.length&&(this.title="... › "+this.title)):(e=e||Sao.common.MODELNAME.get(this.screen.model_name),this.title=e);var t,i,n=this.screen.context._datetime;return n&&Sao.common.MODELHISTORY.contains(this.screen.model_name)?(t=Sao.common.date_format(this.screen.context.date_format),t=" @ "+Sao.common.format_datetime(t+" %H:%M:%S.%f",n),i=Sao.common.ellipsize(this.title,80-t.length)+t,e=this.title+t):i=Sao.common.ellipsize(this.title,80),i}),a=(this.prev_view=o.current_view,this.screen.screen_container.alternate_view=!0,this.info_bar=new Sao.Window.InfoBar,i.view_type||"form"),r=(this.switch_prm=this.screen.switch_view(a).done(()=>{i.new_&&this.screen.current_view.view_type==a&&this.screen.new_(void 0,i.defaults)}),new Sao.Dialog("","window-form","lg",!1)),t=(this.dialog=r,this.el=r.modal,this.el.on("keydown",e=>{e.which==Sao.common.ESC_KEYCODE&&(e.preventDefault(),this.response("RESPONSE_CANCEL"))}),this.screen.group.readonly);if(this.but_ok=null,this.but_new=null,this._initial_value=null,"form"==(this.view_type=a)&&!t){let e;i.new_?e=Sao.i18n.gettext("Delete"):(e=Sao.i18n.gettext("Discard changes"),n=this.screen.current_record,this._initial_value=n.get_on_change_value(),n.group.parent&&n.model.fields[n.group.parent_name]&&(l=n.model.fields[n.group.parent_name],this._initial_value[n.group.parent_name]=l.get_eval(n))),r.footer.append(jQuery("<button/>",{class:"btn btn-link",type:"button",title:e}).text(e).click(()=>{this.response("RESPONSE_CANCEL")}))}if(i.new_&&this.many){let e;e=this.save_current&&!t?Sao.i18n.gettext("Save and New"):Sao.i18n.gettext("Add and New"),r.footer.append(jQuery("<button/>",{class:"btn btn-default",type:"button",title:e}).text(e).click(()=>{this.response("RESPONSE_ACCEPT")}))}if(this.save_current&&!t){var l=Sao.i18n.gettext("Save");this.but_ok=jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:l}).text(l).appendTo(r.footer)}else{let e;e=t||"tree"==a?Sao.i18n.gettext("Close"):i.new_?Sao.i18n.gettext("Add"):Sao.i18n.gettext("Apply changes"),this.but_ok=jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:e}).text(e).appendTo(r.footer)}r.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),"tree"==a&&(n=jQuery("<div/>",{class:"window-form-toolbar"}).appendTo(r.body),l=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(n),this.wid_text=jQuery("<input/>",{type:"input"}).appendTo(n),this.wid_text.hide(),n=jQuery("<div/>",{class:"input-group-btn"}).appendTo(l),l=Sao.common.MODELACCESS.get(this.screen.model_name),e=function(i){return function(e){var t=jQuery(e.target);t.prop("disabled",!0),(i(e)||jQuery.when()).always(function(){t.prop("disabled",!1)})}},this.but_switch=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Switch"),title:Sao.i18n.gettext("Switch")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-switch")).appendTo(n),this.but_switch.click(e(this.switch_.bind(this))),this.but_previous=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Previous"),title:Sao.i18n.gettext("Previous")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-back")).appendTo(n),this.but_previous.click(e(this.previous.bind(this))),this.label=jQuery("<span/>",{class:"badge"}).appendTo(jQuery("<span/>",{class:"btn hidden-xs"}).appendTo(n)),this.but_next=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Next"),title:Sao.i18n.gettext("Next")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-forward")).appendTo(n),this.but_next.click(e(this.next.bind(this))),this.domain&&(this.wid_text.show(),this.but_add=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Add"),title:Sao.i18n.gettext("Add")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).appendTo(n),this.but_add.click(e(this.add.bind(this))),this.but_add.prop("disabled",!l.read||t),this.but_remove=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Remove"),title:Sao.i18n.gettext("Remove")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).appendTo(n),this.but_remove.click(e(this.remove.bind(this))),this.but_remove.prop("disabled",!l.read||t)),this.but_new=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("New"),title:Sao.i18n.gettext("New")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-create")).appendTo(n),this.but_new.click(e(this.new_.bind(this))),this.but_new.prop("disabled",!l.create||t),this.but_del=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Delete"),title:Sao.i18n.gettext("Delete")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-delete")).appendTo(n),this.but_del.click(e(this.delete_.bind(this))),this.but_del.prop("disabled",!l.delete||t),this.but_undel=jQuery("<button/>",{class:"btn btn-default btn-sm",type:"button","aria-label":Sao.i18n.gettext("Undelete"),title:Sao.i18n.gettext("Undelete")}).append(Sao.common.ICONFACTORY.get_icon_img("tryton-undo")).appendTo(n),this.but_undel.click(e(this.undelete.bind(this))),this.but_undel.prop("disabled",!l.delete||t));var c=jQuery("<div/>").appendTo(r.body);r.body.append(this.info_bar.el),this.screen.windows.push(this),this.switch_prm.done(()=>{this.screen.current_view.view_type!=a?this.destroy():(s.done(r.add_title.bind(r)),c.append(this.screen.screen_container.alternate_viewport),this.el.modal("show"))}),this.el.on("shown.bs.modal",e=>{this.screen.display().done(()=>{this.screen.set_cursor()})}),this.el.on("hidden.bs.modal",function(e){jQuery(this).remove()})},record_message:function(e,t){var i,n,o,s;"tree"==this.view_type&&(i="_",n=Sao.common.MODELACCESS.get(this.screen.model_name),o=this.screen.deletable,s=this.screen.group.readonly,1<=e?(i=e,this.domain&&this.but_remove.prop("disabled",!1),this.but_next.prop("disabled",t<=e),this.but_previous.prop("disabled",e<=1),this.but_del.prop("disabled",s||!n.delete||!o),this.but_undel.prop("disabled",s)):(this.but_del.prop("disabled",!0),this.but_undel.prop("disabled",!0),this.but_next.prop("disabled",!0),this.but_previous.prop("disabled",!0),this.domain&&this.but_remove.prop("disabled",!0)),this.label.text(e=i+"/"+t).attr("title",e))},record_modified:function(){this.info_bar.refresh()},add:function(){var e=jQuery.extend([],this.domain),t=this.screen.model_name,i=this.wid_text.val(),n=new Sao.common.DomainParser;new Sao.Window.Search(t,e=>{var t=jQuery.when();if(!jQuery.isEmptyObject(e)){var i=[];for(const n of e)i.push(n[0]);this.screen.group.load(i,!0),t=this.screen.display()}t.done(()=>{this.screen.set_cursor()}),this.entry.val("")},{sel_multi:!0,context:this.context,domain:e,search_filter:n.quote(i)})},remove:function(){this.screen.remove(!1,!0,!1)},new_:function(){this.screen.new_(),this._initial_value=null,--this.many,0==this.many&&this.but_new.addClass("disabled")},delete_:function(){this.screen.remove(!1,!1,!1)},undelete:function(){this.screen.unremove()},previous:function(){return this.screen.display_previous()},next:function(){return this.screen.display_next()},switch_:function(){return this.screen.switch_view()},response:function(a){this.screen.current_view.set_value();var e,r,t,i,n=this.screen.group.readonly;~["RESPONSE_OK","RESPONSE_ACCEPT"].indexOf(a)&&!n&&this.screen.current_record?this.screen.current_record.validate().then(e=>e&&this.screen.attributes.pre_validate?this.screen.current_record.pre_validate().then(()=>!0,()=>!1):e).then(e=>{var t=jQuery.Deferred();if(e&&this.save_current)this.screen.save_current().then(t.resolve,t.reject);else if(e&&"form"==this.screen.current_view.view_type){var i,n=this.screen.current_view,o=[];for(i in n.widgets){var s=n.widgets[i];s.screen&&s.screen.attributes.pre_validate&&(s=s.screen.current_record)&&o.push(s.pre_validate())}jQuery.when.apply(jQuery,o).then(t.resolve,t.reject)}else e?(this.info_bar.clear(),t.resolve()):(this.info_bar.add(this.screen.invalid_message(),"danger"),t.reject());t.fail(()=>{this.screen.display().done(()=>{this.screen.set_cursor()})}),t.done(()=>{"RESPONSE_ACCEPT"==a?(this.screen.new_(),this.screen.current_view.display().done(()=>{this.screen.set_cursor()}),--this.many,0===this.many&&this.but_new.prop("disabled",!0)):(r=!0,this.callback&&this.callback(r),this.destroy())})}):(e=null,"RESPONSE_CANCEL"==a&&!n&&this.screen.current_record?(r=!1,i=(t=this.screen.current_record).modified_fields.id,t.id<0||this.save_current?e=this.screen.cancel_current(this._initial_value):t.modified&&(t.cancel(),e=t.reload().then(()=>{this.screen.display()})),i&&(t.modified_fields.id=i)):r="RESPONSE_CANCEL"!=a&&!n,(e||jQuery.when()).then(()=>{this.callback&&this.callback(r),this.destroy()}))},destroy:function(){this.screen.windows.splice(this.screen.windows.indexOf(this),1),this.screen.screen_container.alternate_view=!1,this.screen.screen_container.alternate_viewport.children().detach(),this.prev_view&&this.screen.switch_view(this.prev_view.view_type),this.el.modal("hide")}}),Sao.Window.Attachment=Sao.class_(Sao.Window.Form,{init:function(e,t){this.resource=e.model.name+","+e.id,this.attachment_callback=t;var t=jQuery.extend({},e.get_context()),i=new Sao.Screen("ir.attachment",{domain:[["resource","=",this.resource]],mode:["tree","form"],context:t}),t=e.rec_name().then(function(e){return Sao.i18n.gettext("Attachments (%1)",e)});Sao.Window.Attachment._super.init.call(this,i,this.callback,{view_type:"tree",title:t}),this.switch_prm=this.switch_prm.then(function(){return i.search_filter()})},callback:function(e){var t=jQuery.when();e&&(t=this.screen.save_current()),this.attachment_callback&&t.always(this.attachment_callback.bind(this))},add_data:function(i,n){var o=this.screen;this.switch_prm.then(function(){o.new_().then(function(e){var t=e.model.fields.data;e.field_set_client(t.description.filename,n),e.field_set_client("data",i),o.display()})})},add_uri:function(t){var i=this.screen;this.switch_prm.then(function(){i.current_record=null,i.switch_view("form").then(function(){i.new_().then(function(e){e.field_set_client("link",t),e.field_set_client("type","link"),i.display()})})})},add_text:function(t){var i=this.screen;this.switch_prm.then(function(){i.current_record=null,i.switch_view("form").then(function(){i.new_().then(function(e){e.field_set_client("description",t),i.display()})})})}}),Sao.Window.Attachment.get_attachments=function(r){var l,e;e=r&&0<=r.id?(l=r.get_context(),Sao.rpc({method:"model.ir.attachment.search_read",params:[[["resource","=",r.model.name+","+r.id]],0,20,null,["rec_name","name","type","link"],l]},r.model.session)):jQuery.when([]);return e.then(function(e){return e.map(function(e){var t,i,n,o,s,a=e.rec_name;return"link"==e.type?[a,e.link]:(t=Sao.Window.Attachment["open_"+e.type],[a,(i=t,n=e,o=l,s=r.model.session,function(){return i(n,o,s)})])})})},Sao.Window.Attachment.open_data=function(t,e,i){Sao.rpc({method:"model.ir.attachment.read",params:[[t.id],["data"],e]},i).then(function(e){Sao.common.download_file(e[0].data,t.name)})},Sao.Window.Note=Sao.class_(Sao.Window.Form,{init:function(e,t){this.resource=e.model.name+","+e.id,this.note_callback=t;var t=jQuery.extend({},e.get_context()),i=new Sao.Screen("ir.note",{domain:[["resource","=",this.resource]],mode:["tree","form"],context:t}),t=e.rec_name().then(function(e){return Sao.i18n.gettext("Notes (%1)",e)});Sao.Window.Note._super.init.call(this,i,this.callback,{view_type:"tree",title:t}),this.switch_prm=this.switch_prm.then(function(){return i.search_filter()})},callback:function(e){var t=jQuery.when();if(e){var i=this.screen.group.model.fields.unread;for(const n of this.screen.group)!(n.get_loaded()||n.id<0)||n.modified_fields.unread||i.set_client(n,!1);t=this.screen.save_current()}this.note_callback&&t.always(this.note_callback.bind(this))}}),Sao.Window.Log=Sao.class_(Sao.Window.Form,{init:function(e){this.resource=e.model.name+","+e.id;var t=e.rec_name().then(function(e){return Sao.i18n.gettext("Logs (%1)",e)}),i=jQuery.extend({},e.get_context()),n=jQuery("<div/>",{class:"form"}),o=jQuery("<table/>",{class:"form-container responsive responsive-noheader"}).appendTo(n),c=jQuery("<tbody/>").appendTo(o),s=(e.model.execute("read",[[e.id],["create_uid.rec_name","create_date","write_uid.rec_name","write_date"]],i).then(([o])=>{var s,a=jQuery("<tr/>").appendTo(c),r=jQuery("<td/>").css("text-align","end").appendTo(a),l=jQuery("<label/>",{class:"form-label",text:Sao.i18n.gettext("Model:")}).appendTo(r);l.uniqueId(),r=jQuery("<td/>").appendTo(a),(s=jQuery("<input/>",{readonly:!0,class:"form-control input-sm","aria-labelledby":l.attr("id")}).val(e.model.name).appendTo(r)).uniqueId(),r=jQuery("<td/>").css("text-align","end").appendTo(a),(l=jQuery("<label/>",{class:"form-label",text:Sao.i18n.gettext("ID:")}).appendTo(r)).uniqueId(),r=jQuery("<td/>").appendTo(a),(s=jQuery("<input/>",{type:"integer",readonly:!0,class:"form-control input-sm","aria-labelledby":l.attr("id")}).val(e.id).appendTo(r)).css("text-align","end"),s.uniqueId(),[["create_uid.",Sao.i18n.gettext("Created by:"),"create_date",Sao.i18n.gettext("Created at:")],["write_uid.",Sao.i18n.gettext("Last Modified by:"),"write_date",Sao.i18n.gettext("Last Modified at:")]].forEach(([e,t,i,n])=>{a=jQuery("<tr/>").appendTo(c),r=jQuery("<td/>").css("text-align","end").appendTo(a),(l=jQuery("<label/>",{class:"form-label",text:t}).appendTo(r)).uniqueId(),r=jQuery("<td/>").appendTo(a),e=(e=o[e])&&e.rec_name,(s=jQuery("<input/>",{readonly:!0,class:"form-control input-sm","aria-labelledby":l.attr("id")}).val(e||"").appendTo(r)).css("width","50ch"),s.uniqueId(),r=jQuery("<td/>").css("text-align","end").appendTo(a),(l=jQuery("<label/>",{class:"form-label",text:n}).appendTo(r)).uniqueId(),r=jQuery("<td/>").appendTo(a),i=(i=o[i])&&Sao.common.format_datetime(Sao.common.date_format()+" %H:%M:%S",i),(s=jQuery("<input/>",{readonly:!0,class:"form-control input-sm","aria-labelledby":l.attr("id")}).val(i||"").appendTo(r)).css("width",i.length+"ch"),s.uniqueId()})}),new Sao.Screen("ir.model.log",{domain:[["resource","=",this.resource]],mode:["tree","form"],context:i}));Sao.Window.Log._super.init.call(this,s,null,{view_type:"tree",title:t}),this.switch_prm=this.switch_prm.then(function(){return s.search_filter()}),this.dialog.body.prepend(n)}}),Sao.Window.Search=Sao.class_(Object,{init:function(e,t,i){var n=(i=i||{}).views_preload||{};this.model_name=e,this.domain=i.domain||[],this.context=i.context||{},this.order=i.order||null,this.view_ids=i.view_ids,this.views_preload=n,this.sel_multi=i.sel_multi,this.callback=t;var t=(t=i.title)||Sao.common.MODELNAME.get(e),o=(this.title=t,this.exclude_field=i.exclude_field||null,new Sao.Dialog(Sao.i18n.gettext("Search %1",this.title),"","lg",!1));this.el=o.modal,this.el.on("keydown",e=>{e.which==Sao.common.ESC_KEYCODE&&(e.preventDefault(),this.response("RESPONSE_CANCEL"))}),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(o.footer),jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("Find")}).text(Sao.i18n.gettext("Find")).click(()=>{this.response("RESPONSE_APPLY")}).appendTo(o.footer),i.new_&&Sao.common.MODELACCESS.get(e).create&&jQuery("<button/>",{class:"btn btn-default",type:"button",title:Sao.i18n.gettext("New")}).text(Sao.i18n.gettext("New")).click(()=>{this.response("RESPONSE_ACCEPT")}).appendTo(o.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).appendTo(o.footer),o.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),this.screen=new Sao.Screen(e,{mode:["tree"],context:this.context,domain:this.domain,order:this.order,view_ids:i.view_ids,views_preload:n,row_activate:this.activate.bind(this),readonly:!0,breadcrumb:[this.title]}),this.screen.load_next_view().done(()=>{this.screen.switch_view().done(()=>{this.sel_multi?this.screen.current_view.selection_mode=Sao.common.SELECTION_MULTIPLE:this.screen.current_view.selection_mode=Sao.common.SELECTION_SINGLE,o.body.append(this.screen.screen_container.el),this.el.modal("show"),this.screen.display(),void 0!==i.search_filter&&this.screen.search_filter(i.search_filter)})}),this.el.on("hidden.bs.modal",function(e){jQuery(this).remove()})},activate:function(){this.response("RESPONSE_OK")},response:function(e){var t,i,n,o,s=[];if("RESPONSE_OK"==e)t=this.screen.current_view.selected_records;else{if("RESPONSE_APPLY"==e)return void this.screen.search_filter(this.screen.screen_container.get_text());if("RESPONSE_ACCEPT"==e)return e=jQuery.extend([],this.view_ids),jQuery.isEmptyObject(e)||e.shift(),i=new Sao.Screen(this.model_name,{domain:this.domain,context:this.context,order:this.order,mode:["form"],view_ids:e,views_preload:this.views_preload,exclude_field:this.exclude_field}),this.el.modal("hide"),void new Sao.Window.Form(i,function(e){e?(e=i.current_record,this.callback([[e.id,e._values.rec_name||""]])):this.callback(null)}.bind(this),{new_:!0,save_current:!0})}if(t)for(n in t)o=t[n],s.push([o.id,o._values.rec_name||""]);this.callback(s),this.el.modal("hide")}}),Sao.Window.Preferences=Sao.class_(Object,{init:function(t){var i=new Sao.Dialog("Preferences","","lg");this.el=i.modal,jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).appendTo(i.footer),i.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),this.screen=new Sao.Screen("res.user",{mode:[]}),this.screen.attributes.readonly=!1,this.screen.group.readonly=!1,this.screen.group.skip_model_access=!0;const n=e=>{this.screen.current_record.cancel(),this.screen.current_record.set(e),this.screen.current_record.id=this.screen.model.session.user_id,this.screen.current_record.validate(null,!0).then(()=>{this.screen.display(!0)}),i.body.append(this.screen.screen_container.el),this.el.modal("show")};this.el.on("hidden.bs.modal",function(e){t(),jQuery(this).remove()}),this.screen.model.execute("get_preferences_fields_view",[],{}).then(e=>{this.screen.add_view(e),this.screen.switch_view().done(()=>{this.screen.new_(!1),this.screen.model.execute("get_preferences",[!1],{}).then(n,this.destroy)})},this.destroy)},response:function(e){var t=jQuery.when();(t="RESPONSE_OK"==e?this.screen.current_record.validate().then(e=>{if(e)return e=jQuery.extend({},this.screen.get()),this.screen.model.execute("set_preferences",[e],{})}):t).done(()=>{this.destroy()})},destroy:function(){this.el.modal("hide")}}),Sao.Window.Revision=Sao.class_(Object,{init:function(e,t,i){this.callback=i;var n,i=new Sao.Dialog(Sao.i18n.gettext("Revision"),"","lg"),i=(this.el=i.modal,jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(i.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).appendTo(i.footer),i.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),jQuery("<div/>",{class:"form-group"}).appendTo(i.body)),o=(jQuery("<label/>",{for:"revision",text:"Revision"}).appendTo(i),this.select=jQuery("<select/>",{class:"form-control",id:"revision",placeholder:Sao.i18n.gettext("Revision")}).appendTo(i),Sao.common.date_format());this.select.append(jQuery("<option/>",{value:null,text:""}));for(n of e){var s=n[2];n=n[0],this.select.append(jQuery("<option/>",{value:n.valueOf(),text:Sao.common.format_datetime(o+" %H:%M:%S.%f",n)+" "+s}))}t&&this.select.val(t.valueOf()),this.el.modal("show"),this.el.on("hidden.bs.modal",function(e){jQuery(this).remove()})},response:function(e){var t=null;"RESPONSE_OK"==e&&(t=(t=this.select.val())&&Sao.DateTime(parseInt(t,10))),this.el.modal("hide"),this.callback(t)}}),Sao.Window.CSV=Sao.class_(Object,{init:function(e){this.dialog=new Sao.Dialog(e,"csv","lg"),this.el=this.dialog.modal,this.fields={},this.fields_model={},jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(Sao.i18n.gettext("Cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(this.dialog.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(Sao.i18n.gettext("OK")).click(e=>{e.preventDefault(),this.response("RESPONSE_OK")}).appendTo(this.dialog.footer);var e=jQuery("<div/>",{class:"row"}).appendTo(this.dialog.body),t=jQuery("<div/>",{class:"col-md-5"}).append(jQuery("<div/>",{class:"panel panel-default"}).append(jQuery("<div/>",{class:"panel-heading"}).append(jQuery("<h3/>",{class:"panel-title",text:Sao.i18n.gettext("All Fields")})))).appendTo(e),t=(this.fields_all=jQuery("<ul/>",{class:"list-unstyled column-fields panel-body"}).css("cursor","pointer").appendTo(t.find(".panel")),this.model_populate(this._get_fields(this.screen.model_name)),this.view_populate(this.fields_model,this.fields_all),this.column_buttons=jQuery("<div/>",{class:"col-md-2"}).appendTo(e),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Add")}).text(" "+Sao.i18n.gettext("Add")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-add")).click(()=>{this.fields_all.find(".bg-primary").each((e,t)=>{this.sig_sel_add(t)})}).appendTo(this.column_buttons),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Remove")}).text(" "+Sao.i18n.gettext("Remove")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-remove")).click(()=>{this.fields_selected.children("li.bg-primary").remove()}).appendTo(this.column_buttons),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Clear")}).text(" "+Sao.i18n.gettext("Clear")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-clear")).click(()=>{this.fields_selected.empty()}).appendTo(this.column_buttons),jQuery("<hr>").appendTo(this.column_buttons),jQuery("<div/>",{class:"col-md-5"}).append(jQuery("<div/>",{class:"panel panel-default"}).append(jQuery("<div/>",{class:"panel-heading"}).append(jQuery("<h3/>",{class:"panel-title",text:Sao.i18n.gettext("Fields Selected")})))).appendTo(e)),e=(this.fields_selected=jQuery("<ul/>",{class:"list-unstyled column-fields panel-body"}).css("cursor","pointer").appendTo(t.find(".panel")),this.chooser_form=jQuery("<div/>",{class:"form-inline"}).appendTo(this.dialog.body),jQuery("<div/>",{}).appendTo(this.dialog.body)),t=(jQuery("<label/>",{text:Sao.i18n.gettext("CSV Parameters")}).append(jQuery("<span/>",{class:"caret"}).html(" ")).css("cursor","pointer").on("click",()=>{this.expander_csv.collapse("toggle")}).appendTo(e),this.expander_csv=jQuery("<div/>",{id:"expander_csv",class:"collapse form-inline"}).appendTo(e),jQuery("<label/>",{text:Sao.i18n.gettext("Delimiter:"),class:"control-label",for:"input-delimiter"})),e=",",e=(navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(e=";"),this.el_csv_delimiter=jQuery("<input/>",{type:"text",class:"form-control",id:"input-delimiter",size:"1",maxlength:"1",value:e}),jQuery("<div/>",{class:"form-group"}).append(t).append(this.el_csv_delimiter).appendTo(this.expander_csv),this.expander_csv.append(" "),jQuery("<label/>",{text:Sao.i18n.gettext("Quote Char:"),class:"control-label",for:"input-quotechar"}));this.el_csv_quotechar=jQuery("<input/>",{type:"text",class:"form-control",id:"input-quotechar",size:"1",maxlength:"1",value:'"'}),jQuery("<div/>",{class:"form-group"}).append(e).append(this.el_csv_quotechar).appendTo(this.expander_csv),this.expander_csv.append(" "),this.el.modal("show"),this.el.on("hidden.bs.modal",function(){jQuery(this).remove()})},_get_fields:function(e){return Sao.rpc({method:"model."+e+".fields_get"},this.session,!1)},on_row_expanded:function(e){var t=jQuery("<ul/>").css("list-style","none").insertAfter(e.view);this.children_expand(e),this.view_populate(e.children,t)},destroy:function(){this.el.modal("hide")}}),Sao.Window.Import=Sao.class_(Sao.Window.CSV,{init:function(e,t){this.name=e,this.screen=t,this.session=Sao.Session.current_session,this.fields_data={},this.fields_invert={},Sao.Window.Import._super.init.call(this,Sao.i18n.gettext("CSV Import: %1",e)),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Auto-Detect")}).text(" "+Sao.i18n.gettext("Auto-Detect")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-search")).click(()=>{this.autodetect()}).appendTo(this.column_buttons);t=jQuery("<label/>",{text:Sao.i18n.gettext("File to Import"),class:"col-sm-6 control-label",for:"input-csv-file"}),this.file_input=jQuery("<input/>",{type:"file",id:"input-csv-file"}),jQuery("<div/>",{class:"form-group"}).append(t).append(jQuery("<div/>",{class:"col-sm-6"}).append(this.file_input)).appendTo(this.chooser_form),e=jQuery("<label/>",{text:Sao.i18n.gettext("Encoding:"),class:"control-label",for:"input-encoding"});this.el_csv_encoding=jQuery("<select/>",{class:"form-control",id:"input-encoding"});for(const i of n)jQuery("<option/>",{val:i}).append(i).appendTo(this.el_csv_encoding);t="utf-8",navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(t="cp1252"),this.el_csv_encoding.children('option[value="'+t+'"]').attr("selected","selected"),jQuery("<div/>",{class:"form-group"}).append(e).append(this.el_csv_encoding).appendTo(this.expander_csv),this.expander_csv.append(" "),t=jQuery("<label/>",{text:Sao.i18n.gettext("Lines to Skip:"),class:"control-label",for:"input-skip"});this.el_csv_skip=jQuery("<input/>",{type:"number",class:"form-control",id:"input-skip",value:"0"}),jQuery("<div/>",{class:"form-group"}).append(t).append(this.el_csv_skip).appendTo(this.expander_csv),this.expander_csv.append(" "),Sortable.create(this.fields_selected.get(0),{handle:".draggable-handle",ghostClass:"dragged-row"})},sig_sel_add:function(e){e=jQuery(e),this._add_node(e.attr("field"),e.attr("name"))},_add_node:function(e,t){jQuery("<li/>",{field:e,class:"draggable-handle"}).text(t).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-drag")).click(function(e){var t=jQuery(e.target);e.ctrlKey||e.metaKey?t.toggleClass("bg-primary"):(t.addClass("bg-primary"),t.siblings().removeClass("bg-primary"))}).appendTo(this.fields_selected)},view_populate:function(s,t){Object.keys(s).sort(function(e,t){return s[t].string<s[e].string?-1:1}).reverse().forEach(i=>{var e=s[i].string||i,n=jQuery("<li/>",{field:s[i].field,name:s[i].name}).text(e).click(e=>{e.ctrlKey||e.metaKey?n.toggleClass("bg-primary"):(this.fields_all.find("li").removeClass("bg-primary"),n.addClass("bg-primary"))}).appendTo(t),o=(s[i].view=n,Sao.common.ICONFACTORY.get_icon_img("tryton-arrow-right").data("expanded",!1).click(e=>{e.stopPropagation();var t,e=o.data("expanded");o.data("expanded",!e),e?(t="tryton-arrow-right",n.next("ul").remove()):(t="tryton-arrow-down",this.on_row_expanded(s[i])),Sao.common.ICONFACTORY.get_icon_url(t).then(function(e){o.attr("src",e)})}).prependTo(n));o.css("visibility",s[i].relation?"visible":"hidden")})},model_populate:function(e,t,i,n){t=t||this.fields_model,i=i||"",n=n||"";for(const r of Object.keys(e)){var o,s,a;e[r].readonly&&"id"!=r||(o=n+(o=e[r].string||r),s="one2many"==e[r].type?e[r].relation:null,a={name:o,field:i+r,relation:s,string:e[r].string},t[r]=a,this.fields[i+r]=a,this.fields_invert[o]=i+r,s&&(a.children={}))}},children_expand:function(e){jQuery.isEmptyObject(e.children)&&e.relation&&this.model_populate(this._get_fields(e.relation),e.children,e.field+"/",e.name+"/")},autodetect:function(){this.file_input.val()?(this.fields_selected.empty(),this.el_csv_skip.val(1),Papa.parse(this.file_input[0].files[0],{delimiter:this.el_csv_delimiter.val(),quoteChar:this.el_csv_quotechar.val(),preview:1,encoding:this.el_csv_encoding.val(),error:(e,t,i,n)=>{Sao.common.warning.run(n,Sao.i18n.gettext("Detection failed"))},complete:e=>{e.data[0].every(e=>{var t,i;return e in this.fields_invert||e in this.fields||(t=this.fields_model,i=e.split("/").slice(0,-1),this._traverse(t,"",i,0)),this._auto_select(e)})}})):Sao.common.message.run(Sao.i18n.gettext("You must select an import file first."))},_auto_select:function(e){var t,i;if(e in this.fields_invert)i=this.fields_invert[t=e];else{if(!(e in this.fields))return Sao.common.warning.run(Sao.i18n.gettext('Unknown column header "%1"',e),Sao.i18n.gettext("Error")),!1;t=this.fields[e].name,i=[e]}return this._add_node(i,t),!0},_traverse:function(e,t,i,n){for(var o,s=Object.keys(e),a=0;a<s.length;a++)if((o=e[s[a]]).name==t+i[n]||o.field==t+i[n]){this.children_expand(o),t+=i[n]+"/",o.children&&this._traverse(o.children,t,i,++n);break}},response:function(e){var i;"RESPONSE_OK"==e&&(i=[],this.fields_selected.children("li").each((e,t)=>{i.push(t.getAttribute("field"))}),e=this.file_input.val())?this.import_csv(e,i).then(()=>{this.destroy()}):this.destroy()},import_csv:function(e,t){var i=this.el_csv_skip.val(),n=this.el_csv_encoding.val(),o=jQuery.Deferred();return Papa.parse(this.file_input[0].files[0],{delimiter:this.el_csv_delimiter.val(),quoteChar:this.el_csv_quotechar.val(),encoding:n,error:(e,t,i,n)=>{Sao.common.warning.run(n,Sao.i18n.gettext("Import failed")).always(o.reject)},complete:e=>{e=e.data.slice(i,e.data.length-1);Sao.rpc({method:"model."+this.screen.model_name+".import_data",params:[t,e,{}]},this.session).then(e=>Sao.common.message.run(Sao.i18n.ngettext("%1 record imported","%1 records imported",e))).then(o.resolve,o.reject)}}),o.promise()}}),Sao.Window.Export=Sao.class_(Sao.Window.CSV,{init:function(e,t,i){this.name=e,this.screen=t,this.session=Sao.Session.current_session,Sao.Window.Export._super.init.call(this,Sao.i18n.gettext("CSV Export: %1",e));var n=this.screen.model.fields;for(const e of i){var o=n[e].description.type;"selection"==o?this.sel_field(e+".translated"):"reference"==o?(this.sel_field(e+".translated"),this.sel_field(e+"/rec_name")):this.sel_field(e)}this.predef_exports={},this.fill_predefwin(),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Save Export")}).text(" "+Sao.i18n.gettext("Save Export")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-save")).click(()=>{this.addreplace_predef()}).appendTo(this.column_buttons),this.button_url=jQuery("<a/>",{class:"btn btn-default btn-block",target:"_blank",rel:"noreferrer noopener",title:Sao.i18n.gettext("URL Export")}).text(" "+Sao.i18n.gettext("URL Export")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-public")).appendTo(this.column_buttons),this.dialog.body.on("change click",this.set_url.bind(this)),jQuery("<button/>",{class:"btn btn-default btn-block",type:"button",title:Sao.i18n.gettext("Delete Export")}).text(" "+Sao.i18n.gettext("Delete Export")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-delete")).click(()=>{this.remove_predef()}).appendTo(this.column_buttons);t=jQuery("<div/>",{class:"panel panel-default"}).append(jQuery("<div/>",{class:"panel-heading"}).append(jQuery("<h3/>",{class:"panel-title",text:Sao.i18n.gettext("Predefined Exports")}))).appendTo(this.column_buttons);this.predef_exports_list=jQuery("<ul/>",{class:"list-unstyled predef-exports panel-body"}).css("cursor","pointer").appendTo(t),this.selected_records=jQuery("<select/>",{class:"form-control",id:"input-records"}).append(jQuery("<option/>",{val:!0,selected:!this.screen_is_tree}).text(Sao.i18n.gettext("Selected Records"))).append(jQuery("<option/>",{val:!1,selected:!!this.screen_is_tree}).text(Sao.i18n.gettext("Listed Records"))),this.ignore_search_limit=jQuery("<input/>",{type:"checkbox"}),this.selected_records.change(()=>{this.ignore_search_limit.parents(".form-group").first().toggle(!JSON.parse(this.selected_records.val())&&!this.screen_is_tree)}),jQuery("<div/>",{class:"form-group"}).appendTo(this.chooser_form).append(jQuery("<label/>",{text:Sao.i18n.gettext("Export:"),class:"control-label",for:"input-records"})).append(this.selected_records),jQuery("<div/>",{class:"form-group"}).appendTo(this.chooser_form).append(jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>",{text:" "+Sao.i18n.gettext("Ignore search limit")}).prepend(this.ignore_search_limit))).hide(),this.el_csv_locale=jQuery("<input/>",{type:"checkbox",checked:"checked"}),jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>",{text:" "+Sao.i18n.gettext("Use locale format")}).prepend(this.el_csv_locale)).appendTo(this.expander_csv),this.expander_csv.append(" "),this.el_add_field_names=jQuery("<input/>",{type:"checkbox",checked:"checked"}),jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>",{text:" "+Sao.i18n.gettext("Add Field Names")}).prepend(this.el_add_field_names)).appendTo(this.expander_csv),this.expander_csv.append(" "),this.set_url(),Sortable.create(this.fields_selected.get(0),{handle:".draggable-handle",ghostClass:"dragged-row"})},get context(){return this.screen.context},get screen_is_tree(){return Boolean(this.screen.current_view&&"tree"==this.screen.current_view.view_type&&this.screen.current_view.children_field)},view_populate:function(s,t){Object.keys(s).sort(function(e,t){return s[t].string<s[e].string?-1:1}).reverse().forEach(i=>{var e=s[i].path,n=jQuery("<li/>",{path:e}).text(s[i].string).click(e=>{e.ctrlKey||e.metaKey?n.toggleClass("bg-primary"):(this.fields_all.find("li").removeClass("bg-primary"),n.addClass("bg-primary"))}).appendTo(t),o=(s[i].view=n,Sao.common.ICONFACTORY.get_icon_img("tryton-arrow-right").data("expanded",!1).click(e=>{e.stopPropagation();var t,e=o.data("expanded");o.data("expanded",!e),e?(t="tryton-arrow-right",n.next("ul").remove()):(t="tryton-arrow-down",this.on_row_expanded(s[i])),Sao.common.ICONFACTORY.get_icon_url(t).then(function(e){o.attr("src",e)})}).prependTo(n));o.css("visibility",s[i].children?"visible":"hidden")})},model_populate:function(e,t,i,n){t=t||this.fields_model,i=i||"",n=n||"";for(const c of Object.keys(e)){var o=e[c],s=o.string||c,a=[{name:c,field:o,string:s}];"selection"==o.type?a.push({name:c+".translated",field:o,string:Sao.i18n.gettext("%1 (string)",s)}):"reference"==o.type&&(a.push({name:c+".translated",field:o,string:Sao.i18n.gettext("%1 (model name)",s)}),a.push({name:c+"/rec_name",field:o,string:Sao.i18n.gettext("%1/Record Name",s)}));for(const d of a){var r=i+d.name,l=n+d.string,l={path:r,string:d.string,long_string:l,relation:d.field.relation};t[d.name]=l,this.fields[r]=l,-1==d.name.indexOf(".")&&d.field.relation&&(l.children={})}}},children_expand:function(e){jQuery.isEmptyObject(e.children)&&e.relation&&this.model_populate(this._get_fields(e.relation),e.children,e.path+"/",e.long_string+"/")},sig_sel_add:function(e){e=(e=jQuery(e)).attr("path");this.sel_field(e)},fill_predefwin:function(){Sao.rpc({method:"model.ir.export.get",params:[this.screen.model_name,["name","header","records","export_fields.name"],this.context]},this.session).done(e=>{for(const t of e)this.predef_exports[t.id]={fields:t["export_fields."].map(e=>e.name),values:t},this.add_to_predef(t.id,t.name),this.predef_exports_list.children("li").first().focus()})},add_to_predef:function(e,t){var i=jQuery("<li/>",{text:t,export_id:e,tabindex:0}).on("keypress",function(e){e=e.keyCode||e.which;13!=e&&32!=e||i.click()}).click(e=>{i.toggleClass("bg-primary").siblings().removeClass("bg-primary"),i.hasClass("bg-primary")&&this.sel_predef(i.attr("export_id"))});this.predef_exports_list.append(i)},addreplace_predef:function(){var n,e,o,s=[];for(const t of this.fields_selected.children("li"))s.push(t.getAttribute("path"));0!==s.length&&(e=t=>{var i={header:this.el_add_field_names.is(":checked"),records:JSON.parse(this.selected_records.val())?"selected":"listed"},e=n?Sao.rpc({method:"model.ir.export.update",params:[n,i,s,this.context]},this.session).then(()=>n):(i.name=t,i.resource=this.screen.model_name,i.export_fields=s.map(e=>({name:e})),Sao.rpc({method:"model.ir.export.set",params:[i,this.context]},this.session));return e.then(e=>{this.session.cache.clear("model."+this.screen.model_name+".view_toolbar_get"),this.predef_exports[e]={fields:s,values:i},0===o.length&&this.add_to_predef(e,t)})},(0===(o=this.predef_exports_list.children("li.bg-primary")).length?(n=null,Sao.common.ask.run(Sao.i18n.gettext("What is the name of this export?"),"export")):(n=o.attr("export_id"),Sao.common.sur.run(Sao.i18n.gettext("Override %1 definition?",o.text())))).then(e))},remove_predef:function(){var e,t=this.predef_exports_list.children("li.bg-primary");0!==t.length&&(e=jQuery(t).attr("export_id"),Sao.rpc({method:"model.ir.export.unset",params:[e,this.context]},this.session).then(()=>{this.session.cache.clear("model."+this.screen.model_name+".view_toolbar_get"),delete this.predef_exports[e],t.remove()}))},sel_predef:function(e){this.fields_selected.empty();var t,i,e=this.predef_exports[e];for(const n of e.fields){if(n in this.fields||(t=this.fields_model,i=n.split("/").slice(0,-1),this._traverse(t,"",i,0)),!(n in this.fields))return;this.sel_field(n)}this.el_add_field_names.prop("checked",e.values.header),this.selected_records.val(JSON.stringify("selected"==e.values.records)),this.selected_records.change()},_traverse:function(e,t,i,n){for(var o,s=Object.keys(e),a=0;a<s.length;a++)if((o=e[s[a]]).path==t+i[n]){this.children_expand(o),t+=i[n]+"/",o.children&&this._traverse(o.children,t,i,++n);break}},sel_field:function(e){var t=this.fields[e].long_string,i=(this.fields[e].relation&&(e+="/rec_name"),jQuery("<li/>",{path:e,class:"draggable-handle"}).text(t).click(function(e){e.ctrlKey||e.metaKey?i.toggleClass("bg-primary"):jQuery(e.target).addClass("bg-primary").siblings().removeClass("bg-primary")}).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-drag")).appendTo(this.fields_selected))},response:function(e){var i,t,n,o,s;"RESPONSE_OK"==e?(i=[],this.fields_selected.children("li").each(function(e,t){i.push(t.getAttribute("path"))}),t=this.el_add_field_names.is(":checked"),(JSON.parse(this.selected_records.val())?(s=this.screen.selected_records.map(function(e){return e.id}),n=this.screen.selected_paths,Sao.rpc({method:"model."+this.screen.model_name+".export_data",params:[s,i,t,this.context]},this.session)):this.screen_is_tree?(s=this.screen.listed_records.map(function(e){return e.id}),n=this.screen.listed_paths,Sao.rpc({method:"model."+this.screen.model_name+".export_data",params:[s,i,t,this.context]},this.session)):(e=this.screen.search_domain(this.screen.screen_container.get_text()),s=this.ignore_search_limit.prop("checked")?(o=0,null):(o=this.screen.offset,this.screen.limit),Sao.rpc({method:"model."+this.screen.model_name+".export_data_domain",params:[e,i,o,s,this.screen.order,t,this.context]},this.session))).then(e=>{this.export_csv(e,n,t).then(()=>{this.destroy()})})):this.destroy()},export_csv:function(e,i,t=!1){var n=this.el_csv_locale.prop("checked"),o={},o=(o.data=e.map(function(e,t){t=i&&i[t]?i[t].length-1:0;return Sao.Window.Export.format_row(e,t,n)}),Papa.unparse(o,{quoteChar:this.el_csv_quotechar.val(),delimiter:this.el_csv_delimiter.val()})),o=(navigator.platform&&"Win"==navigator.platform.slice(0,3)&&(o=Sao.BOM_UTF8+o),Sao.common.download_file(o,this.name+".csv",{type:"text/csv;charset=utf-8"}),e.length);return t&&--o,Sao.common.message.run(Sao.i18n.ngettext("%1 record saved","%1 records saved",o))},set_url:function(){var e,t=[this.session.database,"data",this.screen.model_name],i=[];if(JSON.parse(this.selected_records.val()))e=this.screen.current_view.selected_records.map(function(e){return e.id});else if(e=this.screen.search_domain(this.screen.screen_container.get_text()),this.ignore_search_limit.prop("checked")||null===this.screen.limit||(i.push(["s",this.screen.limit.toString()]),i.push(["p",Math.floor(this.screen.offset/this.screen.limit).toString()])),this.screen.order)for(const n of this.screen.order)i.push(["o",n.map(function(e){return e}).join(",")]);i.splice(0,0,["d",JSON.stringify(Sao.rpc.prepareObject(e))]),jQuery.isEmptyObject(this.screen.local_context)||i.push(["c",JSON.stringify(Sao.rpc.prepareObject(this.screen.local_context))]),this.fields_selected.children("li").each(function(e,t){i.push(["f",t.getAttribute("path")])}),i.push(["dl",this.el_csv_delimiter.val()]),i.push(["qc",this.el_csv_quotechar.val()]),this.el_add_field_names.is(":checked")||i.push(["h","0"]),this.el_csv_locale.prop("checked")&&i.push(["loc","1"]),i=i.map(function(e){return e.map(encodeURIComponent).join("=")}).join("&"),this.button_url.attr("href","/"+t.join("/")+"?"+i)}}),Sao.Window.Export.format_row=function(e,i=0,n=!0){var o=[];return e.forEach(function(e,t){n?e.isDateTime?e=e.local().format(Sao.common.date_format()+" "+Sao.common.moment_format("%X")):e.isDate?e=e.format(Sao.common.date_format()):e.isTimeDelta?e=Sao.common.timedelta.format(e,{s:1,m:60,h:3600}):isNaN(Number(e))||(e=e.toLocaleString(Sao.i18n.BC47(Sao.i18n.getlang()),{minimumFractionDigits:0,maximumFractionDigits:20})):e.isDateTime?e=e.utc():e.isTimeDelta?e=e.asSeconds():"boolean"==typeof e&&(e+=0),(e=0===t&&i&&"string"==typeof e?" ".repeat(i)+e:e)instanceof Uint8Array&&(e=Sao.common.btoa(e)),o.push(e)}),o},Sao.Window.EmailEntry=Sao.class_(Sao.common.InputCompletion,{init:function(e,t){this.session=t,Sao.Window.EmailEntry._super.init.call(this,e,this._email_source,this._email_match_selected,this._email_format)},_email_match_selected:function(e){this.input.val(e[2])},_email_source:function(e){return this.input[0].selectionStart<this.input.val().length?jQuery.when([]):Sao.rpc({method:"model.ir.email.complete",params:[e,Sao.config.limit,{}]},this.session).fail(function(){Sao.Logger.warn("Unable to complete email entry")})},_email_format:function(e){return e[1]}}),Sao.Window.Email=Sao.class_(Object,{init:function(e,t,i,n){this.record=t,this.dialog=new Sao.Dialog(Sao.i18n.gettext("E-mail %1",e),"email","lg"),this.el=this.dialog.modal,this.dialog.content.addClass("form-horizontal");var o=this.dialog.body;function s(e,t,i){var n=jQuery("<div/>",{class:"form-group"}).appendTo(o),t=(jQuery("<label/>",{class:"control-label col-sm-1",text:t,for:"email-"+e}).appendTo(n),jQuery("<input/>",{type:"text",class:"form-control input-sm",id:"email-"+e}).appendTo(jQuery("<div/>",{class:"col-sm-11"}).appendTo(n)));return i&&t.attr("required",!0),t}this.to=s("to",Sao.i18n.gettext("To:"),!0),this.cc=s("cc",Sao.i18n.gettext("Cc:")),this.bcc=s("bcc",Sao.i18n.gettext("Bcc:"));for(const l of[this.to,this.cc,this.bcc])new Sao.Window.EmailEntry(l,this.record.model.session);this.subject=s("subject",Sao.i18n.gettext("Subject:"),!0);var e=jQuery("<div/>",{class:"panel panel-default"}).appendTo(o).append(jQuery("<div/>",{class:"panel-heading"}).append(Sao.common.richtext_toolbar())),a=(this.body=jQuery("<div>",{class:"email-richtext form-control input-sm mousetrap",contenteditable:!0,spellcheck:!0,id:"email-body"}).appendTo(jQuery("<div/>",{class:"panel-body"}).appendTo(e)),jQuery("<div/>",{class:"col-md-4"}).appendTo(o));jQuery("<label/>",{text:Sao.i18n.gettext("Reports")}).appendTo(a),this.print_actions={};for(const c of i){var r=jQuery("<input/>",{type:"checkbox"});jQuery("<div/>",{class:"checkbox"}).append(jQuery("<label/>").text(Sao.i18n.gettext(c.name)).prepend(r)).appendTo(a),this.print_actions[c.id]=r}e=jQuery("<div/>",{class:"col-md-4"}).appendTo(o);jQuery("<label/>",{text:Sao.i18n.gettext("Attachments")}).appendTo(e),this.attachments=jQuery("<select/>",{class:"form-control input-sm",name:"attachments",multiple:!0}).appendTo(e),Sao.rpc({method:"model.ir.attachment.search_read",params:[[["resource","=",t.model.name+","+t.id],["OR",["data","!=",null],["file_id","!=",null]]],0,null,null,["rec_name"],t.get_context()]},t.model.session).then(e=>{for(const t of e)this.attachments.append(jQuery("<option/>",{value:JSON.stringify(t.id),text:t.rec_name}))}).fail(function(){Sao.Logger.error("Could not fetch attachment for",t)}),this.files=jQuery("<div/>",{class:"col-md-4"}).appendTo(o),jQuery("<label/>",{text:Sao.i18n.gettext("Files")}).appendTo(this.files),this._add_file_button(),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Cancel")}).text(" "+Sao.i18n.gettext("Cancel")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-cancel")).click(()=>{this.response("RESPONSE_CANCEL")}).appendTo(this.dialog.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("Send")}).text(" "+Sao.i18n.gettext("Send")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-send")).appendTo(this.dialog.footer),this.dialog.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),this._fill_with(n),this.el.modal("show"),this.el.on("hidden.bs.modal",function(){jQuery(this).remove()})},_add_file_button:function(){var e=jQuery("<div/>").appendTo(this.files),t=jQuery("<input/>",{type:"file"}).appendTo(e),i=jQuery("<a/>",{class:"close",title:Sao.i18n.gettext("Remove File")}).append(jQuery("<span/>",{"aria-hidden":!0,text:"x"})).append(jQuery("<span/>",{class:"sr-only"}).text(Sao.i18n.gettext("Remove")));i.hide(),i.appendTo(e),t.on("change",()=>{i.show(),this._add_file_button()}),i.click(function(){e.remove()})},get_files:function(){var n=[],o=[];return this.files.find("input[type=file]").each(function(e,t){var i;t.files.length&&(i=jQuery.Deferred(),n.push(i),Sao.common.get_file_data(t.files[0],function(e,t){o.push([t,e]),i.resolve()}))}),jQuery.when.apply(jQuery,n).then(function(){return o})},get_attachments:function(){var e=this.attachments.val();return e?e.map(function(e){return JSON.parse(e)}):[]},_fill_with:function(e){e=e?Sao.rpc({method:"model.ir.email.template.get",params:[e,this.record.id,{}]},this.record.model.session):Sao.rpc({method:"model.ir.email.template.get_default",params:[this.record.model.name,this.record.id,{}]},this.record.model.session);e.then(e=>{this.to.val((e.to||[]).join(", ")),this.cc.val((e.cc||[]).join(", ")),this.bcc.val((e.bcc||[]).join(", ")),this.subject.val(e.subject||""),this.body.html(Sao.HtmlSanitizer.sanitize(e.body||""));var t,i=e.reports||[];for(t in this.print_actions)this.print_actions[t].prop("checked",~i.indexOf(parseInt(t,10)))})},response:function(e){if("RESPONSE_OK"==e){var t,i=this.to.val(),n=this.cc.val(),o=this.bcc.val(),s=this.subject.val(),a=Sao.common.richtext_normalize(this.body.html()),r=[];for(t in this.print_actions)this.print_actions[t].prop("checked")&&r.push(t);var l=this.get_attachments(),c=this.record;this.get_files().then(function(e){return Sao.rpc({method:"model.ir.email.send",params:[i,n,o,s,a,e,[c.model.name,c.id],r,l,{}]},c.model.session)}).then(()=>{this.destroy()})}else this.destroy()},destroy:function(){this.el.modal("hide")}}),Sao.Window.CodeScanner=Sao.class_(Object,{init:function(e,t=!1){this.callback=e,this.loop=t,this.submitting=!1,this.dialog=new Sao.Dialog(Sao.i18n.gettext("Code Scanner"),"code-scanner","md"),this.el=this.dialog.modal,this.input=jQuery("<input/>",{type:"text",class:"form-control input-sm mousetrap","aria-label":Sao.i18n.gettext("Code"),placeholder:Sao.i18n.gettext("Code")}).appendTo(jQuery("<div/>",{class:"col-sm-12"}).appendTo(this.dialog.body));function i(e){var t=e?(n.addClass("active"),n.attr("aria-pressed",e),Sao.common.ICONFACTORY.get_icon_url("tryton-sound-on").done(e=>{o.attr("src",e)})):(n.removeClass("active"),n.attr("aria-pressed",e),Sao.common.ICONFACTORY.get_icon_url("tryton-sound-off").done(e=>{o.attr("src",e)}));return localStorage.setItem("sao_code_scanner_sound",e),t}var n=jQuery("<button/>",{class:"btn btn-default pull-right",type:"button",title:Sao.i18n.gettext("Toggle Sound")}).prependTo(this.dialog.header),o=jQuery("<img/>",{class:"icon"}).appendTo(n),e=JSON.parse(localStorage.getItem("sao_code_scanner_sound")),t=i(e=null===e?!0:e);n.click(()=>i(!n.hasClass("active"))),jQuery("<button/>",{class:"btn btn-link",type:"button",title:Sao.i18n.gettext("Close")}).text(" "+Sao.i18n.gettext("Close")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-close")).click(()=>{this.response("RESPONSE_CLOSE")}).appendTo(this.dialog.footer),jQuery("<button/>",{class:"btn btn-primary",type:"submit",title:Sao.i18n.gettext("OK")}).text(" "+Sao.i18n.gettext("OK")).prepend(Sao.common.ICONFACTORY.get_icon_img("tryton-ok")).appendTo(this.dialog.footer),this.dialog.content.submit(e=>{e.preventDefault(),this.response("RESPONSE_OK")}),this.el.on("shown.bs.modal",()=>{this.input.on("blur",this._keep_focus),this.input.focus()}),this.el.on("hidden.bs.modal",function(){jQuery(this).remove()}),t.then(()=>this.el.modal("show"))},_play_sound:function(e){JSON.parse(localStorage.getItem("sao_code_scanner_sound"))&&Sao.common.play_sound(e)},_keep_focus:function(){setTimeout(()=>this.focus(),1)},response:function(e){if(!this.submitting){if("RESPONSE_OK"==e){var t=this.input.val();if(this.input.val(""),t)return this.submitting=!0,this.input.off("blur"),this.callback(t).always(()=>this.submitting=!1).then(e=>{this._play_sound("success"),this.loop&&e||this.destroy(),this.input.on("blur",this._keep_focus),this.input.focus()},e=>{this._play_sound("danger"),"UserError"==e[0]?Sao.common.warning.run(e[1][1],e[1][0]):Sao.common.error.run(e[0],e[1]),this.destroy()})}this.loop&&"RESPONSE_OK"==e||this.destroy()}},destroy:function(){this.el.modal("hide")}})}(),!function(){"use strict";Sao.Wizard=Sao.class_(Object,{init:function(e){this.widget=jQuery("<div/>",{class:"wizard"}),this.name=e||Sao.i18n.gettext("Wizard"),this.action_id=null,this.id=null,this.ids=null,this.action=null,this.context=null,this.states={},this.session_id=null,this.start_state=null,this.end_state=null,this.screen=null,this.screen_state=null,this.state=null,this.session=Sao.Session.current_session,this.__processing=!1,this.__waiting_response=!1,this.info_bar=new Sao.Window.InfoBar},run:function(e){this.action=e.action,this.action_id=e.data.action_id,this.id=e.data.id,this.ids=e.data.ids,this.model=e.data.model,this.context=jQuery.extend({},e.context),this.context.active_id=this.id,this.context.active_ids=this.ids,this.context.active_model=this.model,this.context.action_id=this.action_id,Sao.rpc({method:"wizard."+this.action+".create",params:[this.session.context]},this.session).then(e=>{this.session_id=e[0],this.start_state=this.state=e[1],this.end_state=e[2],this.process()},()=>{this.destroy()})},process:function(){this.__processing||this.__waiting_response||function(){var e,t;this.state==this.end_state?this.end():(e=jQuery.extend({},this.context),t={},this.screen&&(t[this.screen_state]=this.screen.get_on_change_value()),Sao.rpc({method:"wizard."+this.action+".execute",params:[this.session_id,t,this.state,e]},this.session).then(i=>{i.view?(this.clean(),e=i.view,this.update(e.fields_view,e.buttons),this.screen.new_(!1).then(()=>{this.screen.current_record.set_default(e.defaults||{}).then(()=>{this.screen.current_record.set(e.values||{}),this.update_buttons(),this.screen.set_cursor()})}),this.screen_state=e.state,this.__waiting_response=!0):this.state=this.end_state;var e,t=()=>{if(i.actions)for(const t of i.actions){var e=jQuery.extend({},this.context);delete e.active_id,delete e.active_ids,delete e.active_model,delete e.action_id,Sao.Action.execute(t[0],t[1],e)}};this.state==this.end_state?this.end().then(t):t(),this.__processing=!1},e=>{this.__processing=!1}))}.call(this)},destroy:function(e){},end:function(){return Sao.rpc({method:"wizard."+this.action+".delete",params:[this.session_id,this.session.context]},this.session).then(e=>{this.destroy(e)}).fail(()=>{Sao.Logger.warn("Unable to delete session %s of wizard %s",this.session_id,this.action)})},clean:function(){this.widget.empty(),this.states={}},response:function(e){this.__waiting_response=!1,this.screen.current_view.set_value(),e.validate&&!this.screen.current_record.validate(null,null,null,!0)?(this.screen.display(!0),this.info_bar.add(this.screen.invalid_message(),"danger")):(this.info_bar.clear(),this.state=e.state,this.process())},_get_button:function(e){var t="btn-default",t=(e.default?t="btn-primary":e.state==this.end_state&&(t="btn-link"),new Sao.common.Button(e,void 0,void 0,t));return this.states[e.state]=t},record_modified:function(){this.update_buttons(),this.info_bar.refresh()},update_buttons:function(){var e,t=this.screen.current_record;for(e in this.states)this.states[e].set_state(t)},update:function(e,t){for(const i of t)this._get_button(i);this.screen&&this.screen.windows.splice(this.screen.windows.indexOf(this),1),this.screen=new Sao.Screen(e.model,{mode:[],context:this.context}),this.screen.add_view(e),this.screen.switch_view(),this.screen.windows.push(this),this.header.append(jQuery("<h4/>",{class:"model-title",title:this.name}).text(Sao.common.ellipsize(this.name,80))),this.widget.append(this.screen.screen_container.el)}}),Sao.Wizard.create=function(e){var t,i;e.window?(t=new Sao.Wizard.Form(e.name),i=new Sao.Tab.Wizard(t),Sao.Tab.add(i)):t=new Sao.Wizard.Dialog(e.name),t.run(e)},Sao.Wizard.Form=Sao.class_(Sao.Wizard,{init:function(e){Sao.Wizard.Form._super.init.call(this,e),this.tab=null,this.header=jQuery("<div/>",{class:"modal-header"}),this.form=jQuery("<div/>",{class:"wizard-form"}).append(this.header).append(this.widget),this.footer=jQuery("<div/>",{class:"modal-footer"}).appendTo(this.form)},clean:function(){Sao.Wizard.Form._super.clean.call(this),this.header.empty(),this.footer.empty()},_get_button:function(e){var t=Sao.Wizard.Form._super._get_button.call(this,e);return this.footer.append(t.el),t.el.click(()=>{this.response(e)}),t},destroy:function(e){switch(Sao.Wizard.Form._super.destroy.call(this,e),e){case"reload menu":Sao.Session.current_session.reload_context().then(function(){Sao.menu()});break;case"reload context":Sao.Session.current_session.reload_context()}},end:function(){return Sao.Wizard.Form._super.end.call(this).always(()=>this.tab.close())}}),Sao.Wizard.Dialog=Sao.class_(Sao.Wizard,{init:function(e){Sao.Wizard.Dialog._super.init.call(this,e);e=new Sao.Dialog(e,"wizard-dialog","md",!1);this.dialog=e.modal,this.header=e.header,this.content=e.content,this.footer=e.footer,this.dialog.on("keydown",e=>{e.which==Sao.common.ESC_KEYCODE&&(e.preventDefault(),this.end_state in this.states)&&this.response(this.states[this.end_state].attributes)}),e.body.append(this.widget).append(this.info_bar.el)},clean:function(){Sao.Wizard.Dialog._super.clean.call(this),this.header.empty(),this.footer.empty()},_get_button:function(t){var e=Sao.Wizard.Dialog._super._get_button.call(this,t);return this.footer.append(e.el),t.default?(this.content.unbind("submit"),this.content.submit(e=>{this.response(t),e.preventDefault()}),e.el.attr("type","submit")):e.el.click(()=>{this.response(t)}),e},update:function(e,t){this.content.unbind("submit"),Sao.Wizard.Dialog._super.update.call(this,e,t),this.show()},destroy:function(n){Sao.Wizard.Dialog._super.destroy.call(this,n);var e=()=>{this.dialog.remove();var e=jQuery(".wizard-dialog").filter(":visible")[0],t=!1,i=!(e=e||Sao.Tab.tabs.get_current())||!this.model||Sao.main_menu_screen&&Sao.main_menu_screen.model_name==this.model?(t=!0,Sao.main_menu_screen):e.screen;i&&(e=jQuery.when(),i.current_record&&!t&&(t=i.model_name==this.model?this.ids:[i.current_record.id],e=i.reload(t,!0)),n)&&e.then(function(){i.client_action(n)})};(this.dialog.data("bs.modal")||{}).isShown?(this.dialog.on("hidden.bs.modal",e),this.dialog.modal("hide")):e()},show:function(){var e=this.screen.current_view;if("form"==e.view_type){var t=!1;for(const i of e.get_fields()){for(const n of e.widgets[i])if(n.expand){t=!0;break}if(t)break}}else t=!0;t?this.dialog.find(".modal-dialog").removeClass("modal-md modal-sm").addClass("modal-lg"):this.dialog.find(".modal-dialog").removeClass("modal-lg modal-sm").addClass("modal-md"),this.dialog.modal("show")},hide:function(){this.dialog.modal("hide")},state_changed:function(){this.process()}})}(),!function(){"use strict";Sao.View.BoardXMLViewParser=Sao.class_(Sao.View.FormXMLViewParser,{_parse_board:function(e,t){var i=new Sao.View.Form.Container(Number(e.getAttribute("col")||4));if(this.view.containers.push(i),this.view.el.append(i.el),this.parse_child(e,i),0<this._containers.length)throw"AssertionError"},_parse_action:function(e,t){var i;void 0===t.yexpand&&(t.yexpand=!0),void 0===t.yfill&&(t.yfill=!0),i=new Sao.View.Board.Action(this.view,t),this.view.actions.push(i),this.container.add(i,t)}}),Sao.View.Board=Sao.class_(Object,{xml_parser:Sao.View.BoardXMLViewParser,init:function(e,t){var i;this.context=t,this.actions=[],this.containers=[],this.state_widgets=[],this.el=jQuery("<div/>",{class:"board"}),new this.xml_parser(this,null,{}).parse(e.children()[0]),i=[];for(const n of this.actions)i.push(n.action_prm);this.actions_prms=jQuery.when.apply(jQuery,i)},reload:function(){for(var e=0;e<this.actions.length;e++)this.actions[e].display();var t,i=[];for(t of this.state_widgets.toReversed()){var n=t.set_state(null);n&&i.push(n)}for(const o of this.containers)o.set_grid_template();jQuery.when.apply(jQuery,i).done(()=>{for(const e of this.containers)e.set_grid_template()})},active_changed:function(e){for(const t of this.actions)t!==e&&t.update_domain(this.actions)}}),Sao.View.Board.Action=Sao.class_(Object,{init:function(e,a){var r=Sao.Session.current_session,e=(this.name=a.name,this.view=e,this.el=jQuery("<div/>",{class:"board-action panel panel-default"}),this.title=jQuery("<div/>",{class:"panel-heading"}),this.el.append(this.title),this.body=jQuery("<div/>",{class:"panel-body"}),this.el.append(this.body),new Sao.Model("ir.action.act_window"));this.action_prm=e.execute("get",[this.name],{}),this.action_prm.done(e=>{var t={};if(this.action=e,t.view_ids=[],t.mode=null,jQuery.isEmptyObject(e.views))jQuery.isEmptyObject(e.view_id)||(t.view_ids=[e.view_id[0]]);else{t.view_ids=[],t.mode=[];for(const o of e.views)t.view_ids.push(o[0]),t.mode.push(o[1])}"pyson_domain"in this.action||(this.action.pyson_domain="[]");var i={},n=((i=jQuery.extend(i,r.context))._user=r.user_id,new Sao.PYSON.Decoder(i));t.context=jQuery.extend({},this.view.context,n.decode(e.pyson_context||"{}")),(i=jQuery.extend(i,t.context)).context=i,n=new Sao.PYSON.Decoder(i),t.order=n.decode(e.pyson_order),t.search_value=n.decode(e.pyson_search_value||"[]"),t.tab_domain=[];for(const s of e.domains)t.tab_domain.push([s[0],n.decode(s[1]),s[2]]);t.context_model=e.context_model,t.context_domain=e.context_domain,null!==e.limit?t.limit=e.limit:t.limit=Sao.config.limit,this.context=i,this.domain=[],this.update_domain([]),t.row_activate=this.row_activate.bind(this),this.screen=new Sao.Screen(this.action.res_model,t),a.string?this.title.text(a.string):this.title.text(this.action.name),this.screen.switch_view().done(()=>{this.body.append(this.screen.screen_container.el),this.screen.search_filter()})})},row_activate:function(){var e;this.screen.current_record&&("tree"==this.screen.current_view.view_type&&1==this.screen.current_view.attributes.keyword_open?(e=this.screen.current_view.selected_records.map(function(e){return e.id}),Sao.Action.exec_keyword("tree_open",{model:this.screen.model_name,id:this.screen.current_record.id,ids:e},jQuery.extend({},this.screen.group._context),!1)):new Sao.Window.Form(this.screen,e=>{e?this.screen.current_record.save():this.screen.current_record.cancel()},{title:this.title.text()}))},display:function(){this.screen.search_filter(this.screen.screen_container.get_text())},record_message:function(){this.view.active_changed(this)},get active(){return this.screen&&this.screen.current_record?{active_id:this.screen.current_record.id,active_ids:this.screen.selected_records.map(function(e){return e.id})}:{active_id:null,active_ids:[]}},update_domain:function(e){var t,i,n,o=jQuery.extend({},this.context);for(o._actions={},t=0,i=e.length;t<i;t++)o._actions[e[t].name]=e[t].active;n=new Sao.PYSON.Decoder(o).decode(this.action.pyson_domain),Sao.common.compare(this.domain,n)||(this.domain.splice(0,this.domain.length),jQuery.extend(this.domain,n),this.screen&&this.display())}})}(),!function(){"use strict";Sao.Bus={},Sao.Bus.id=Sao.common.uuid4(),Sao.Bus.channels=["client:"+Sao.Bus.id],Sao.Bus.listen=function(n,o){o=o||1;var e,s=Sao.Session.current_session;s&&((e=jQuery.ajax({headers:{Authorization:"Session "+s.get_auth()},contentType:"application/json",data:JSON.stringify({last_message:n,channels:Sao.Bus.channels}),dataType:"json",url:"/"+s.database+"/bus",type:"POST",timeout:Sao.config.bus_timeout})).done(function(e){Sao.Session.current_session==s&&(e.message&&(n=e.message.message_id,Sao.Logger.info("poll channels %s with last message",Sao.Bus.channels,n),Sao.Bus.handle(e.message)),Sao.Bus.listen(n,1))}),e.fail(function(e,t,i){Sao.Session.current_session==s&&("timeout"===i?Sao.Bus.listen(n,1):501==e.status?Sao.Logger.info("Bus not supported"):(Sao.Logger.error("An exception occured while connection to the bus. Sleeping for %s seconds",o,i),window.setTimeout(Sao.Bus.listen,Math.min(1e3*o,Sao.config.bus_timeout),n,2*o)))}))},Sao.Bus.handle=function(e){if("notification"===e.type){try{if("granted"!=Notification.permission)return void!void 0}catch(e){return void!Sao.Logger.error(e.message,e.stack)}new Notification(e.title,{body:e.body||""})}}}(),!function(){"use strict";var i={translate_view:function(e){e=e.model;Sao.Tab.create({model:"ir.translation",domain:[["model","=",e]],mode:["tree","form"],name:Sao.i18n.gettext("Translate view")})},get_plugins:function(e){var t=Sao.common.MODELACCESS.get("ir.translation");return t.read&&t.write?[[Sao.i18n.gettext("Translate view"),i.translate_view]]:[]}};Sao.Plugins.push(i)}(),!function(){"use strict";var r={B:!0,BODY:!0,BR:!0,DIV:!0,FONT:!0,I:!0,U:!0},l={align:!0,color:!0,face:!0,size:!0};Sao.HtmlSanitizer={},Sao.HtmlSanitizer.sanitize=function(e){if(""==(e=e.trim()))return"";if("<br>"==e)return"";var t=document.createElement("iframe");if(void 0===t.sandbox)return Sao.Logger.warn("Your browser do not support sandboxed iframes, unable to sanitize HTML."),e;t.sandbox="allow-same-origin",t.style.display="none",document.body.appendChild(t);var a=t.contentDocument||t.contentWindow.document;null==a.body&&a.write("<body></body>"),a.body.innerHTML=e;e=function e(t){if(t.nodeType==Node.TEXT_NODE)i=t.cloneNode(!0);else if(t.nodeType==Node.ELEMENT_NODE&&r[t.tagName]){if("BR"!=t.tagName&&""==t.innerHTML.trim())return document.createDocumentFragment();for(var i=a.createElement(t.tagName),n=0;n<t.attributes.length;n++){var o=t.attributes[n];l[o.name]&&i.setAttribute(o.name,o.value)}for(n=0;n<t.childNodes.length;n++){var s=e(t.childNodes[n]);i.appendChild(s,!1)}}else i=document.createDocumentFragment(),"SCRIPT"!=t.tagName&&(i.textContent=t.textContent);return i}(a.body);return document.body.removeChild(t),e.innerHTML.replace(/<br[^>]*>(\S)/g,"<br>\n$1").replace(/div><div/g,"div>\n<div")}}();
|