Explorar o código

#Ticket 780
Additional improvements for bx_autocomplete_fields function and fix for payments orders form

AlexeyUna %!s(int64=9) %!d(string=hai) anos
pai
achega
f0baa8bf9b

+ 36 - 16
inc/js/functions.js

@@ -780,24 +780,36 @@ function bx_get_param(s) {
     return aDolOptions[s];
 }
 
-function bx_autocomplete_fields(id, url, name, b_img){
-	$('#' + id + ' input[type=text]').autocomplete({
-		source: url,
+function bx_autocomplete_fields(iId, sUrl, sName, bShowImg, bOnlyOnce, onSelect){
+	if (!$('#' + iId).hasClass('bx-form-input-autotoken'))
+			$('#' + iId).addClass('bx-form-input-autotoken');
+	
+	$('#' + iId + ' input[type=text]').autocomplete({
+		source: sUrl,
 		select: function(e, ui) {
 			$(this).val(ui.item.label);
 			$(this).trigger('superselect', ui.item);
-			e.preventDefault();
+					
+			if (typeof onSelect === 'function')
+				onSelect(ui);
+			
+			e.preventDefault();			
 		}
 	});
 
-	$('#' + id + ' input[type=text]').on('superselect', function(e, item) {
+	$('#' + iId + ' input[type=text]').on('superselect', function(e, item) {
 		$(this).hide();
 		if ('undefined' != typeof(item))
-			$(this).before('<b class="bx-def-color-bg-hl bx-def-round-corners">' + (b_img ? '<img class="bx-def-thumb bx-def-thumb-size bx-def-margin-sec-right" src="' + item.thumb + '">' : '') + item.label +'<input type="hidden" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" name="' + name + '[]" value="'+ item.value +'" /></b>');
-
-		fAutoShrinkInput();
-		$(this).show();
-		this.value = '';
+			$(this).before('<b class="bx-def-color-bg-hl bx-def-round-corners">' + 
+							(bShowImg ? '<img class="bx-def-thumb bx-def-thumb-size bx-def-margin-sec-right" src="' + item.thumb + '">' : '') + 
+							item.label + '<input type="hidden" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" name="' + sName + (bOnlyOnce ? '' : '[]') + '" value="' + item.value + '" /></b>');
+
+		if (!bOnlyOnce)
+		{
+			fAutoShrinkInput();
+			$(this).show();
+			this.value = '';
+		}
 
 	}).on('keydown', function(e) {
 
@@ -807,21 +819,29 @@ function bx_autocomplete_fields(id, url, name, b_img){
 
 	});
 
-	$('#' + id).on('click', 'b', function() {
+	$('#' + iId).on('click', 'b', function() {
 		$(this).remove();
-		fAutoShrinkInput();
+			
+		if (bOnlyOnce)
+			$('#' + iId + ' input[type=text]').val('').show();
+		else
+			fAutoShrinkInput();
 	});
 
 	fAutoShrinkInput = function () {
-		var iWidthCont = $('#' + id + '.bx-form-input-autotoken').innerWidth();
+		var iWidthCont = $('#' + iId + '.bx-form-input-autotoken').innerWidth();
 		var iWidthExisting = 0;
-		$('#' + id + '.bx-form-input-autotoken b').each(function () {
+		$('#' + iId + '.bx-form-input-autotoken b').each(function () {
 			iWidthExisting += $(this).outerWidth(true);
 		});
-		$('#' + id + '.bx-form-input-autotoken input').width(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
+
+		$('#' + iId + '.bx-form-input-autotoken input').innerWidth(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
 	};
 
-	fAutoShrinkInput();
+	if (!bOnlyOnce)
+		fAutoShrinkInput();
+	else
+		$('#' + iId + '.bx-form-input-autotoken input').outerWidth('100%');
 };
 
 /** @} */

+ 4 - 2
modules/boonex/market/classes/BxMarketFormEntry.php

@@ -256,8 +256,10 @@ class BxMarketFormEntry extends BxBaseModTextFormEntry
             'id' => $aInput['name'] . time(),
             'url_get_recipients' => $sGetSubentriesUrl,
             'name' => $aInput['name'],
-			'b_img' => false,
-            'placeholder' => $sPlaceholder,
+			'b_img' => 1,
+			'only_once' => 0,
+			'on_select' => 'null',
+		    'placeholder' => $sPlaceholder,
             'vals' => $sVals,
         ));
     }

+ 6 - 1
modules/boonex/payment/classes/BxPaymentFormView.php

@@ -11,10 +11,15 @@
 
 class BxPaymentFormView extends BxTemplStudioFormView
 {
-    function __construct($aInfo, $oTemplate = false)
+	function __construct($aInfo, $oTemplate = false)
     {
         parent::__construct($aInfo, $oTemplate);
     }
+	
+	protected function genCustomInputClient ($aInput)
+	{
+		return parent::genCustomInputUsernamesSuggestions ($aInput);
+	}
 }
 
 /** @} */

+ 11 - 3
modules/boonex/payment/classes/BxPaymentGridProcessed.php

@@ -38,10 +38,18 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
         $oForm->aInputs['client_id']['attrs'] = array(
         	'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client_id'),
         );
-        $oForm->aInputs['client']['attrs'] = array(
-        	'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client'),
+        
+		$oForm->aInputs['client']['attrs'] = array(
+        	'id' => $this->_oModule->_oConfig->getHtmlIds('processed', 'order_processed_client')			
         );
-
+		
+		$oForm->aInputs['client']['ajax_get_suggestions'] = BX_DOL_URL_ROOT . 'modules/?r=' . $this->_oModule->_oConfig->getUri() . '/get_clients';
+		
+		$oForm->aInputs['client']['custom'] = array(
+			'only_once' => true,
+			'on_select' => "function(oObject){{$sJsObject}.paOnShowPopup(oObject);}"
+		);
+				
         $oForm->aInputs['module_id']['attrs'] = array(
 			'onchange' => 'javascript:' . $sJsObject . '.paOnSelectModule(this);'
 		);

+ 1 - 1
modules/boonex/payment/install/sql/install.sql

@@ -331,7 +331,7 @@ INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `c
 ('bx_payment_form_processed', @sName, 'id', '0', '', 0, 'hidden', '_bx_payment_form_processed_input_id_sys', '', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 0, 0),
 ('bx_payment_form_processed', @sName, 'seller_id', '0', '', 0, 'hidden', '_bx_payment_form_processed_input_seller_id_sys', '', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 0, 0),
 ('bx_payment_form_processed', @sName, 'client_id', '0', '', 0, 'hidden', '_bx_payment_form_processed_input_client_id_sys', '', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 0, 0),
-('bx_payment_form_processed', @sName, 'client', '0', '', 0, 'text', '_bx_payment_form_processed_input_client_sys', '_bx_payment_form_processed_input_client', '', 0, 0, 0, '', '', '', 'Avail', '', '_bx_payment_form_processed_input_client_err', 'Xss', '', 0, 0),
+('bx_payment_form_processed', @sName, 'client', '0', '', 0, 'custom', '_bx_payment_form_processed_input_client_sys', '_bx_payment_form_processed_input_client', '', 0, 0, 0, '', '', '', 'Avail', '', '_bx_payment_form_processed_input_client_err', 'Xss', '', 0, 0),
 ('bx_payment_form_processed', @sName, 'order', '0', '', 0, 'text', '_bx_payment_form_processed_input_order_sys', '_bx_payment_form_processed_input_order', '', 0, 0, 0, '', '', '', 'Avail', '', '_bx_payment_form_processed_input_order_err', 'Xss', '', 0, 0),
 ('bx_payment_form_processed', @sName, 'module_id', '0', '', 0, 'select', '_bx_payment_form_processed_input_module_id_sys', '_bx_payment_form_processed_input_module_id', '', 0, 0, 0, '', '', '', 'Avail', '', '_bx_payment_form_processed_input_module_id_err', 'Int', '', 0, 0),
 ('bx_payment_form_processed', @sName, 'items', '0', '', 0, 'custom', '_bx_payment_form_processed_input_items_sys', '_bx_payment_form_processed_input_items', '', 0, 0, 0, '', '', '', '', '', '_bx_payment_form_processed_input_items_err', '', '', 0, 0),

+ 3 - 12
modules/boonex/payment/js/orders.js

@@ -25,18 +25,9 @@ BxPaymentOrders.prototype.init = function(oOptions) {
 };
 
 /*--- Manual Order function ---*/
-BxPaymentOrders.prototype.paOnShowPopup = function(oSelect) {
-	var $this = this;
-
-	$('#' + this._aHtmlIds['order_processed_client']).autocomplete({
-        source: this._sActionsUrl + 'get_clients/',
-        select: function(oEvent, oUi) {
-        	$('#' + $this._aHtmlIds['order_processed_client_id']).val(oUi.item.value);
-            $(this).val(oUi.item.label);
-
-            oEvent.preventDefault();
-        }
-    });
+BxPaymentOrders.prototype.paOnShowPopup = function(oUi) {
+	console.log(oUi);
+	$('#' + this._aHtmlIds['order_processed_client_id']).val(oUi.item.value);	
 };
 
 BxPaymentOrders.prototype.paOnSelectModule = function(oSelect) {

+ 0 - 2
modules/boonex/payment/template/order_processed_add.html

@@ -13,8 +13,6 @@
                         glGrids.__object__.processJson(data, '__action__');
                     }
                 });
-
-                __js_object__.paOnShowPopup();
             });
         </script>
     </div>

+ 3 - 3
template/form_field_custom_suggestions.html

@@ -3,7 +3,7 @@
     <input type="text" value="" placeholder="__placeholder__" class="bx-def-font-inputs bx-form-input-text" />
 </div>
 <script>
-$(function(){
-	bx_autocomplete_fields('__id__','__url_get_recipients__', '__name__',__b_img__);
-});
+	$(function(){
+		bx_autocomplete_fields('__id__','__url_get_recipients__','__name__',__b_img__,__only_once__,__on_select__);
+	});
 </script>

+ 4 - 2
template/scripts/BxBaseFormView.php

@@ -955,14 +955,16 @@ BLAH;
             'id' => $aInput['name'] . time() . mt_rand(0, 100),
             'url_get_recipients' => $aInput['ajax_get_suggestions'],
             'name' => $aInput['name'],
-			'b_img' => true,
+			'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
+			'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
+			'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
             'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
             'vals' => $sVals,
         ));
     }
 
     /**
-     * Generate Select Element
+     * Generate Select Element	
      *
      * @param  array  $aInput
      * @return string