//= require rails_admin/custom/ckeditor_ajax (function($) { function nearestField($input) { return $input.closest('.form-group, .control-group'); } function buildProductLocaleTabs() { var $form = $('form').filter(function() { return $(this).find('[name="product[name]"]').length > 0; }).first(); if ($form.length === 0) { return; } var fieldMap = [ { key: 'zh-CN', label: '简体中文', nameField: nearestField($form.find('[name="product[name]"]')), detailField: nearestField($form.find('[name="product[detail]"]')) }, { key: 'en', label: 'English', nameField: nearestField($form.find('[name="product[name_en]"]')), detailField: nearestField($form.find('[name="product[detail_en]"]')) }, { key: 'ru', label: 'Русский', nameField: nearestField($form.find('[name="product[name_ru]"]')), detailField: nearestField($form.find('[name="product[detail_ru]"]')) }, { key: 'zh-TW', label: '繁體中文', nameField: nearestField($form.find('[name="product[name_tw]"]')), detailField: nearestField($form.find('[name="product[detail_tw]"]')) } ]; if ($form.find('.product-locale-tabs').length > 0) { return; } var hasAllFields = true; $.each(fieldMap, function(_, group) { if (group.nameField.length === 0 || group.detailField.length === 0) { hasAllFields = false; return false; } }); if (!hasAllFields) { return; } var $anchor = fieldMap[0].nameField; var $mount = $('
'); $anchor.before($mount); var $tabs = $(''); var $header = $('名称与详情按语言分别维护,未填写时接口默认回退到简体中文。