function transitionPage(selectorToFadeOut, selectorToFadeIn)
{
$(selectorToFadeOut).fadeOut(100, function()
{
$(selectorToFadeIn).fadeIn(100);
});
}
function initMediaWizard()
{
$("#dialog-wizard-form").dialog(
{
autoOpen: false,
height: 550,
width:800,
modal: true,
resizable:false,
close: function()
{
resetWizard();
}
});
$('#existing_attach_sel').change(function()
{
loadAttachment($('#existing_attach_sel option:selected').val());
if($('#existing_attach_sel option:selected').val().length > 0)
{
$("#stage-1 button:contains('Next')").button( "option", "disabled", false );
}
else
{
$("#stage-1 button:contains('Next')").button( "option", "disabled", true );
}
});
$('#existing_attach_sel_2').change(function()
{
loadAttachment($('#existing_attach_sel_2 option:selected').val());
if($('#existing_attach_sel_2 option:selected').val().length > 0)
{
$("#stage-1 button:contains('Next')").button( "option", "disabled", false );
}
else
{
$("#stage-1 button:contains('Next')").button( "option", "disabled", true );
}
});
$('select[name=image_format]').change(function()
{
loadFormat($('select[name=image_format] option:selected').val());
if($('select[name=image_format] option:selected').val().length > 0)
{
$("#stage-3-image button:contains('Next')").button( "option", "disabled", false );
}
else
{
$("#stage-3-image button:contains('Next')").button( "option", "disabled", true );
}
});
$('select[name=relationship]').change(function()
{
loadFormat($('select[name=relationship] option:selected').val());
if($('select[name=relationship] option:selected').val().length > 0)
{
$("#stage-3-other button:contains('Next')").button( "option", "disabled", false );
}
else
{
$("#stage-3-other button:contains('Next')").button( "option", "disabled", true );
}
});
/* Set form validation */
$("#upload_form").validate(
{
submitHandler: function(oForm)
{
uploadAttachment(oForm);
}
});
$('#media_form').validate(
{
submitHandler: function(oForm)
{
createMediaData(oForm);
}
});
$('#create_format_form').validate(
{
submitHandler: function(oForm)
{
createFormat(oForm);
}
});
/* Set click handlers */
addFileChangeHandler();
$("#media_type").change(function()
{
$("#stage-2 input[name=type]").val($("#media_type option:selected").val());
});
$("#dialog-wizard-form button:contains('Cancel'), #stage-2-success button:contains('Finish')").button().click(function(evt)
{
evt.preventDefault();
$("#dialog-wizard-form").dialog("close");
});
$("#stage-1 button:contains('Next')").button().click(function()
{
if($('input[name=attach-choice-group]:checked').val() == "Existing")
{
$("input[name=attachment_id]").val($('#existing_attach_sel option:selected').val());
//lookup id
$.getJSON(CONTEXT_PATH + '/resources/attachments/' + $('#existing_attach_sel option:selected').val() + '.json' , function()
{
})
.success(function(data)
{
if(data.type.toLowerCase() === 'image')
{
populateImgResizeFormats(data.id);
transitionPage("#stage-1","#stage-3-image");
}
else
{
populateRelationships();
transitionPage("#stage-1","#stage-3-other");
}
})
.error(function(data)
{
alert("error looking up attachment");
//alert(JSON.stringify(data));
});
}
else if($('input[name=attach-choice-group]:checked').val() == "Assigned")
{
$("input[name=attachment_id]").val($('#existing_attach_sel_2 option:selected').val());
//lookup id
$.getJSON(CONTEXT_PATH + '/resources/attachments/' + $('#existing_attach_sel_2 option:selected').val() + '.json' , function()
{
})
.success(function(data)
{
if(data.type.toLowerCase() === 'image')
{
populateImgResizeFormats(data.id);
transitionPage("#stage-1","#stage-3-image");
}
else
{
populateRelationships();
transitionPage("#stage-1","#stage-3-other");
}
})
.error(function(data)
{
alert("error looking up attachment");
//alert(JSON.stringify(data));
});
}
else
{
transitionPage("#stage-1","#stage-2");
}
});
$("#stage-2 button:contains('Upload')").button().click(function(evt)
{
evt.preventDefault();
$("#upload_form").submit();
});
$("#stage-2 button:contains('Back')").button().click(function(evt)
{
evt.preventDefault();
transitionPage("#stage-2", "#stage-1");
});
$("#stage-2-fail button:contains('Back')").button().click(function()
{
transitionPage("#stage-2-fail", "#stage-1");
});
$("#stage-2-success button:contains('Next')").button().click(function()
{
var fname = $("#upload_file").val();
// this required for ie
if(fname && fname.lastIndexOf('\\') > 0)
{
fname = fname.substring(fname.lastIndexOf('\\') + 1);
}
fname.replace(/%/g,'%25');
//lookup id
$.post(CONTEXT_PATH + '/resources/attachments/0/lookup?filename=' + fname , function()
{
})
.success(function(data)
{
$("input[name=attachment_id]").val(data.id);
if(data.type.toLowerCase() === 'image')
{
populateImgResizeFormats(data.id);
$("input[name=base_height]").val(data.height);
$("input[name=base_width]").val(data.width);
transitionPage("#stage-2-success","#stage-3-image");
}
else
{
populateRelationships();
transitionPage("#stage-2-success","#stage-3-other");
}
})
.error(function(data)
{
alert("error looking up attachment by filename");
//alert(JSON.stringify(data));
});
});
$("#stage-3-image button:contains('Next')").button().click(function(evt)
{
evt.preventDefault();
if($('input[name=format-choice-group]:checked').val() == "Existing")
{
transitionPage("#stage-3-image","#stage-5");
}
else
{
transitionPage("#stage-3-image","#stage-4");
}
});
$("#stage-3-other button:contains('Next')").button().click(function(evt)
{
evt.preventDefault();
transitionPage("#stage-3-other","#stage-5");
});
$("#stage-4 button:contains('Back')").button().click(function(evt)
{
evt.preventDefault();
transitionPage("#stage-4", "#stage-3-image");
});
$("#stage-4 button:contains('Next')").button().click(function(evt)
{
evt.preventDefault();
$('#create_format_form').submit();
});
$("#stage-4-success button:contains('Next')").button().click(function(evt)
{
evt.preventDefault();
populateImgResizeFormats($("input[name=attachment_id]").val());
transitionPage("#stage-4-success", "#stage-3-image");
});
$("#stage-5 button:contains('Next')").button().click(function(evt)
{
evt.preventDefault();
$('#media_form').submit();
});
$("#stage-5-success button:contains('Finish')").button().click(function(evt)
{
evt.preventDefault();
notifyChangeMade();
if($("#addThis:checked").val() === 'on')
{
addMediaDataItem($('#media_record_id').val(), $('dd.wizard'), $('#media_schema_field').val());
}
$("#dialog-wizard-form").dialog("close");
});
$("[name=format-choice-group]").change(function()
{
if($('input[name=format-choice-group]:checked').val() == "Existing")
{
$("select[name=image_format]").removeAttr('disabled');
if($('select[name=image_format] option:selected').val().length == 0)
{
$("#stage-3-image button:contains('Next')").button( "option", "disabled", true );
}
}
else
{
$("#stage-3-image button:contains('Next')").button( "option", "disabled", false );
$("select[name=image_format]").attr('disabled','disabled');
}
});
$("[name=attach-choice-group]").change(function()
{
if($('input[name=attach-choice-group]:checked').val() == "Existing")
{
$("#stage-1 .exist").show();
$("#stage-1 .assigned").hide();
if($('#existing_attach_sel option:selected').val().length == 0)
{
$("#stage-1 button:contains('Next')").button( "option", "disabled", true );
}
}
else if($('input[name=attach-choice-group]:checked').val() == "Assigned")
{
$("#stage-1 .assigned").show();
$("#stage-1 .exist").hide();
if($('#existing_attach_sel_2 option:selected').val().length == 0)
{
$("#stage-1 button:contains('Next')").button( "option", "disabled", true );
}
}
else
{
resetWizard();
$("#stage-1 button:contains('Next')").button( "option", "disabled", false );
$("#stage-1 .exist, #stage-1 .assigned").hide();
}
});
$('#artifacts').click(function()
{
if($(this).is(':checked'))
{
$("#small_size").removeAttr('disabled').addClass('required');
$("#small_size").parent().prev().addClass('mandatory');
$("#medium_size").removeAttr('disabled').addClass('required');
$("#medium_size").parent().prev().addClass('mandatory');
$("#large_size").removeAttr('disabled').addClass('required');
$("#large_size").parent().prev().addClass('mandatory');
$("#resize_dimension").removeAttr('disabled').addClass('required');
$("#resize_dimension").parent().prev().addClass('mandatory');
}
else
{
$("#small_size").attr('disabled','disabled').removeClass('required');
$("#small_size").parent().prev().removeClass('mandatory');
$("#medium_size").attr('disabled','disabled').removeClass('required');
$("#medium_size").parent().prev().removeClass('mandatory');
$("#large_size").attr('disabled','disabled').removeClass('required');
$("#large_size").parent().prev().removeClass('mandatory');
$("#resize_dimension").attr('disabled','disabled').removeClass('required');
$("#resize_dimension").parent().prev().removeClass('mandatory');
}
});
}
function loadAttachmentsList()
{
$('#existing_attach_sel').html('');
$.getJSON(CONTEXT_PATH + '/resources/attachments.json', function(data)
{
})
.success(function(data)
{
for(var attach_iter = 0; attach_iter < data.length; ++attach_iter )
{
$('#existing_attach_sel').append('');
}
$("#existing_attach_sel").combobox();
})
.error(function(data)
{
//alert(JSON.stringify(data));
alert("failed to load attachments list");
});
}
function loadRelatedAttachmentsList()
{
$('#existing_attach_sel_2').html('');
$.getJSON(CONTEXT_PATH + '/resources/attachments.json?resource_identifier=' + $('#stage-2 input[name="identifier"]').val() , function(data)
{
})
.success(function(data)
{
for(var attach_iter = 0; attach_iter < data.length; ++attach_iter )
{
$('#existing_attach_sel_2').append('');
}
$("#existing_attach_sel_2").combobox();
})
.error(function(data)
{
//alert(JSON.stringify(data));
alert("failed to load attachments list");
});
}
function loadAttachment(attachment_id)
{
$(".attach_preview").html("")
if(attachment_id && attachment_id.length > 0)
{
//get attachment
$.getJSON(CONTEXT_PATH + '/resources/attachments/' + attachment_id + '.json' , function()
{
})
.success(function(data)
{
if(data.type.toLowerCase() === 'image')
{
$(".attach_preview").append('');
$(".attach_preview").append('