Skip to content

Commit

Permalink
moved profiles page js to script file
Browse files Browse the repository at this point in the history
  • Loading branch information
Simonas Šerlinskas committed Sep 5, 2016
1 parent f962940 commit 018e24f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 71 deletions.
78 changes: 71 additions & 7 deletions Resources/js/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$(document).ready(function () {
var table = $('#settings').DataTable( {
var settingTable = $('#settings').DataTable( {
ajax: {
url: Routing.generate('ongr_settings_search_page'),
dataSrc: 'documents'
Expand Down Expand Up @@ -141,18 +141,18 @@ $(document).ready(function () {
data: data,
success: function (response) {
if (response.error == false) {
table.ajax.reload();
settingTable.ajax.reload();
$('#setting-form-modal').modal('hide')
} else {
$('#setting-form-error').show();
$('#setting-form-error-message').html(response.message);
$('#setting-form-error').show();
}
}
});
});

$('#settings tbody').on( 'click', 'a.edit', function () {
var data = table.row( $(this).parents('tr') ).data();
var data = settingTable.row( $(this).parents('tr') ).data();
reloadProfiles(data.profile);
$('#setting-action-title').text('Setting edit');
$('#force-update').val('1');
Expand Down Expand Up @@ -188,15 +188,14 @@ $(document).ready(function () {

$('#settings tbody').on( 'click', 'a.delete-setting', function (e) {
e.preventDefault();

var name = $(this).data('name');
$.confirm({
text: "Are you sure you want to delete "+name+" setting?",
text: "Are you sure you want to delete setting?",
title: "Confirmation required",
confirm: function(button) {
$.post(Routing.generate('ongr_settings_settings_delete'), {name: name}, function(data) {
if (data.error == false) {
table.ajax.reload();
settingTable.ajax.reload();
}
});
},
Expand All @@ -206,4 +205,69 @@ $(document).ready(function () {
dialogClass: "modal-dialog modal-lg"
});
});



//Profile section
var profileTable = $('#profiles').DataTable( {
ajax: {
url: Routing.generate('ongr_settings_profiles_get_all_detailed'),
dataSrc: 'documents'
},
stateSave: true,
order: [[ 1, "asc" ]],
columns: [
{ data: 'name' },
{ data: 'name' },
{ data: 'settings' },
{}
],
columnDefs: [
{
"targets": 0,
"orderable": false,
"render": function ( data, type, row ) {
var className = 'toggle-profile';
var label = $('<label/>').addClass('btn btn-default').addClass(className)
.addClass(className + '-' + row['name']).attr('data-name', row['name']);
var on = label.clone().html('ON').attr('data-element', className + '-' + row['name']);
var off = label.clone().html('OFF').attr('data-element', className + '-' + row['name']);

if (row['active'] == true) {
on.addClass('btn-primary');
} else {
off.addClass('btn-primary');
}

var cell = $('<div/>').addClass('btn-group btn-group-sm').append(on, off);

return cell.prop('outerHTML');
}
},
{
"targets": 2,
"orderable": false,
},
{
"targets": 3,
"data": null,
"orderable": false,
"defaultContent": '<a class="copy-link btn btn-primary btn-xs" data-toggle="modal" data-target="#setting-edit">Copy link</a>&nbsp;' +
''
} ]
} );

$('#profiles tbody').on( 'click', 'label.toggle-profile', function () {
var self = $(this);
$.post(Routing.generate('ongr_settings_profiles_toggle'), {name:self.data('name')}, function(){
$(".toggle-profile-" + self.data('name')).toggleClass('btn-primary');
})
} );

$('#profiles tbody').on( 'click', 'a.copy-link', function (e) {
e.preventDefault();
$('#profile-list-error-message').html('Enabling profiles by link is not yet implemented.');
$('#profile-list-error').show();
} );

});
2 changes: 1 addition & 1 deletion Resources/public/script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 5 additions & 63 deletions Resources/views/Profiles/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@


{% block body %}
<div id="profile-list-error" class="alert alert-danger alert-dismissible fade in" style="display: none;" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4>You got an error!</h4>
<p id="profile-list-error-message"></p>
</div>
<table id="profiles" class="display table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
Expand All @@ -12,67 +17,4 @@
</tr>
</thead>
</table>
{% endblock %}

{% block javascripts %}
{{ parent() }}
<script type="application/javascript">
$(document).ready(function () {
var table = $('#profiles').DataTable( {
ajax: {
url: './profiles/get_all_detailed',
dataSrc: 'documents'
},
stateSave: true,
order: [[ 1, "asc" ]],
columns: [
{ data: 'name' },
{ data: 'name' },
{ data: 'settings' },
{}
],
columnDefs: [
{
"targets": 0,
"orderable": false,
"render": function ( data, type, row ) {
var className = 'toggle-profile';
var label = $('<label/>').addClass('btn btn-default').addClass(className)
.addClass(className + '-' + row['name']).attr('data-name', row['name']);
var on = label.clone().html('ON').attr('data-element', className + '-' + row['name']);
var off = label.clone().html('OFF').attr('data-element', className + '-' + row['name']);
if (row['active'] == true) {
on.addClass('btn-primary');
} else {
off.addClass('btn-primary');
}
var cell = $('<div/>').addClass('btn-group btn-group-sm').append(on, off);
return cell.prop('outerHTML');
}
},
{
"targets": 2,
"orderable": false,
},
{
"targets": 3,
"data": null,
"orderable": false,
"defaultContent": '<a class="edit btn btn-primary btn-xs" data-toggle="modal" data-target="#setting-edit">Copy link</a>&nbsp;' +
''
} ]
} );
$('#profiles tbody').on( 'click', 'label.toggle-profile', function () {
var self = $(this);
$.post('./profiles/toggle', {name:self.data('name')}, function(){
$(".toggle-profile-" + self.data('name')).toggleClass('btn-primary');
})
} );
})
</script>
{% endblock %}
5 changes: 5 additions & 0 deletions Resources/views/Settings/list.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% extends 'ONGRSettingsBundle::base.html.twig' %}
{% block body %}
<div id="setting-list-error" class="alert alert-danger alert-dismissible fade in" style="display: none;" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4>You got an error!</h4>
<p id="setting-list-error-message"></p>
</div>
<table id="settings" class="display table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
Expand Down

0 comments on commit 018e24f

Please sign in to comment.