Skip to content

Instantly share code, notes, and snippets.

@shabaz-ejaz
Created February 16, 2018 22:20
Show Gist options
  • Save shabaz-ejaz/96be7b4b20ba9146436f1f9f1d274211 to your computer and use it in GitHub Desktop.
Save shabaz-ejaz/96be7b4b20ba9146436f1f9f1d274211 to your computer and use it in GitHub Desktop.
@extends('quarx::layouts.dashboard', ['pageTitle' => '_camelUpper_casePlural_ » Edit'])
@section('content')
<div class="row">
<div class="col-md-12">
<div class="pull-right raw-margin-top-24 raw-margin-left-24">
{!! Form::open(['route' => 'assessments.search']) !!}
<input class="form-control form-inline pull-right" name="search" placeholder="Search">
{!! Form::close() !!}
</div>
<h1 class="pull-left">Assessments: Edit</h1>
<a class="btn btn-primary pull-right raw-margin-top-24 raw-margin-right-8"
href="{!! route('assessments.create') !!}">Add New</a>
</div>
</div>
<div class="row">
<div class="col-md-12">
{!! Form::model($assessment, ['route' => ['assessments.update', $assessment->id], 'method' => 'patch']) !!}
{!! FormMaker::fromObject($assessment,
[
'name',
'description' => [
'class' => 'redactor',
'type' => 'textarea'
]
] )
!!}
{!! Form::submit('Update', ['class' => 'btn btn-primary pull-right']) !!}
{!! Form::close() !!}
</div>
</div>
<br/>
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>
Assessment Sections!
<small>Add your sections here</small>
</h1>
<a id="add-new-section-modal-btn pull-right" href="#add-new-section-modal" role="button"
class="btn btn-default" data-toggle="modal">Add new section</a>
</div>
<div class="modal fade" id="add-new-section-modal" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
Add new assessment section
</h4>
</div>
<div class="modal-body">
{!! Form::open(['route' => array('sections.store', 'model_slug' => 'assessments', 'model_id' => $assessment->id)]) !!}
@form_maker_table("assessment_sections", ['name',
'description' => [
'class' => 'redactor',
'type' => 'textarea']
])
<div style="text-align: right;">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
{{-- <table class="table table-striped table-hover">
<tbody class="sortable" data-entityname="sections">
@foreach ($assessment->sections as $section)
<tr data-itemId="{{ $section->id }}">
<td class="sortable-handle"><span class="glyphicon glyphicon-sort"></span></td>
<td class="id-column">{{ $section->id }}</td>
<td>{{ $section->name }}</td>
</tr>
@endforeach
</tbody>
</table>--}}
<div class="panel-group sortable" id="accordion" role="tablist" aria-multiselectable="true"
data-entityname="sections">
@foreach ($assessment->sections->where('parent', NULL) as $section)
{{-- {{ dd($section->questionGroups) }}--}}
<div class="panel panel-info parent-panel" data-itemId="{{ $section->id }}">
<div class="panel-heading sortable-handle" role="tab" id="heading{{ $section->id }}">
<a role="button" data-toggle="collapse" data-parent="#accordion"
href="#collapse{{ $section->id }}" aria-expanded="true"
aria-controls="collapse{{ $section->id }}">
<h4 class="panel-title parent-panel-title">
<span class="glyphicon glyphicon-sort"></span>
{{ $section->name }}
</h4>
</a>
</div>
<div id="collapse{{ $section->id }}" class="panel-collapse collapse" role="tabpanel"
aria-labelledby="heading{{ $section->id }}">
<div class="panel-body">
{!! Form::open(['method' => 'DELETE', 'route' => ['section.destroy', $section->id, $assessment->id, 'assessments']]) !!}
{!! csrf_field() !!}
{!! method_field('DELETE') !!}
<button class="btn btn-danger btn-xs pull-right" type="submit"
onclick="return confirm('Are you sure you want to delete this section?')"><i
class="fa fa-trash"></i> Delete
</button>
{!! Form::close() !!}
<a class="btn btn-warning btn-xs pull-right raw-margin-right-16" data-toggle="modal" role="button" href="#edit-section-modal-{{$section->id}}"><span class="fa fa-edit"></span> Edit</a>
<div class="modal fade" id="edit-section-modal-{{$section->id}}" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
Edit {{ $section->name }}
</h4>
</div>
<div class="modal-body">
{!! Form::model($section, ['route' => ['sections.update', $section->id, 'model_slug' => 'assessments', 'model_id' => $assessment->id,], 'method' => 'patch']) !!}
@form_maker_object($section, ['name',
'description' => [
'class' => 'redactor',
'type' => 'textarea']
])
<div style="text-align: right;">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<a id="add-new-sub-section-modal-btn-{{$section->id}} pull-right"
href="#add-new-subsection-modal-{{$section->id}}" role="button"
class="btn btn-default" data-toggle="modal">Add new subsection</a>
<div class="modal fade" id="add-new-subsection-modal-{{$section->id}}" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
Add new assessment sub section to {{ $section->name }}
</h4>
</div>
<div class="modal-body">
{!! Form::open(['route' => array('sections.store', 'model_slug' => 'assessments', 'model_id' => $assessment->id, 'parent' => $section->id)]) !!}
@form_maker_table("assessment_sections", ['name',
'description' => [
'class' => 'redactor',
'type' => 'textarea']
])
<div style="text-align: right;">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<br/>
<br/>
<div class="panel-group sortable" id="accordionSub" role="tablist"
aria-multiselectable="true" data-entityname="sections">
@foreach ($assessment->sections->where('parent', $section->id) as $subsection)
<div class="panel panel-default" data-itemId="{{ $subsection->id }}">
<div class="panel-heading sortable-handle" role="tab"
id="headingSub{{ $subsection->id }}">
<a role="button" data-toggle="collapse" data-parent="#accordionSub"
href="#collapseSub{{ $subsection->id }}" aria-expanded="true"
aria-controls="collapseSub{{ $subsection->id }}">
<h4 class="panel-title">
<span class="glyphicon glyphicon-sort"></span>
{{ $subsection->name }}
</h4>
</a>
</div>
<div id="collapseSub{{ $subsection->id }}" class="panel-collapse collapse"
role="tabpanel" aria-labelledby="headingSub{{ $subsection->id }}">
<div class="panel-body">
{!! Form::open(['method' => 'DELETE', 'route' => ['section.destroy', $subsection->id, $assessment->id, 'assessments']]) !!}
{!! csrf_field() !!}
{!! method_field('DELETE') !!}
<button class="btn btn-danger btn-xs pull-right" type="submit"
onclick="return confirm('Are you sure you want to delete this subsection?')">
<i class="fa fa-trash"></i> Delete
</button>
{!! Form::close() !!}
<a class="btn btn-warning btn-xs pull-right raw-margin-right-16" data-toggle="modal" role="button" href="#edit-subsection-modal-{{$subsection->id}}"><span class="fa fa-edit"></span> Edit</a>
<div class="modal fade" id="edit-subsection-modal-{{$subsection->id}}" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
Edit {{ $subsection->name }}
</h4>
</div>
<div class="modal-body">
{!! Form::model($subsection, ['route' => ['sections.update', $subsection->id, 'model_slug' => 'assessments', 'model_id' => $assessment->id,], 'method' => 'patch']) !!}
@form_maker_object($subsection, ['name',
'description' => [
'class' => 'redactor',
'type' => 'textarea']
])
<div style="text-align: right;">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<a id="add-new-question-modal-btn-{{$subsection->id}}"
href="#add-new-question-modal-{{$subsection->id}}" role="button" class="btn btn-default"
data-toggle="modal">Add new question</a>
{{--<div class="modal fade" id="add-new-question-modal-{{$subsection->id}}" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
Add new question
</h4>
</div>
<div class="modal-body">
{!! Form::open(['route' => array('question_groups.store', 'section_id' => $subsection->id, 'created_from_assessment' => true, 'assessment_id' => $assessment->id)]) !!}
@form_maker_table("assessment_sections",
[
'name' => [
'alt_name' => 'Question Title',
'name' => 'question_name',
'custom' => 'required'
],
'description' => [
'class' => 'redactor',
'name' => 'question_description',
'type' => 'textarea'
],
'help' => [
'type' => 'textarea',
'alt_name' => 'Help text'
]
]
)
<div class="form-group type-form">
<label class="control-label" for="type-{{ $subsection->id }}">Question Type</label>
<select id="type-{{ $subsection->id }}" class="form-control question-type-dropdown"
name="question_type">
<option disabled selected value></option>
<option value="0">Radio</option>
<option value="1">Checkbox</option>
<option value="2">Number</option>
</select>
</div>
<div class="row type-form-results" style="display: none;">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">Type: <span class="question-type"></span><a class="btn btn-default btn-xs pull-right raw-margin-right-16 clear_inputs"><span class="fa fa-ban"></span> Clear</a></div>
<div class="panel-body">
<div class="row">
<div class="col-md-12 question-inputs-container">
<a class="btn btn-warning btn-xs raw-margin-right-16 add_row_title_button"><span class="fa fa-plus"></span> Add new row title</a>
<div class="row">
<div class="col-md-6">
Row title:
<div class="row_titles">
<div class="form-group">
<input class="form-control row_title_input" type="text" name="row_titles[]" value="Statement" placeholder="Question">
<a class="label label-danger remove_row_title"><i class="fa fa-trash"></i> Remove</a>
</div>
</div>
</div>
<div class="col-md-6">
Possible options:
<div class="well">
<a class="btn btn-warning btn-xs raw-margin-right-16 add_option_button"role="button"><span class="fa fa-plus"></span> Add new option</a>
<div class="options">
<div class="form-group ">
<input class="form-control radio-option-input" type="text" name="row_options[]" value="Option" placeholder="Question">
<a class="label label-danger remove_option"><i class="fa fa-trash"></i> Remove</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br />
<div style="text-align: right;">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>--}}
<br /><br />
@if(!$subsection->questionGroups->isEmpty())
<table class="table table-striped subsection-questions-table">
<thead>
<tr>
<th>Question</th>
<th>Type</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($subsection->questionGroups as $questionGroup)
<tr>
<td>{{ $questionGroup->name }}</td>
<td>{{ config('constants.question_types')[$questionGroup->type] }}</td>
<td>
<a class="btn btn-warning btn-xs raw-margin-right-16 edit-question-btn" data-toggle="modal" role="button" href="#edit-question-modal-{{$questionGroup->id}}"><span class="fa fa-edit"></span> Edit</a>
{!! Form::open(['method' => 'DELETE', 'route' => ['section.destroy', $subsection->id, $assessment->id, 'assessments']]) !!}
{!! csrf_field() !!}
{!! method_field('DELETE') !!}
<button class="btn btn-danger btn-xs" type="submit"
onclick="return confirm('Are you sure you want to delete this subsection?')">
<i class="fa fa-trash"></i> Delete
</button>
{!! Form::close() !!}
</td>
</tr>
<div class="modal fade" id="edit-question-modal-{{$questionGroup->id}}" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
Edit question: {{ $questionGroup->name }}
</h4>
</div>
<div class="modal-body">
{!! Form::model($questionGroup, ['route' => ['question_groups.update', $questionGroup->id, 'model_slug' => 'assessments', 'model_id' => $assessment->id], 'method' => 'patch']) !!}
{!! FormMaker::fromObject($questionGroup,
[
'description' => [
'class' => 'redactor',
'type' => 'textarea'
],
'help' => [
'type' => 'textarea',
'alt_name' => 'Help text'
],
'type' => [
'type' => 'select',
'class' => 'question-type-edit question-type-dropdown',
'alt_name' => 'Type',
'options' => array_flip(config('constants.question_types'))
],
] ) !!}
<div class="row type-form-results" style="display: none;">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">Type: <span class="question-type"></span><a class="btn btn-default btn-xs pull-right raw-margin-right-16 clear_inputs"><span class="fa fa-ban"></span> Clear</a></div>
<div class="panel-body">
<div class="row">
<div class="col-md-12 question-inputs-container">
<a class="btn btn-warning btn-xs raw-margin-right-16 add_row_title_button"><span class="fa fa-plus"></span> Add new row title</a>
<div class="row">
<div class="col-md-6">
Row titles:
<div class="row_titles">
@foreach($questionGroup->questions->sortBy('id') as $rowTitle)
<div class="form-group" style="clear: both;">
<input class="form-control row_title_input" type="text" name="row_titles_updated[{{$rowTitle->id }}]" value="{{ $rowTitle->name }}" placeholder="Question">
<a class="label label-danger remove_row_title"><i class="fa fa-trash"></i> Remove</a>
</div>
@endforeach
</div>
</div>
<div class="col-md-6">
Possible options:
<div class="well">
<a class="btn btn-warning btn-xs raw-margin-right-16 add_option_button"role="button"><span class="fa fa-plus"></span> Add new option</a>
<div class="options">
@foreach($questionGroup->questionMappings->sortBy('id') as $option)
<div class="form-group" style="clear: both;">
<input class="form-control radio-option-input" type="text" name="row_options[]" value="{{ $option->name }}" placeholder="Question">
<a class="label label-danger remove_option"><i class="fa fa-trash"></i> Remove</a>
</div>
@endforeach
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br />
<div style="text-align: right;">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endforeach
</tbody>
</table>
@endif
<br /> <br />
{!! $subsection->description !!}
</div>
</div>
</div>
@endforeach
</div>
{!! $section->description !!}
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
@stop
@section('javascript')
<script type="text/javascript">
/**
*
* @param type string 'insertAfter' or 'insertBefore'
* @param entityName
* @param id
* @param positionId
*/
var changePosition = function (requestData) {
$.ajax({
'url': '/admin/sections/sort',
'type': 'POST',
'data': requestData,
'success': function (data) {
if (data.success) {
console.log('Saved!');
quarxNotify('Saved', 'alert-success')
} else {
quarxNotify(data.errors[0], 'alert-danger');
console.error(data.errors);
}
},
'error': function () {
quarxNotify('Something went wrong!', 'alert-danger');
console.error('Something wrong!');
}
});
};
$(document).ready(function () {
var $sortableTable = $('.sortable');
if ($sortableTable.length > 0) {
$sortableTable.sortable({
forcePlaceholderSize: true,
placeholder: "testclass",
handle: '.sortable-handle',
axis: 'y',
update: function (a, b) {
var entityName = $(this).data('entityname');
var $sorted = b.item;
var $previous = $sorted.prev();
var $next = $sorted.next();
if ($previous.length > 0) {
changePosition({
parentId: $sorted.data('parentid'),
type: 'moveAfter',
entityName: entityName,
id: $sorted.data('itemid'),
positionEntityId: $previous.data('itemid'),
"_token": "{{ csrf_token() }}"
});
} else if ($next.length > 0) {
changePosition({
parentId: $sorted.data('parentid'),
type: 'moveBefore',
entityName: entityName,
id: $sorted.data('itemid'),
positionEntityId: $next.data('itemid'),
"_token": "{{ csrf_token() }}"
});
} else {
quarxNotify('Something went wrong!', 'alert-danger');
console.error('Something wrong!');
}
},
cursor: "move"
});
}
});
</script>
@endsection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment