(function(){u8.Crm.Widgets.CatalogLabel=function(e,t){this.FieldLabel(e,t)};u8.Crm.Widgets.CatalogLabel.makeClass({name:"CatalogLabel",deriveFrom:u8.Crm.Widgets.FieldLabel});$.extend(u8.Crm.Widgets.CatalogLabel.prototype,{getParentValue:function(){return this._parentValue},setParentValue:function(e){this._parentValue=Number(e);this.update("view")},_updateText:function(){var e=this;this._ensureFieldSchema(function(){var t=e._fieldSchema;var a=e.getParentValue();var i=e.getValue();if(t.isHierarchicalCatalogField()&&!a&&!(a>=0&&i>=0)){e._createView("");return}u8.using({catalogs:[{schema:t,parentCode:a}]},function(){var l=u8.services.catalogs.codeToText(t,Number(i),a);e._createView(l)}.ifAlive(e))}.ifAlive(e))},_createView:function(e){this.$(this.element).toggleClass("with-image",!!this.imageTemplate);if(this.imageTemplate){this._createViewWithImage(e)}else{this.setText(e)}},_createViewWithImage:function(e){var t=this.$;var a=t("<div />");var i=this._getImage(this.getValue());if(i){t('<div class="u8-cataloglabel-image"/>').html(u8.images.html(i,"s")).appendTo(a)}t('<div class="u8-cataloglabel-text" />').html(e).appendTo(a);this.setHtml(a.html())},_getImage:function(e){if(!this.imageTemplate){return null}var t=u8.format(this.imageTemplate,{VALUE:e}),a=u8.session.images[t];if(!a){u8.log.warn("Image '"+t+"' does not exist.");return null}return a.style||this.page.html.imageUrl(a.filename)}})})();