This repository has been archived by the owner on Jun 9, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding repo and global admin pages #25
- Loading branch information
1 parent
1fc12a7
commit 8904d03
Showing
10 changed files
with
399 additions
and
594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +0,0 @@ | ||
.config-area { | ||
border: 1px; | ||
border-color: black; | ||
border-style: dotted; | ||
width: 400px; | ||
padding: 5px 15px; | ||
} | ||
|
||
fieldset { | ||
border: 1px; | ||
padding: 5px 15px; | ||
} | ||
|
||
legend { | ||
font-weight: bold; | ||
font-size: 20px; | ||
} | ||
|
||
.left { | ||
float: left; | ||
} | ||
|
||
.right { | ||
float: right; | ||
} | ||
|
||
.error { | ||
font-weight: bold; | ||
color: red; | ||
} | ||
|
||
input[type="text"], | ||
input[type="password"] { | ||
width: 100%; | ||
} | ||
|
||
.prnfb > form { | ||
margin: 10px 0 0 0; | ||
} | ||
|
||
.prnfb-template { | ||
display: none; | ||
} | ||
|
||
.visibleif { | ||
display: none; | ||
} | ||
|
||
th { | ||
text-align: left; | ||
} | ||
|
||
td > input[type="text"] { | ||
width: 90%; | ||
margin: 0 10% 0 0; | ||
float: left | ||
} | ||
|
||
.expandable .content { | ||
display: none; | ||
} | ||
|
||
.expandable.expanded .content { | ||
display: inherit; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,160 +1,17 @@ | ||
(function($) { | ||
'use strict'; | ||
var config_resource = AJS.contextPath() + "/rest/prnfb-admin/1.0/"; | ||
$(document).ready(function() { | ||
function getEmpties($headers) { | ||
var empties = []; | ||
$('.header', $headers).each(function(iheader, $header) { | ||
var allValue = ""; | ||
$('input[type="text"]', $header).each(function(iinput, $input) { | ||
allValue += $input.value.trim(); | ||
}); | ||
if (allValue === "") { | ||
empties.push($header); | ||
} | ||
}); | ||
return empties; | ||
} | ||
|
||
function adjustHeaders($headers) { | ||
var empties = getEmpties($headers); | ||
if (empties.length === 0) { | ||
$headers.append($(".prnfb-template .header")[0].outerHTML); | ||
} | ||
|
||
if (empties.length > 1) { | ||
empties[1].remove(); | ||
} | ||
} | ||
|
||
function setEvents() { | ||
$('input[name="delete"]').click(function(e) { | ||
var $form = $(this).closest('form'); | ||
var formIdentifier = $('input[name="FORM_IDENTIFIER"]', $form).val(); | ||
$.ajax({ | ||
url: config_resource + formIdentifier, | ||
dataType: "json", | ||
type: "DELETE", | ||
error: function(xhr, data, error) { | ||
console.log(xhr); | ||
console.log(data); | ||
console.log(error); | ||
}, | ||
success: function(data, text, xhr) { | ||
$form.remove(); | ||
} | ||
}); | ||
}); | ||
|
||
$('.expandable').each(function(index, el) { | ||
var $element = $(el); | ||
$element.find('.toggle').click(function() { | ||
$element.toggleClass('expanded'); | ||
}); | ||
}); | ||
//If there are only a few triggers configured, they can be expanded by default without confusion. | ||
if ($('.expandable').length < 4) { | ||
$('.expandable').addClass('expanded'); | ||
} | ||
|
||
$('.headers').keyup(function(e) { | ||
var $headers = $(this); | ||
adjustHeaders($headers); | ||
}); | ||
|
||
$('input[name="save"]').click(function(e) { | ||
var $form = $(this).closest('form'); | ||
$(".post", $form).html("Saving..."); | ||
$.ajax({ | ||
url: config_resource, | ||
dataType: "json", | ||
type: "POST", | ||
contentType: "application/json", | ||
data: JSON.stringify($form.serializeArray(), null, 2), | ||
processData: false, | ||
error: function(xhr, data, error) { | ||
$(".error." + xhr.responseJSON.field, $form).html(xhr.responseJSON.error); | ||
if (xhr.responseJSON.field) { | ||
$(".post", $form).html("There were errors, form not saved!"); | ||
} else { | ||
$(".post", $form).html(xhr.responseText); | ||
} | ||
}, | ||
success: function(data, text, xhr) { | ||
getAll(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function addNewForm(formType) { | ||
var $template = $(".prnfb-template-" + formType).clone(); | ||
$('input[name="delete"]', $template).remove(); | ||
$('input[name=method][value=GET]', $template).attr('checked', 'checked'); | ||
$('.expandable', $template).addClass('expanded'); | ||
$(".prnfb-" + formType).append($template.html()); | ||
} | ||
define('plugin/prnfb/admin', [ | ||
'jquery', | ||
'aui', | ||
'plugin/prnfb/utils' | ||
], function($, AJS, common) { | ||
|
||
function getAll() { | ||
$.ajax({ | ||
url: config_resource, | ||
dataType: "json" | ||
}).done(function(configs) { | ||
$(".prnfb-TRIGGER_CONFIG_FORM").html(""); | ||
$(".prnfb-BUTTON_CONFIG_FORM").html(""); | ||
$(".prnfb-GLOBAL_SETTINGS").html(""); | ||
$.each(configs, function(index, config) { | ||
var formType = 'TRIGGER_CONFIG_FORM'; | ||
$.each(config, function(fieldIndex, field_map) { | ||
if (field_map.name === 'FORM_TYPE') { | ||
formType = field_map.value; | ||
} | ||
}); | ||
|
||
var $template = $(".prnfb-template-" + formType).clone(); | ||
|
||
$.each(config, function(fieldIndex, field_map) { | ||
var safe_value = field_map.value.replace(/[^a-zA-Z\_]/g, ''); | ||
$('.variable[data-variable="' + field_map.name + '"]', $template).html(field_map.value); | ||
$('input[type="text"][name="' + field_map.name + '"]', $template).attr('value', field_map.value); | ||
$('input[type="password"][name="' + field_map.name + '"]', $template).attr('value', field_map.value); | ||
$('textarea[name="' + field_map.name + '"]', $template).text(field_map.value); | ||
$('input[type="hidden"][name="' + field_map.name + '"]', $template).attr('value', field_map.value); | ||
$('input[type="checkbox"][name="' + field_map.name + '"][value="' + safe_value + '"]', $template).attr('checked', 'checked'); | ||
$('input[type="radio"][name="' + field_map.name + '"][value="' + safe_value + '"]', $template).attr('checked', 'checked'); | ||
$('.visibleif.' + field_map.name + '_' + safe_value, $template).show(); | ||
}); | ||
|
||
var header_names = []; | ||
var header_values = []; | ||
$.each(config, function(fieldIndex, field_map) { | ||
if (field_map.name === 'header_name') { | ||
header_names.push(field_map.value); | ||
} else if (field_map.name === 'header_value') { | ||
header_values.push(field_map.value); | ||
} | ||
}); | ||
for (var i = 0; i < header_names.length; i++) { | ||
$('input[type="text"][name="header_name"]', $template).last().attr('value', header_names[i]); | ||
$('input[type="text"][name="header_value"]', $template).last().attr('value', header_values[i]); | ||
adjustHeaders($(".headers", $template)); | ||
} | ||
|
||
if (!$('input[name=method]:checked', $template).val()) { | ||
$('input[name=method][value=GET]', $template).attr('checked', 'checked'); | ||
} | ||
|
||
$(".prnfb-" + formType).append($template.html()); | ||
}); | ||
addNewForm('TRIGGER_CONFIG_FORM'); | ||
addNewForm('BUTTON_CONFIG_FORM'); | ||
if ($('[name="FORM_TYPE"][value="GLOBAL_SETTINGS"]').length < 2) { | ||
addNewForm('GLOBAL_SETTINGS'); | ||
} | ||
setEvents(); | ||
}); | ||
} | ||
|
||
getAll(); | ||
$(document).ready(function() { | ||
var globalRepoAdminUrl = AJS.contextPath() + "/rest/prnfb-admin/1.0"; | ||
$.getJSON(globalRepoAdminUrl, function(data) { | ||
common.setupRepoSettingsForm(data); | ||
}); | ||
}); | ||
})(AJS.$ || jQuery); | ||
}); | ||
|
||
AJS.$(document).ready(function() { | ||
require('plugin/prnfb/admin'); | ||
}); |
Oops, something went wrong.