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.0 KiB

12 years ago
yii.gii = (function ($) {
12 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({
12 years ago
html: true,
trigger: 'hover',
12 years ago
placement: 'right',
content: $hint.html()
12 years ago
});
12 years ago
});
};
12 years ago
12 years ago
var initStickyInputs = function () {
$('.sticky:not(.error) input[type="text"],select,textarea').each(function () {
12 years ago
var value;
if (this.tagName === 'SELECT') {
12 years ago
value = this.options[this.selectedIndex].text;
} else if (this.tagName === 'TEXTAREA') {
12 years ago
value = $(this).html();
} else {
value = $(this).val();
}
if (value === '') {
12 years ago
value = '[empty]';
}
$(this).before('<div class="sticky-value">' + value + '</div>').hide();
});
$('.sticky-value').on('click', function () {
12 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>');
12 years ago
}
12 years ago
});
12 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 () {
12 years ago
$('.default-view-results,.default-view-files').hide();
$('.default-view button[name="generate"]').hide();
12 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]);
}
});
12 years ago
}
};
})(jQuery);