Mjs.Dialogs.CreateCodeline = {
open : function(type, img) {
$('#codeline_type').val(type);
$("#code_image").attr('src', img);
Mjs.Dialogs.CreateCodeline._open();
},
init : function() {
$("#dialog-create-codeline").dialog({
autoOpen : false,
height : 300,
width : 350,
modal : true,
buttons : {
"Finish" : function() {
Mjs.Dialogs.CreateCodeline._handleFinishButton(this);
},
Cancel : function() {
$(this).dialog("close");
}
},
close : function() {
$("#code_name").val("").removeClass("ui-state-error");
},
open : function() {
Mjs.Dialogs.CreateCodeline._openCreateCodelineDialog(this);
}
});
},
_resetHtml : function(jDialogElement) {
$('.validateTips', jDialogElement).html('Add a new codeline to the page');
},
_open : function() {
var jEl = $("#dialog-create-codeline");
Mjs.Dialogs.CreateCodeline._resetHtml(jEl);
jEl.dialog("open");
},
_openCreateCodelineDialog : function(dialogEl) {
$('#codeline_type').change(
function() {
switch ($(dialogEl).val()) {
case "development":
$("#code_image").attr('src',
'url(css/images/branch_dev.png)');
break;
case "main":
$("#code_image").attr('src',
'url(css/images/branch_main.png)');
break;
case "release":
$("#code_image").attr('src',
'url(css/images/branch_release.png)');
break;
}
});
$("#code_name").focus();
$(dialogEl).data().dialog.uiDialog.handleEnterKey(function() {
Mjs.Dialogs.CreateCodeline._handleFinishButton(dialogEl);
});
},
_handleFinishButton : function(dialogEl) {
var bValid = true;
$("#code_name").removeClass("ui-state-error");
bValid = bValid
&& Mjs.Util.checkLength($("#code_name"), "codeline name", 1,
25, dialogEl);
if (bValid) {
var params = {
type : $("#codeline_type option:selected").val(),
name : $("#code_name").val()
};
Mjs.Collections.codelineCollection.add(params);
$(dialogEl).dialog("close");
}
}
};