/**
     *	Return the page content to add a new item
     *
     *	@return string The html code that output the interface for adding a nem item
     */
    function elementEdition($itemToEdit = '')
    {
        global $attribute_displayed_field, $attribute_options_group;
        $dbFieldList = wpshop_database::fields_to_input(self::getDbTable());
        $editedItem = '';
        if ($itemToEdit != '') {
            $editedItem = self::getElement($itemToEdit);
        }
        $the_form_content_hidden = $the_form_general_content = '';
        $the_form_option_content_list = array();
        foreach ($dbFieldList as $input_key => $input_def) {
            if (!isset($attribute_displayed_field) || !is_array($attribute_displayed_field) || in_array($input_def['name'], $attribute_displayed_field)) {
                $input_def['label'] = $input_def['name'];
                $input_def_id = $input_def['id'] = 'wpshop_' . self::currentPageCode . '_edition_table_field_id_' . $input_def['label'];
                $pageAction = isset($_REQUEST[self::getDbTable() . '_action']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable() . '_action']) : '';
                $requestFormValue = isset($_REQUEST[self::currentPageCode][$input_def['label']]) ? wpshop_tools::varSanitizer($_REQUEST[self::currentPageCode][$input_def['label']]) : '';
                $currentFieldValue = $input_def['value'];
                if (is_object($editedItem)) {
                    $currentFieldValue = $editedItem->{$input_def}['label'];
                } elseif ($pageAction != '' && $requestFormValue != '') {
                    $currentFieldValue = $requestFormValue;
                }
                if ($input_def['label'] == 'status') {
                    if (in_array('notused', $input_def['possible_value'])) {
                        $key = array_keys($input_def['possible_value'], 'notused');
                        unset($input_def['possible_value'][$key[0]]);
                    }
                    if (in_array('dbl', $input_def['possible_value'])) {
                        $key = array_keys($input_def['possible_value'], 'dbl');
                        unset($input_def['possible_value'][$key[0]]);
                    }
                    $input_def['type'] = 'checkbox';
                    $input_def['label'] = __('Use this attribute', 'wpshop');
                    $input_def['possible_value'] = array('valid');
                    $input_def_id .= '_valid';
                    $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for using this attribute', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                }
                if (substr($input_def['label'], 0, 3) == 'is_' || $input_def['label'] == '_display_informations_about_value') {
                    $input_def['type'] = 'checkbox';
                    $input_def['possible_value'] = 'yes';
                }
                switch ($input_def['label']) {
                    case 'is_requiring_unit':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for using unit with this attribute', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_visible_in_front':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for displaying this attribute in shop', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_visible_in_front_listing':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for displaying this attribute in product listing in shop', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_used_for_sort_by':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for displaying this attribute into sortbar', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_searchable':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for including values of this attribute as search parameter', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_visible_in_advanced_search':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box for using in advanced search form', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'frontend_css_class':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Separate with a space each CSS Class', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'backend_css_class':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Separate with a space each CSS Class', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_historisable':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if you want to save the different value this attribute, each time it is modified', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_filterable':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if you want to use this attribute in the filter search', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_intrinsic':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if this attribute is intrinsic for a product', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_used_for_variation':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if this attribute is used for variation. It means that the user would be able to choose a value in frontend', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                    case 'is_used_in_variation':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if you want to use this attribute for variation definition', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        if (!empty($editedItem) && $editedItem->is_used_for_variation == 'yes') {
                            $input_def['option'] = 'disabled="disabled"';
                        }
                        break;
                    case 'is_user_defined':
                        $input_def['options_label']['custom'] = '<a href="#" title="' . __('Check this box if you want your customer to choose a value for this attribute into frontend product', 'wpshop') . '" class="wpshop_infobulle_marker">?</a>';
                        break;
                }
                $input_def['value'] = $currentFieldValue;
                if ($input_def['label'] == 'code') {
                    $input_def['type'] = 'hidden';
                } elseif ($input_def['label'] == 'entity_id') {
                    $input_def['possible_value'] = wpshop_entities::get_entities_list();
                    $input_def['valueToPut'] = 'index';
                    $input_def['type'] = 'select';
                    $i = 0;
                    foreach ($input_def['possible_value'] as $entity_id => $entity_name) {
                        if ($i <= 0) {
                            $current_entity_id = $entity_id;
                        }
                        $i++;
                    }
                } elseif ($input_def['label'] == '_unit_group_id') {
                    $input_def['possible_value'] = wpshop_attributes_unit::get_unit_group();
                    $input_def['type'] = 'select';
                } elseif ($input_def['label'] == '_default_unit') {
                    $unit_group_list = wpshop_attributes_unit::get_unit_group();
                    $input_def['possible_value'] = wpshop_attributes_unit::get_unit_list_for_group(!empty($editedItem->_unit_group_id) ? $editedItem->_unit_group_id : (!empty($unit_group_list) ? $unit_group_list[0]->id : ''));
                    $input_def['type'] = 'select';
                } elseif ($input_def['label'] == 'backend_input') {
                    if (!is_object($editedItem)) {
                        $input_def['type'] = 'hidden';
                    } else {
                        $new_possible_value = array();
                        switch ($editedItem->data_type) {
                            case 'integer':
                                $new_possible_value[__('Checkbox', 'wpshop')] = 'checkbox';
                                $new_possible_value[__('Radio button', 'wpshop')] = 'radio';
                                $new_possible_value[__('select', 'wpshop')] = 'select';
                                $new_possible_value[__('multiple-select', 'wpshop')] = 'multiple-select';
                                break;
                            case 'varchar':
                                switch ($input_def['value']) {
                                    case 'hidden':
                                        $new_possible_value[__('Hidden field', 'wpshop')] = 'hidden_field';
                                        break;
                                    case 'password':
                                        $new_possible_value[__('Password field', 'wpshop')] = 'pass_field';
                                        break;
                                    default:
                                        $new_possible_value[__('Text field', 'wpshop')] = 'short_text';
                                        break;
                                }
                                break;
                            case 'text':
                                $new_possible_value[__('Textarea field', 'wpshop')] = 'textarea';
                                break;
                            case 'decimal':
                                $new_possible_value[__('Number field', 'wpshop')] = 'float_field';
                                break;
                            case 'datetime':
                                $new_possible_value[__('Date field', 'wpshop')] = 'date_field';
                                break;
                        }
                        $input_def['possible_value'] = $new_possible_value;
                    }
                } elseif ($input_def['label'] == 'frontend_input') {
                    $new_possible_value = array();
                    if (is_object($editedItem)) {
                        switch ($editedItem->data_type) {
                            case 'integer':
                                $new_possible_value[__('Checkbox', 'wpshop')] = 'checkbox';
                                $new_possible_value[__('Radio button', 'wpshop')] = 'radio';
                                $new_possible_value[__('select', 'wpshop')] = 'select';
                                $new_possible_value[__('multiple-select', 'wpshop')] = 'multiple-select';
                                break;
                            case 'varchar':
                                switch ($input_def['value']) {
                                    case 'hidden':
                                        $new_possible_value[__('Hidden field', 'wpshop')] = 'hidden_field';
                                        break;
                                    case 'password':
                                        $new_possible_value[__('Password field', 'wpshop')] = 'pass_field';
                                        break;
                                    default:
                                        $new_possible_value[__('Text field', 'wpshop')] = 'short_text';
                                        break;
                                }
                                break;
                            case 'text':
                                $new_possible_value[__('Textarea field', 'wpshop')] = 'textarea';
                                break;
                            case 'decimal':
                                $new_possible_value[__('Number field', 'wpshop')] = 'float_field';
                                break;
                            case 'datetime':
                                $new_possible_value[__('Date field', 'wpshop')] = 'date_field';
                                break;
                        }
                    } else {
                        $new_possible_value[__('Text field', 'wpshop')] = 'short_text';
                        $new_possible_value[__('Number field', 'wpshop')] = 'float_field';
                        $new_possible_value[__('Date field', 'wpshop')] = 'date_field';
                        $new_possible_value[__('Textarea field', 'wpshop')] = 'textarea';
                        $new_possible_value[__('Password field', 'wpshop')] = 'pass_field';
                        $new_possible_value[__('Hidden field', 'wpshop')] = 'hidden_field';
                        $new_possible_value[__('Checkbox', 'wpshop')] = 'checkbox';
                        $new_possible_value[__('Radio button', 'wpshop')] = 'radio';
                        $new_possible_value[__('select', 'wpshop')] = 'select';
                        $new_possible_value[__('multiple-select', 'wpshop')] = 'multiple-select';
                    }
                    $input_def['possible_value'] = $new_possible_value;
                    if (!empty($editedItem->frontend_input)) {
                        switch ($editedItem->frontend_input) {
                            case 'text':
                                switch ($editedItem->data_type) {
                                    case 'varchar':
                                        $input_def['value'] = 'short_text';
                                        break;
                                    case 'decimal':
                                        $input_def['value'] = 'float_field';
                                        break;
                                    case 'datetime':
                                        $input_def['value'] = 'date_field';
                                        break;
                                    case 'hidden':
                                        $input_def['value'] = 'hidden_field';
                                        break;
                                    case 'password':
                                        $input_def['value'] = 'pass_field';
                                        break;
                                }
                                break;
                            default:
                                $input_def['value'] = $editedItem->frontend_input;
                                break;
                        }
                    }
                }
                if (is_object($editedItem) && ($input_def['label'] == 'code' || $input_def['label'] == 'data_type' || $input_def['label'] == 'entity_id')) {
                    // $input_def['type'] = 'hidden';
                    $input_def['option'] = ' disabled="disabled" ';
                    $the_form_content_hidden .= '<input type="hidden" name="' . self::getDbTable() . '[' . $input_def['name'] . ']" value="' . $input_def['value'] . '" />';
                    $input_def['label'] = $input_def['name'];
                    $input_def['name'] = $input_def['name'] . '_already_defined';
                }
                $input_def['value'] = str_replace("\\", "", $input_def['value']);
                $the_input = wpshop_form::check_input_type($input_def, self::getDbTable());
                if ($input_def['label'] == 'default_value') {
                    if (!empty($editedItem->frontend_input)) {
                        switch ($editedItem->frontend_input) {
                            case 'text':
                                $input_def['type'] = 'text';
                                switch ($editedItem->data_type) {
                                    case 'datetime':
                                        $the_input = wpshop_attributes::attribute_type_date_config(unserialize($input_def['value']));
                                        $input_def['label'] = __('Date field configuration', 'wpshop');
                                        break;
                                    default:
                                        $the_input = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE);
                                        break;
                                }
                                break;
                            case 'hidden':
                                $the_input = '';
                                break;
                            case 'password':
                                $the_input = '';
                                break;
                            case 'select':
                            case 'multiple-select':
                            case 'radio':
                            case 'checkbox':
                                $input_def['label'] = __('Options list for attribute', 'wpshop') . '
<div class="alignright wpshop_change_select_data_type" >
	+' . __('Change data type for this attribute', 'wpshop') . '
</div>';
                                $the_input = wpshop_attributes::get_select_options_list($itemToEdit, $editedItem->data_type_to_use);
                                break;
                            case 'textarea':
                                $input_def['type'] = 'textarea';
                                $the_input = wpshop_form::check_input_type($input_def, WPSHOP_DBT_ATTRIBUTE);
                                break;
                        }
                    } else {
                        $input_def['type'] = 'text';
                        $the_input = wpshop_form::check_input_type($input_def, self::getDbTable());
                    }
                }
                if ($input_def['label'] == '_unit_group_id') {
                    $the_input .= '<div id="wpshop_loader_input_group_unit"></div>';
                    $the_input .= '<a class="button-primary" href="#wpshop_unit_group_list" id="wpshop_attribute_group_unit_manager_opener">' . __('Manage group unit', 'wpshop') . '</a>';
                }
                if ($input_def['label'] == '_default_unit') {
                    $the_input .= '<div id="wpshop_loader_input_unit"></div>';
                    $the_input .= '<a class="button-primary" href="#wpshop_unit_list" id="wpshop_attribute_unit_manager_opener">' . __('Manage units', 'wpshop') . '</a>';
                    $the_input .= '<input type="hidden" name="input_wpshop_load_attribute_unit_list" id="input_wpshop_load_attribute_unit_list" value="' . wp_create_nonce("wpshop_load_attribute_unit_list") . '" />';
                    $the_input .= '<div id="wpshop_attribute_unit_manager" title="' . __('Unit management', 'wpshop') . '" class="wpshopHide" ><div class="loading_picture_container" id="product_chooser_picture" ><img src="' . WPSHOP_LOADING_ICON . '" alt="loading..." /></div></div>';
                }
                if ($input_def['type'] != 'hidden') {
                    if ($input_def['label'] == 'entity_id' && is_object($editedItem)) {
                        $the_input .= '<br/><span class="wpshop_duplicate_attribute" >' . __('Duplicate this attribute to another entity', 'wpshop') . '</span>';
                    }
                    $input = '
		<tr class="wpshop_' . self::currentPageCode . '_edition_table_line wpshop_' . self::currentPageCode . '_edition_table_line_' . $input_def['name'] . '" >
			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_label wpshop_' . self::currentPageCode . '_edition_table_field_label_' . $input_def['name'] . '" ><label for="' . $input_def_id . '" >' . __($input_def['label'], 'wpshop') . '</label></td>
			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_input wpshop_' . self::currentPageCode . '_edition_table_field_input_' . $input_def['name'] . '" >' . $the_input . '</td>
		</tr>';
                    if (substr($input_def['label'], 0, 3) == 'is_' || substr($input_def['label'], 0, 1) == '_' || in_array($input_def['label'], unserialize(WPSHOP_ATTRIBUTE_DEF_COLUMN_INTO_OPTIONS))) {
                        $the_form_option_content_list[$input_def['label']] = $input;
                    } else {
                        $the_form_general_content .= $input;
                        if ($input_def['label'] == 'frontend_input' && !is_object($editedItem)) {
                            $the_input = wpshop_attributes_set::get_attribute_set_complete_list($current_entity_id, self::getDbTable(), self::currentPageCode);
                            $input = '
		<tr class="wpshop_' . self::currentPageCode . '_edition_table_line wpshop_' . self::currentPageCode . '_edition_table_line_set_section" >
			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_label wpshop_' . self::currentPageCode . '_edition_table_field_label_set_section" ><label for="' . self::currentPageCode . '_set_section" >' . __('Affect this new attribute to the set section', 'wpshop') . '</label></td>
			<td class="wpshop_' . self::currentPageCode . '_edition_table_cell wpshop_' . self::currentPageCode . '_edition_table_field_input wpshop_' . self::currentPageCode . '_edition_table_field_input_set_section" >' . $the_input . '</td>
		</tr>';
                            $the_form_general_content .= $input;
                        }
                    }
                } else {
                    $the_form_content_hidden .= '
				' . $the_input;
                }
            }
        }
        $section_legend = '';
        $section_page_code = self::currentPageCode;
        $section_content = $the_form_general_content;
        ob_start();
        include WPSHOP_TEMPLATES_DIR . 'admin/admin_box_section.tpl.php';
        $the_form_general_content = ob_get_contents();
        ob_end_clean();
        /** It is attribute TVA, add a button to calcilate price in mass **/
        if (!empty($editedItem) && !empty($editedItem->code) && $editedItem->code == 'tx_tva') {
            $the_form_general_content .= '<input type="button" id="wps_update_price_infos" value="' . __('Update all products price', 'wpshop') . '" /> <img src="' . WPSHOP_LOADING_ICON . '" alt="" id="update_products_loader" /> <br/>';
            $the_form_general_content .= __('If you have updated your VAT rates, save it and update your products price after', 'wpshop');
        }
        if (!empty($the_form_option_content_list)) {
            $the_form_option_content_section = '';
            foreach ($attribute_options_group as $group_name => $group_content) {
                $section_content = '';
                foreach ($group_content as $group_code) {
                    if (array_key_exists($group_code, $the_form_option_content_list)) {
                        $section_content .= $the_form_option_content_list[$group_code];
                        unset($the_form_option_content_list[$group_code]);
                    }
                }
                $section_legend = __($group_name, 'wpshop');
                $section_page_code = self::currentPageCode;
                ob_start();
                include WPSHOP_TEMPLATES_DIR . 'admin/admin_box_section.tpl.php';
                $the_form_option_content_section .= ob_get_contents();
                ob_end_clean();
            }
            /*	Check there are other attributes to display not in defined group	*/
            if (!empty($the_form_option_content_list)) {
                $section_legend = __('General options', 'wpshop');
                $section_content = implode('', $the_form_option_content_list);
                $section_page_code = self::currentPageCode;
                ob_start();
                include WPSHOP_TEMPLATES_DIR . 'admin/admin_box_section.tpl.php';
                $the_form_option_content = ob_get_contents();
                ob_end_clean();
                $the_form_option_content .= $the_form_option_content_section;
            }
        }
        /*	Default content for the current page	*/
        $bloc_list[self::currentPageCode]['main_info']['title'] = __('Main informations', 'wpshop');
        $bloc_list[self::currentPageCode]['main_info']['content'] = $the_form_general_content;
        $bloc_list[self::currentPageCode]['options']['title'] = __('Options', 'wpshop');
        $bloc_list[self::currentPageCode]['options']['content'] = $the_form_option_content;
        $the_form = '
<form name="' . self::getDbTable() . '_form" id="' . self::getDbTable() . '_form" method="post" action="#" >
	' . wpshop_form::form_input(self::getDbTable() . '_action', self::getDbTable() . '_action', isset($_REQUEST['action']) && $_REQUEST['action'] != '' ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'save', 'hidden') . '
	' . wpshop_form::form_input(self::currentPageCode . '_form_has_modification', self::currentPageCode . '_form_has_modification', 'no', 'hidden') . $the_form_content_hidden . wpshop_display::custom_page_output_builder($bloc_list, WPSHOP_ATTRIBUTE_EDITION_PAGE_LAYOUT) . '
</form>
<div title="' . __('Change data type for selected attribute', 'wpshop') . '" id="wpshop_dialog_change_select_data_type" ><div id="wpshop_dialog_change_select_data_type_container" ></div></div>';
        $input_def['possible_value'] = wpshop_entities::get_entities_list();
        unset($input_def['possible_value'][$current_entity_id]);
        $input_def['valueToPut'] = 'index';
        $input_def['type'] = 'select';
        $input_def['name'] = 'wpshop_entity_to_duplicate_to';
        $input_def['id'] = 'wpshop_entity_to_duplicate_to';
        $the_form .= '
<div title="' . __('Duplicate attribute to another entity', 'wpshop') . '" id="wpshop_dialog_duplicate_attribute" >
	' . __('Choose an entity to copy the selected attribute to', 'wpshop') . '
	' . wpshop_form::check_input_type($input_def) . '
</div>';
        $the_form .= '
<script type="text/javascript" >
	wpshop(document).ready(function(){
		wpshopMainInterface("' . self::getDbTable() . '", "' . __('Are you sure you want to quit this page? You will loose all current modification', 'wpshop') . '", "' . __('Are you sure you want to delete this attributes group?', 'wpshop') . '");

		jQuery("#wpshop_dialog_duplicate_attribute").dialog({
			autoOpen: false,
			width: 500,
			height: 100,
			modal: true,
			dialogClass: "wpshop_uidialog_box",
			resizable: false,
			buttons:{
				"' . __('Duplicate', 'wpshop') . '": function(){
					var data = {
						action: "wpshop_duplicate_attribute",
						wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_duplicate_attribute") . '",
						attribute_id: jQuery("#wpshop_attributes_edition_table_field_id_id").val(),
						entity: jQuery("#wpshop_entity_to_duplicate_to").val()
					};
					jQuery.post(ajaxurl, data, function(response) {
						if (response[0]) {
							jQuery("#wpshop_dialog_duplicate_attribute").append(response[1]);
						}
						else {
							alert(response[1]);
						}
					}, "json");
				},
				"' . __('Cancel', 'wpshop') . '": function(){
					jQuery(this).dialog("close");
					jQuery(".wpshop_duplicate_attribute_result").remove();
				}
			}
		});
		jQuery(".wpshop_duplicate_attribute").live("click", function(){
			jQuery("#wpshop_dialog_duplicate_attribute").dialog("open");
		});

		jQuery("#wpshop_dialog_change_select_data_type").dialog({
			autoOpen: false,
			width: 800,
			height: 200,
			modal: true,
			dialogClass: "wpshop_uidialog_box",
			resizable: false,
			buttons:{
				"' . __('Change type', 'wpshop') . '": function(){
					var delete_entity = false;
					if(jQuery("#delete_entity").is(":checked")){
						var delete_entity = true;
					}
					var delete_items_of_entity = false;
					if(jQuery("#delete_items_of_entity").is(":checked")){
						var delete_items_of_entity = true;
					}
					var data = {
						action: "attribute_select_data_type_change",
						wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_change_select_data_type_change") . '",
						attribute_id: jQuery("#wpshop_attributes_edition_table_field_id_id").val(),
						internal_data: jQuery("#internal_data").val(),
						data_type: jQuery("#wpshop_attribute_change_data_type_new_type").val(),
						delete_entity: delete_entity,
						delete_items_of_entity: delete_items_of_entity
					};
					jQuery.post(ajaxurl, data, function(response) {
						jQuery(".wpshop_attributes_edition_table_field_input_default_value").html( response );
						jQuery("#wpshop_dialog_change_select_data_type").dialog("close");
					}, "json");
				},
				"' . __('Cancel', 'wpshop') . '": function(){
					jQuery(this).dialog("close");
				}
			}
		});

		jQuery(".wpshop_attribute_change_select_data_type_deletion_input").live("click",function() {
			var display = false;
			if (jQuery(".wpshop_attribute_change_select_data_type_deletion_input_item").is(":checked") ) {
				display = true;
			}
			if (jQuery(".wpshop_attribute_change_select_data_type_deletion_input_entity").is(":checked") ) {
				display = true;
			}
			if (display) {
				jQuery(".wpshop_attribute_change_data_type_alert").show();
			}
			else {
				jQuery(".wpshop_attribute_change_data_type_alert").hide();
			}
		});

		jQuery(".wpshop_change_select_data_type").live("click",function(){
			jQuery("#wpshop_dialog_change_select_data_type_container").html(jQuery("#wpshopLoadingPicture").html());
			jQuery("#wpshop_dialog_change_select_data_type").dialog("open");

			var data = {
				action: "attribute_select_data_type",
				current_attribute: jQuery("#wpshop_attributes_edition_table_field_id_id").val(),
				wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_change_select_data_type") . '"
			};
			jQuery.post(ajaxurl, data, function(response) {
				jQuery("#wpshop_dialog_change_select_data_type_container").html( response );
			}, "json");

		});
		jQuery("#wpshop_attributes_edition_table_field_id__unit_group_id").change(function(){
			change_unit_list();
		});';
        if (!is_object($editedItem)) {
            $the_form .= '
		jQuery("#wpshop_attributes_edition_table_field_id_frontend_input").change(function(){
			jQuery(".wpshop_attributes_edition_table_field_input_default_value").html(jQuery("#wpshopLoadingPicture").html());

			var data = {
				action: "attribute_output_type",
				current_type: jQuery(this).val(),
				wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_output_type_selection") . '"
			};
			jQuery.post(ajaxurl, data, function(response) {
				jQuery(".wpshop_attributes_edition_table_field_input_default_value").html((response[0]));
				jQuery(".wpshop_attributes_edition_table_field_label_default_value label").html((response[1]));
			}, "json");

// 			var data = {
// 				action: "attribute_frontend_input_type",
// 				current_type: jQuery(this).val(),
// 				wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_frontend_input_type") . '"
// 			};
// 			jQuery.getJSON(ajaxurl, data, function(response) {
// 				jQuery("#wpshop_attributes_edition_table_field_id_frontend_input").html(response);
// 			});

		});';
        }
        $the_form .= '
			jQuery("#wpshop_attributes_edition_table_field_id_entity_id").change(function(){
			jQuery(".wpshop_attributes_edition_table_field_input_set_section").html(jQuery("#wpshopLoadingPicture").html());

			var data = {
				action: "attribute_entity_set_selection",
				current_entity_id: jQuery(this).val(),
				wpshop_ajax_nonce: "' . wp_create_nonce("wpshop_attribute_entity_set_selection") . '"
			};
			jQuery.post(ajaxurl, data, function(response) {
				jQuery(".wpshop_attributes_edition_table_field_input_set_section").html( response );
			}, "json");
		});


		jQuery("#wpshop_attributes_edition_table_field_id_is_used_for_variation").click(function(){
			if ( jQuery(this).is(":checked") ) {
				jQuery("#wpshop_attributes_edition_table_field_id_is_used_in_variation").prop("checked", false);
				jQuery("#wpshop_attributes_edition_table_field_id_is_used_in_variation").prop("disabled", true);
			}
			else {
				jQuery("#wpshop_attributes_edition_table_field_id_is_used_in_variation").prop("disabled", false);
			}
		});
	});
	function change_unit_list(){
		var data = {
					action: "load_attribute_unit_list",
					wpshop_ajax_nonce: jQuery("#input_wpshop_load_attribute_unit_list").val(),
					current_group: jQuery("#wpshop_attributes_edition_table_field_id__unit_group_id").val(),
					selected_list:"unit"
				};
			//Response, update the combo box
				jQuery.post(ajaxurl, data, function(response) {
					if ( response[0] ) {
						jQuery("#wpshop_attributes_edition_table_field_id__default_unit").html(response[1]);
					}
					else {
						alert( response[1] );
					}
				}, "json");

	}
</script>';
        return $the_form;
    }
예제 #2
0
/**
 * Load comboBox of unit or group of unit
 */
function wpshop_ajax_load_attribute_unit_list()
{
    check_ajax_referer('wpshop_load_attribute_unit_list', 'wpshop_ajax_nonce');
    $response = '';
    $current_group = isset($_POST['current_group']) && !empty($_POST['current_group']) ? $_POST['current_group'] : null;
    $selected_list = isset($_POST['selected_list']) && !empty($_POST['selected_list']) ? $_POST['selected_list'] : null;
    $group = wpshop_tools::varSanitizer($current_group);
    $selected_list = wpshop_tools::varSanitizer($selected_list);
    if (!empty($group) && !empty($selected_list)) {
        /* Test if we want display the group unit list OR the unit list */
        if ($selected_list == 'group unit') {
            $list = wpshop_attributes_unit::get_unit_group();
        } else {
            $list = wpshop_attributes_unit::get_unit_list_for_group($group);
        }
        foreach ($list as $unit) {
            $response .= '<option value="' . $unit->id . '" ' . ($current_group == $unit->id && $selected_list == 'group unit' ? 'selected="selected"' : '') . '>' . $unit->name . '</option>';
        }
        $result = array(true, $response);
    } else {
        $result = array(false, __('Incorrect order request', 'wpshop'));
    }
    echo json_encode($result);
    die;
}