File: /home/imensosw/www/imenso.co/matrix/js/common.js
var app= {};
app.document={docId:"", rowId:"", assignment_no:""};
app.location = window.location.origin+"/matrix/";
if(window.location.hostname=="sh018.hostgator.tempwebhost.net")
{
app.location = "http://sh018.hostgator.tempwebhost.net/~a16102wt/matrix/";
}
$(document).ready(function(){
app.getData();
});
$(document).on('click', '#row_link', function(){
app.document.assignment_no = location.search.split('assignment_no=')[1];
app.document.docId = $(this).attr('data-doc_id');
app.document.rowId = $(this).attr('data-row_id');
$.ajax({
url: app.location+"post_data.php",
type: "POST",
data: { get_detail : true , assignment_no : app.document.assignment_no , docId:$(this).attr('data-doc_id') },
dataType:"json",
success:function(result)
{
$("#title").val(result.doc_title);
$("#date").val(result.doc_date);
$("#description").val(result.doc_description);
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
app.clickToDocId();
});
$(document).on('click', '#submit_button', function(e){
e.preventDefault();
app.handleForm();
});
app.getData = function(){
var default_length = $('ul.list-group > li.default').length;
var done_length = $('ul.list-group > li.done').length;
var doubt_length = $('ul.list-group > li.doubt').length;
$('#doc_default').html(default_length);
$('#doc_done').html(done_length);
$('#doc_doubt').html(doubt_length);
$('#total_doc').html(default_length+done_length);
if ($('ul.list-group > li').hasClass('default')) {
if(length>0)
{
$('ul.list-group > li.default:first>a').trigger('click');
$('ul.list-group > li.default:first').addClass('active');
}
else{
}
}
}
app.clickToDocId = function(){
$("#row_iframe").attr("src","docs/"+app.document.assignment_no+"/"+app.document.docId+".pdf");
$("#rowId").val(app.document.rowId);
$("#docId").val(app.document.docId);
$('ul.list-group > li.active').removeClass('active');
$('ul').find('[data-doc_id="'+app.document.docId+'"]').closest('li').addClass('active');
}
app.handleForm = function(){
app.addForm();
app.submitForm();
}
app.addForm = function() {
app.formData={
assignment_no:app.document.assignment_no,
docId:app.document.docId,
rowId:app.document.rowId,
title:$('#title').val().trim(),
date:$('#date').val().trim(),
description:$('#description').val().trim(),
}
}
app.validateForm = function(){
var error=[];
if(app.formData.title=="") {
error.push("Please enter title");
}
if(app.formData.date=="") {
error.push("Please enter start date");
}
if(app.formData.description=="") {
error.push("Please enter description");
}
return error;
}
app.submitForm = function(){
if( $(".error").attr('status') == 'block')
{
return false ;
}
$.ajax({
url: app.location+"post_data.php",
type: "POST",
data: {formData:app.formData},
dataType:"html",
success:function(result){
if(result.status=="default"){
if($('ul.list-group > li.active>a').attr('data-doc_id')==app.document.docId) {
$('ul.list-group > li.active').addClass('default');
$('ul.list-group > li.active').removeClass('done');
if($('ul.list-group > li.active').hasClass('doubt')) {
$('ul.list-group > li.active').removeClass('doubt');
}
}
}
else{
// alert("success");
if($('ul.list-group > li.active>a').attr('data-doc_id')==app.document.docId) {
if(result.status=="doubt") {
$('ul.list-group > li.active').addClass('done doubt');
}
$('ul.list-group > li.active').addClass('done');
$('ul.list-group > li.active').removeClass('default');
}
$('ul.list-group > li.active').removeClass('active');
if ($('ul.list-group > li').hasClass('default')) {
var length = $('ul.list-group > li.default').length;
if(length>0) {
$('ul.list-group > li.default:first>a').trigger('click');
$('ul.list-group > li.default:first').addClass('active');
}
}
$( '#formAddRow' ).each(function(){
this.reset();
});
app.getData();
if($('ul.list-group > li.done').length == $('ul.list-group > li').length )
{
app.myFunction();
}
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
// alert("Can't open file. It may be in use");
}
});
}
app.myFunction = function()
{
var r = confirm("Do you want to submit the file!");
if (r == true)
{
$.ajax({
url: app.location+"post_data.php",
type: "POST",
data: {assignment_no: app.document.assignment_no , assignment_status_id:2 },
dataType:"json",
success:function(result){
console.log(result.status);
if(result.status == "fail")
{
alert(result.message);
// window.location.href = app.location;
}
else {
// alert(333);
window.location.href = app.location;
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
}
}