Yii2 Bootstrap 3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.1 KiB

11 years ago
yii.gii = (function ($) {
11 years ago
var isActive = $('.default-view').length > 0;
var initHintBlocks = function () {
$('.hint-block').each(function () {
var $hint = $(this);
$hint.parent().find('label').addClass('help').popover({
11 years ago
html: true,
trigger: 'hover',
11 years ago
placement: 'right',
content: $hint.html()
11 years ago
});
11 years ago
});
};
11 years ago
11 years ago
var initStickyInputs = function () {
11 years ago
$('.sticky:not(.error)').find('input[type="text"],select,textarea').each(function () {
11 years ago
var value;
if (this.tagName === 'SELECT') {
11 years ago
value = this.options[this.selectedIndex].text;
} else if (this.tagName === 'TEXTAREA') {
11 years ago
value = $(this).html();
} else {
value = $(this).val();
}
if (value === '') {
11 years ago
value = '[empty]';
}
$(this).before('<div class="sticky-value">' + value + '</div>').hide();
});
$('.sticky-value').on('click', function () {
11 years ago
$(this).hide();
$(this).next().show().get(0).focus();
});
};
var initPreviewDiffLinks = function () {
$('.preview-code,.diff-code').on('click', function () {
var $modal = $('#preview-modal');
var $link = $(this);
$modal.find('.modal-title').text($link.data('title'));
$modal.find('.modal-body').html('Loading ...');
$modal.modal('show');
$.ajax({
type: 'POST',
cache: false,
url: $link.prop('href'),
data: $('.default-view form').serializeArray(),
success: function (data) {
$modal.find('.modal-body').html(data);
$modal.find('.content').css('max-height', ($(window).height() - 200) + 'px');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$modal.find('.modal-body').html('<div class="error">' + XMLHttpRequest.responseText + '</div>');
11 years ago
}
11 years ago
});
11 years ago
return false;
});
};
var initConfirmationCheckboxes = function () {
var $checkAll = $('#check-all');
$checkAll.click(function () {
$('.default-view-files table .check input').prop('checked', this.checked);
});
$('.default-view-files table .check input').click(function () {
$checkAll.prop('checked', !$('.default-view-files table .check input:not(:checked)').length);
});
$checkAll.prop('checked', !$('.default-view-files table .check input:not(:checked)').length);
};
return {
init: function () {
initHintBlocks();
initStickyInputs();
initPreviewDiffLinks();
initConfirmationCheckboxes();
// model generator: hide class name input when table name input contains *
$('#model-generator #generator-tablename').on('change', function () {
$('#model-generator .field-generator-modelclass').toggle($(this).val().indexOf('*') == -1);
}).change();
// hide Generate button if any input is changed
$('.default-view .form-group input,select,textarea').change(function () {
11 years ago
$('.default-view-results,.default-view-files').hide();
$('.default-view button[name="generate"]').hide();
11 years ago
});
$('.module-form #generator-moduleclass').change(function () {
var value = $(this).val().match(/(\w+)\\\w+$/);
var $idInput = $('#generator-moduleid');
if (value && value[1] && $idInput.val() == '') {
$idInput.val(value[1]);
}
});
11 years ago
}
};
})(jQuery);