Created
July 11, 2014 08:26
-
-
Save sclinede/c8e986a1f392c830f892 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Обработка событий для YML на СК | |
* | |
*/ | |
app.modules.companyYmlAction = (function(self) { | |
var | |
$clickedButton; | |
function _getContentForPopup(options) { | |
var | |
text; | |
if (options.$checkedRadio.val() === 'archive') { | |
text = options.$popup.data('content_1'); | |
} else { | |
if (options.$checkedRadio.val() === 'delete') { | |
text = options.$popup.data('content_2'); | |
} | |
} | |
return text; | |
} | |
function _showAlertMessage() { | |
// предупреждение о загруженных товарах | |
if ($('.js-tabs-block-yml').data('is_new_record')) { | |
openStaticPopup('js-alert-message-yml'); | |
} | |
} | |
function _initEvents() { | |
$('.js-file-field').change(function() { | |
$('.js-file-name').val($(this).val()); | |
}); | |
$('.js-uf-yml').submit(function(e) { | |
var | |
$this = $clickedButton.closest('.js-uf-yml'), | |
$popup = $('.js-upload-yml-message-popup'), | |
$checkedRadio = $this.find('.js-confirm-radio:checked'), | |
text; | |
$this.find('.js-yml-import-hidden').val($clickedButton.hasClass('js-yml-upload') ? 1 : 0); | |
if ($clickedButton.hasClass('js-yml-upload') && !$this.data('checked')) { | |
text = _getContentForPopup({$popup: $popup, $checkedRadio: $checkedRadio}); | |
if (!text) { | |
return; | |
} | |
$this.data('checked', true); | |
$('.js-sycp-text').text(text); | |
openStaticPopup('js-upload-yml-message-popup'); | |
$doc.one('closepopup', function() { | |
formSubmitter.enableButtons($('.js-uf-yml')[0]); | |
hidePopup('popup-container'); | |
}); | |
e.preventDefault(); | |
} | |
}); | |
$('.js-confirm-checkbox, .js-confirm-radio').change(function() { | |
$(this).closest('.js-uf-yml').data('checked', false); | |
}); | |
$('.js-yml-upload, .js-yml-save').click(function() { | |
$clickedButton = $(this); | |
$clickedButton.attr('type', 'submit') | |
.closest('.js-uf-yml') | |
.find('.js-yml-upload, .js-yml-save') | |
.not(this) | |
.attr('type', 'button'); | |
}); | |
$doc.on('click', '.js-upload-yml-button', function() { | |
var | |
$currentForm = $clickedButton.closest('.js-uf-yml'); | |
hidePopup('popup-container'); | |
$('.js-process-tip').show(); | |
$currentForm.submit(); | |
}); | |
$doc.on('click', '.js-cancel-upload-yml-button', function(e) { | |
e.preventDefault(); | |
formSubmitter.enableButtons($clickedButton.closest('.js-uf-yml')[0]); | |
hidePopup('popup-container'); | |
}); | |
// при изменении полей в одной форме, они меняются и в другой | |
$doc.on('change', '.js-uf-yml input[type!="file"][type!="hidden"], .js-uf-yml select', function() { | |
var | |
$field = $(this), | |
$opposite = $('.js-uf-yml').not($field.closest('.js-uf-yml')).find('[name="' + $field.attr('name') + '"]'); | |
if ($field.is(':checkbox')) { | |
$opposite.prop('checked', $field.prop('checked')); | |
} else { | |
if ($field.is(':radio')) { | |
$opposite.filter('[value="' + $field.val() + '"]').prop('checked', $field.prop('checked')); | |
} else { | |
$opposite.val($field.val()); | |
} | |
} | |
}); | |
} | |
self.load = function init() { | |
_initEvents(); | |
_showAlertMessage(); | |
}; | |
return self; | |
})(app.modules.companyYmlAction || {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment