mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 13:32:15 +00:00
* Add basic markdown support site wide
* Improved MD support.
Add some styling for images in MD
Add support for the bastardisation of the MD html for RML.
* Add processing for <ul> in RML
* Add OL processing to RML
* Fix a bug with squares appearing around the last page number
* Remove rml formatting in event_detail
* Improve handling of code blocks in RML
* Add MD to rigboard
Reduce MD title sizes as they were offensively large
* Add parsing of markdown when editing event items
* Improved list handling in RML
* Add tests for markdown support.
Focuses mainly on RML as that's where it will break
* Add indications of where MD support is enabled as per comment by @samozzy in #178.
Isn't quite a full description, but for the most part this should be enough for the people who know how to use it see where they can use it.
* Add failing test for markdown processing none
* Fix for failing test in e0d56e
* Add failing test for using single line breaks as per comment on #214
* Enable line break extension for single breaks in paragraphs by new lines.
Pass tests in ef3de607c3
* Enable GH flavour linebreaks in JS rendered markdown
* Made RML bullets pretty :)
* Added WYSIWYG editor. Works for notes & description, fails miserably for items :(
* Fixed for event items. Will probably fail tests because selenium can't type in simpleMDE :(
* FIX: Re-enable markdown on paperwork
Strikethrough is broken in all sorts of places for whatever reason
* FEAT: Markdown support on asset comments
* FIX: Prevent js injection through markdown fields
* Initial fixes
* Basic dark theme for simplemde
* Swap to locally delivered SimpleMDE
* Region for selenium testing of SimpleMDE
Bleh, Javascript all around
* Tests passing!
Fixed not using region for item modal, and overflow error on paperwork with really long description. Looks junk but I'm not really bothered
* Pep8 fixes
* Fallback for null HCapatcha sitekey
I.e. when we're on a branch
* Fix item description print being broken
* Actually fix sitekey problem
* Fixes for using markdown in asset comments
* Properly initialise markdown on asset comments
Co-authored-by: David Taylor <david@taylorhq.com>
Co-authored-by: FreneticScribbler <aj@aronajones.com>
140 lines
4.2 KiB
JavaScript
140 lines
4.2 KiB
JavaScript
marked.setOptions({
|
|
breaks: true,
|
|
})
|
|
|
|
function setupItemTable(items_json) {
|
|
objectitems = JSON.parse(items_json)
|
|
$.each(objectitems, function (key, val) {
|
|
objectitems[key] = JSON.parse(val);
|
|
})
|
|
newitem = -1;
|
|
}
|
|
|
|
function nl2br(str, is_xhtml) {
|
|
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
|
|
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
|
|
}
|
|
|
|
function escapeHtml(str) {
|
|
return $('<div/>').text(str).html();
|
|
}
|
|
|
|
function updatePrices() {
|
|
// individual rows
|
|
var sum = 0;
|
|
for (var pk in objectitems) {
|
|
var fields = objectitems[pk].fields;
|
|
var sub = fields.cost * fields.quantity;
|
|
$('#item-' + pk + ' .sub-total').html(parseFloat(sub).toFixed(2)).data('subtotal', sub);
|
|
|
|
sum += Number(sub);
|
|
}
|
|
|
|
$('#sumtotal').text(parseFloat(sum).toFixed(2));
|
|
var vat = sum * Number($('#vat-rate').data('rate'));
|
|
$('#vat').text(parseFloat(vat).toFixed(2));
|
|
$('#total').text(parseFloat(sum + vat).toFixed(2));
|
|
}
|
|
|
|
function setupMDE(selector) {
|
|
editor = new SimpleMDE({
|
|
element: $(selector)[0],
|
|
forceSync: true,
|
|
toolbar: ["bold", "italic", "strikethrough", "|", "unordered-list", "ordered-list", "|", "link", "|", "preview", "guide"],
|
|
status: true,
|
|
});
|
|
$(selector).data('mde_editor',editor);
|
|
}
|
|
|
|
$('#item-table').on('click', '.item-delete', function () {
|
|
delete objectitems[$(this).data('pk')]
|
|
$('#item-' + $(this).data('pk')).remove();
|
|
updatePrices();
|
|
});
|
|
|
|
$('#item-table').on('click', '.item-add', function () {
|
|
$('#item-form').data('pk', newitem);
|
|
|
|
// Set the form values
|
|
$('#item_name').val('');
|
|
$('#item_description').val('');
|
|
$('#item_quantity').val('');
|
|
$('#item_cost').val('');
|
|
|
|
$($(this).data('target')).modal('show');
|
|
});
|
|
|
|
$('#item-table').on('click', '.item-edit', function () {
|
|
// set the pk as we will need this later
|
|
var pk = $(this).data('pk');
|
|
$('#item-form').data('pk', pk);
|
|
|
|
// Set the form values
|
|
var fields = objectitems[pk].fields;
|
|
$('#item_name').val(fields.name);
|
|
$('#item_description').val(fields.description);
|
|
$('#item_quantity').val(fields.quantity);
|
|
$('#item_cost').val(fields.cost);
|
|
|
|
$($(this).data('target')).modal('show');
|
|
});
|
|
|
|
$('body').on('submit', '#item-form', function (e) {
|
|
e.preventDefault();
|
|
var pk = $(this).data('pk');
|
|
$('#itemModal').modal('hide');
|
|
|
|
var fields;
|
|
if (pk == newitem--) {
|
|
// Create the new data structure and add it on.
|
|
fields = new Object();
|
|
fields['name'] = $('#item_name').val()
|
|
fields['description'] = $('#item_description').val();
|
|
fields['cost'] = $('#item_cost').val();
|
|
fields['quantity'] = $('#item_quantity').val();
|
|
|
|
var order = 0;
|
|
for (item in objectitems) {
|
|
order++;
|
|
}
|
|
|
|
fields['order'] = order;
|
|
|
|
objectitems[pk] = new Object();
|
|
objectitems[pk]['fields'] = fields;
|
|
|
|
// Add the new table
|
|
$('#new-item-row').clone().attr('id', 'item-' + pk).data('pk', pk).appendTo('#item-table-body');
|
|
$('#item-'+pk+' .item-delete, #item-'+pk+' .item-edit').data('pk', pk)
|
|
} else {
|
|
// Existing item
|
|
// update data structure
|
|
fields = objectitems[pk].fields;
|
|
fields.name = $('#item_name').val()
|
|
fields.description = $('#item_description').val();
|
|
fields.cost = $('#item_cost').val();
|
|
fields.quantity = $('#item_quantity').val();
|
|
objectitems[pk].fields = fields;
|
|
|
|
}
|
|
// update the table
|
|
$row = $('#item-' + pk);
|
|
$row.find('.name').html(escapeHtml(fields.name));
|
|
$row.find('.description').html(marked(fields.description));
|
|
$row.find('.cost').html(parseFloat(fields.cost).toFixed(2));
|
|
$row.find('.quantity').html(fields.quantity);
|
|
|
|
updatePrices();
|
|
});
|
|
|
|
$('body').on('submit', '.itemised_form', function (e) {
|
|
$('#id_items_json').val(JSON.stringify(objectitems));
|
|
});
|
|
|
|
sortable("#item-table tbody")[0].addEventListener('sortupdate', function (e) {
|
|
var items = e.detail.destination.items;
|
|
for(var i in items) {
|
|
objectitems[items[i].dataset.pk].fields.order = i;
|
|
}
|
|
});
|