Skip to content

Commit

Permalink
WIP on AJAX add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Crampton committed Mar 3, 2015
1 parent eb25927 commit 28d2052
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 10 deletions.
15 changes: 15 additions & 0 deletions app/controllers/AjaxController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class AjaxController extends BaseController
{
public function __construct()
{
$this->beforeFilter('staff');
}

public function ajax_add_comment()
{
return json_encode(['value' => 'test']);
}

}
4 changes: 3 additions & 1 deletion app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
Route::resource('tickets', 'TicketsController');

// Admin Routing
// Route::resource('/users/roles', 'UserRolesController');
Route::resource('users', 'UsersController');
Route::resource('sessions', 'SessionsController');

// Special Routes
Route::post('ajax/ajax_add_comment', 'AjaxController@ajax_add_comment');
19 changes: 19 additions & 0 deletions app/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@
@yield('content')
</div><!-- /.container -->

<!-- Comment Modal -->
<div class="modal fade" id="comment_modal" tabindex="-1" role="dialog" aria-labelledby="comment_modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Add comment to this ticket</h4>
</div>
<div class="modal-body">
{{ Form::textarea('comment_add', null, ['class' => 'form-control']) }}
</div>
<div class="modal-footer">
{{ Form::button('Cancel', ['class' => 'btn btn-default', 'data-dismiss' => 'modal']) }}
{{ Form::button('Add Comment', ['class' => 'btn btn-primary', 'id' => 'submit_comment']) }}
</div>
</div>
</div>
</div>


<!-- Bootstrap core JavaScript
================================================== -->
Expand Down
16 changes: 7 additions & 9 deletions app/views/tickets/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@

<div class="col-md-4">
<div id="content_doc_container" class="form-group has-feedback">
{{ Form::label('content_doc', 'Upload and insert document (max 8mb): ', array('class' => 'control-label')) }}
{{ Form::file('content_doc', array('class' => 'form-control')) }}
{{ Form::label('content_doc', 'Upload and insert document (max 8mb): ', ['class' => 'control-label']) }}
{{ Form::file('content_doc', ['class' => 'form-control']) }}
<span id="content_doc_glyph" class="glyphicon glyphicon-ok form-control-feedback hide" aria-hidden="true"></span>
<span id="ajax-error-doc"></span>
</div>
<div id="content_image_container" class="form-group has-feedback">
{{ Form::label('content_image', 'Upload and insert image: (max 8mb)', array('class' => 'control-label')) }}
{{ Form::file('content_image', array('class' => 'form-control')) }}
{{ Form::label('content_image', 'Upload and insert image: (max 8mb)', ['class' => 'control-label']) }}
{{ Form::file('content_image', ['class' => 'form-control']) }}
<span id="content_image_glyph" class="glyphicon glyphicon-ok form-control-feedback hide" aria-hidden="true"></span>
<span id="ajax-error-content"></span>
</div>
Expand All @@ -59,12 +59,12 @@
<div class="col-md-6">
<div class="form-group">
{{ Form::label('description', 'Description: ') }} {{ $errors->first('description', '<span class="label label-danger">:message</span>') }}
{{ Form::textarea('description', $ticket->master_description, array('id' => 'content_editor', 'class' => 'form-control')) }}
{{ Form::textarea('description', $ticket->master_description, ['id' => 'content_editor', 'class' => 'form-control']) }}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{{ Form::label('comments', 'Comments: ') }}
{{ Form::label('comments', 'Comments: ') }} {{ Form::button('Add Comment', ['class' => 'btn btn-xs btn-primary pull-right', 'data-toggle' => 'modal', 'data-target' => '#comment_modal']) }}
<ul>
@foreach($comments as $comment)
<li>{{ $comment->updated_at . ': ' . $comment->comments_comment }}</li>
Expand All @@ -74,7 +74,7 @@
</div>
<div class="col-md-12">
<div class="form-group">
{{ Form::submit('Update', array('class' => 'btn btn-success')) }}
{{ Form::submit('Update', ['class' => 'btn btn-success']) }}
</div>
</div>
{{ Form::close() }}
Expand All @@ -83,6 +83,4 @@

</div>

<hr />

@stop
31 changes: 31 additions & 0 deletions public/js/utilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// General Scripts
$(document).ready(function()
{
$('#submit_comment').on('click', function() {
add_comment();
});

});

// AJAX Functions
function add_comment(event)
{
$.ajax({
url: '/ajax/ajax_add_comment',
cache: false,
type: 'POST',
dataType: 'json',

success: function(response)
{
console.log(response);
},
error: function(jqXHR, textStatus, errorThrown)
{
// Handle errors here
console.log('ERRORS: ' + errorThrown);
}

});

}

0 comments on commit 28d2052

Please sign in to comment.