@extends('admin/layouts/default')

{{-- Page title --}}
@section('title')
Add Article
@parent
@stop

{{-- page level styles --}}
@section('header_styles')
	@include('admin.layouts.css')


<link rel="stylesheet" href="{{ asset('assets/vendors/bootstrap-tagsinput/css/bootstrap-tagsinput.css') }}" />
<link rel="stylesheet" href="{{ asset('assets/vendors/bootstrap-tagsinput/css/app.css') }}" />
<script type="text/javascript" src="{{ asset('js/author_affiliation.js') }}"></script>
<script>

	var MAMP = MAMP || {};
	MAMP.Subapp = MAMP.Subapp || {};

	MAMP.Subapp.Admin = angular.module('MAMP.Subapp.Admin', []);

	MAMP.Subapp.Admin.config(function($interpolateProvider) 
	{
		$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
	});


</script>
	
	
@stop

{{-- Page content --}}
@section('content')


<section class="content-header">
<!--section starts-->
<h1>Add Article</h1>
<ol class="breadcrumb">
	<li><a href="{{ route('admin.dashboard') }}"><i class="livicon" data-loop="true" data-name="home" data-size="14"></i>Dashboard</a></li>
<li ><a href="{{ URL::to('admin/articles') }}">Article List</a></li>
	<li class="active">Add Article</li>
</ol>
</section>

<!--section ends-->
<section class="content paddingleft_right15">
<!--main content-->
<div class="row">
	<div class="panel panel-primary ">

		<div class="panel-heading">
			<h3 class="panel-title"><i class="livicon" data-c="#fff" data-hc="white" data-loop="true" data-name="gear" data-size="16"></i>Options</h3>
			<span class="pull-right clickable"><i class="glyphicon glyphicon-chevron-up"></i></span>
		</div>
								
		<div class="panel-body">
			<div class="row acc-wizard">
					@if ($errors->any())
						<div class="row">
							<div class="col-md-9 col-lg-offset-3 col-md-offset-3 pd-r lert alert-danger">
								<strong>Whoops!</strong> There were some problems with your input.<br>
								<ul>
									@foreach ($errors->all() as $error)
										<li>{{ $error }}</li>
									@endforeach
								</ul>
							</div>
						</div>
					@endif
					<div class="col-md-2">
						<ol class="acc-wizard-sidebar">
							@isset($article)
								<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#update_article_form">Article Form</a></li>	
							@else
								<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#add_article_form">Article Form</a></li>	
							@endisset
							<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#abstract_detail_form">Abstract Detail</a></li>
							
							<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#upoload_file">Upload File</a></li>
							
							<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#author_form">Authors</a></li>
							
							<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#references">References</a></li>
							
							<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#funder_form">Funder Detail</a></li>
							
							<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#meta">Meta Tags</a></li>
							<li class="acc-wizard-todo "><a data-parent="#accordion-demo" data-toggle="collapse" href="#multi_lang">Multi Language</a></li>
						</ol>
					</div>
					<div class="col-md-10 pd-r">
						<div class="panel-group" id="accordion-demo" ng-app="MAMP.Subapp.Admin">
						
							@isset($article)
							<!-- Article Form Start-->
								@include('admin.article.includes.update_article_form')
							<!-- Article Form End-->

							<!-- Article Detail Form Start-->
								@include('admin.article.includes.abstract_detail_form')
								
							<!-- Article Form End-->

							<!-- Upload File Start-->
								@include('admin.article.includes.upload_files')
							<!-- Upload File End-->
							
							<!-- Author Form Start-->
								@include('admin.article.includes.author_form')
							<!-- Author Form End-->

							<!-- References Form Start-->
								@include('admin.article.includes.references_form')
							<!-- References Form End-->

							<!-- Funder Form Start-->
								@include('admin.article.includes.funder_form')
							<!-- References Form End-->
							
							<!-- Meta Tags Start-->
								@include('admin.article.includes.meta_tag')
							<!-- Meta Tags End-->
							
							<!-- Multiple Language Start-->
								@include('admin.article.includes.multiple.multiple_language')
							<!-- Multiple Language End-->

							@else
							<!-- Article Form Start-->
								@include('admin.article.includes.add_article_form')
							<!-- Article Form End-->	
							@endisset
							
							<!-- Article Form Start-->
								@include('admin.author.edit_author_affiliation')
							<!-- Article Form End-->	
								@include('admin.author.multiple.edit_multi_lang_author_affiliation')


						</div>
					</div>
			</div>
		</div>
	</div>
</div>
<!--main content ends-->
</section>
            <!-- content -->
            @stop


{{-- page level scripts --}}

<script type="text/javascript" src="{{ asset('js/jquery.min.js') }}"></script>
<script src="{{ asset('assets/vendors/bootstrap-tagsinput/js/bootstrap-tagsinput.js') }}"  type="text/javascript"></script>
<script type="text/javascript" src="{!! asset('js/angular.js') !!}"></script>
<script>

<?php if(old('is_epub')!= 0)
{ ?>
$(document).ready(function() {
	$("#issue_id").prop("disabled", true);
});
<?php } ?>

function onchange_isEPUB(){
    
    var ocboEPUB = document.getElementById("is_epub");
    var otxtVol = document.getElementById("volume_id");
    var otxtIssue = document.getElementById("issue_id");
  
    //if this is epub
    if(ocboEPUB.options[ocboEPUB.selectedIndex].value == "2")
    {               
        //otxtVol.value = 0;
        otxtIssue.value = 0;
        otxtVol.disabled = true;
       otxtIssue.disabled = true;
        
    }
    else if(ocboEPUB.options[ocboEPUB.selectedIndex].value == "3")
    {               
        //otxtVol.value = 0;
        otxtIssue.value = 0;
        otxtVol.disabled = true;
        otxtIssue.disabled = true;
        
    }
    else if(ocboEPUB.options[ocboEPUB.selectedIndex].value == "5")
    {               
        //otxtVol.value = 0;
        otxtIssue.value = 0;
        otxtVol.disabled = true;
        otxtIssue.disabled = true;
        
    }
    else if(ocboEPUB.options[ocboEPUB.selectedIndex].value == "4")
    {               
        //otxtVol.value = 0;
        otxtIssue.value = 0;
        //otxtVol.disabled = true;
        otxtIssue.disabled = true;
        
    }
    else if(ocboEPUB.options[ocboEPUB.selectedIndex].value == "1")
    {               
        //otxtVol.value = 0;
        otxtIssue.value = 0;
        //otxtVol.disabled = true;
        otxtIssue.disabled = true;
        
    }
    else
    {
        otxtVol.disabled = false;
        otxtIssue.disabled = false;
        otxtIssue.required= true;
        
    }   
}

function CountPages(){
	var fp = $('#first_page').val();
	var lp = $('#last_page').val();
	var tp = lp-fp+1;
	$('#page_count').val(tp);
}

$(function () {
		
		$("#journal_id").change(function(){
		
			var link_id = $('#link_id').val();
			var journal_id = $('#journal_id').val();

			  $.ajax({
					type: "GET",
					url: '',
					data: {journal_id: journal_id,ajx_search : true},
					success: function( msg ) 
					{	//-----volume search--------
						var data = msg['volume_search'];
						$('#volume_id').empty();
						$('#issue_id').empty();						
						$('#section_id').empty();						
						//console.log(data);						
							$("#volume_id").append('<option value="">Select Volume</option>');
						$.each(data, function(key,value) 
						{							
							$("#volume_id").append('<option value="'+value['volume_id']+'" >'+value['volume_name']+'</option>');
						});	
						//-----section search--------
						var data2 = msg['section_search'];
						//console.log(data2.length);	
						if (data2.length === 0)	
						{
							$("#section_id").prop("disabled", true);
						}
						else
						{
							$("#section_id").prop("disabled", false);
							$("#section_id").append('<option value="">Select Section</option>');
							$.each(data2, function(key,value) 
							{							
								$("#section_id").append('<option value="'+value['js_id']+'" >'+value['js_title']+'</option>');
							});					
						}				

					}
				});						
		});
		
		$("#volume_id").change(function(){
					
			var volume_id = $('#volume_id').val();

			  $.ajax({
					type: "GET",
					url: '',
					data: {volume_id: volume_id,ajx_search : true},
					success: function( msg ) 
					{
						var data = msg['issue_search'];
						//console.log(data);
						$('#issue_id').empty();						
							$("#issue_id").append('<option value="" >Select Issue</option>');
						$.each(data, function(key,value) 
						{							
							$("#issue_id").append('<option value="'+value['issue_id']+'" >'+value['title']+'</option>');
						});					
					}
				});						
		});
		
		$("#article_no").keyup(function()
		{
			var journal_id = $('#journal_id').val();
			var volume_id = $('#volume_id').val();
			var issue_id = $('#issue_id').val();
			var article_no = $('#article_no').val();
			
			if(journal_id && volume_id)
			{
				
			  $.ajax({
					type: "GET",
					data: 
					{
						journal_id: journal_id,
						volume_id: volume_id, 
						issue_id: issue_id, 
						article_no:article_no,
						ajx_search : true, 
						article_exist:true
					},
					success: function( msg )
					{
						console.log(msg.article);
					   if (msg.article_no == article_no)
						{
							$('#lbl_volume').html('Article '+article_no+' Already Exist');
							$('#lbl_volume').addClass("text-danger");
							$('#lbl_volume').removeClass("text-success");
						}
						else
						{
							$('#lbl_volume').html('Article '+article_no+' Available');
							$('#lbl_volume').removeClass("text-danger");
							$('#lbl_volume').addClass("text-success");
						}
					}
				});
			}
		});

	$("#journal_id").select2({
		theme:"bootstrap",
		placeholder:"",
		width: '100%'
	});
	$("#volume_id").select2({
		theme:"bootstrap",
		placeholder:"",
		width: '100%'
	});
	$("#issue_id").select2({
		theme:"bootstrap",
		placeholder:"",
		width: '100%'
	});
	$("#section_id").select2({
		theme:"bootstrap",
		placeholder:"",
		width: '100%'
	});
});
  function edit_multilanguage(data) {
		$("#article_title").val(data.title);
		$("#abstract").val(data.abstract);
		$("#language").val(data.language_id);
		
		// keyword_input_field
		tagsinputfield = '<input name="multi_keywords" id="multi_keywords" type="text" value="'+data.keyword+'"  data-role="tagsinput" class="form-control" />'
		$("#keyword_input_field").html(tagsinputfield);
		// console.log(tagsinputfield);
		$("#submit_lang_btn").val("Update")
		

			
		
	}
</script>
@section('footer_scripts')
	 @include('admin.layouts.js')
@stop