From 99c229fae761dd29b3585e19cacc5cab358af564 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 21 May 2017 22:26:36 -0400 Subject: [PATCH] Add toastr, fix several things regarding custom nav elements --- admin/manage_custom_nav_elements.php | 93 ++++++++++++------- .../Navigation/CustomNavElementController.php | 1 + api/Core/json_error.php | 3 +- api/index.php | 4 +- css/mods-for-hesk-new.css | 4 + css/toastr.min.css | 1 + inc/common.inc.php | 12 +++ inc/headerAdmin.inc.php | 12 ++- internal-api/js/alerts.js | 31 +++++++ internal-api/js/lang.js | 5 + internal-api/js/manage-custom-nav-elements.js | 65 ++++++------- js/modsForHesk-javascript.js | 6 +- js/toastr.min.js | 2 + language/en/text.php | 22 +++++ 14 files changed, 188 insertions(+), 73 deletions(-) create mode 100644 css/toastr.min.css create mode 100644 internal-api/js/alerts.js create mode 100644 internal-api/js/lang.js create mode 100644 js/toastr.min.js diff --git a/admin/manage_custom_nav_elements.php b/admin/manage_custom_nav_elements.php index 683bb30f..821b0cdf 100644 --- a/admin/manage_custom_nav_elements.php +++ b/admin/manage_custom_nav_elements.php @@ -30,7 +30,7 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');

- Custom Nav Menu Elements[!] +

+
- - - - - - + + + + + + @@ -72,8 +75,11 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); '); - var currentPlace = 1; + var currentPlace = 0; var addedElementToPlace = false; var first = true; var lastElement = null; $.each(data, function() { if (this.place !== currentPlace) { - if (!addedElementToPlace) { - $('#table-body').append(''); - } - if (lastElement !== null) { //-- Hide the down arrow on the last element $('[data-value="' + lastElement.id + '"]').parent().parent() @@ -145,7 +156,6 @@ function loadTable(modalToClose) { $('#table-body').append(''); currentPlace = this.place; - console.log(this); addedElementToPlace = false; first = true; } @@ -181,7 +191,7 @@ function loadTable(modalToClose) { first = false; } - $('#table-body').append($template); + $tableBody.append($template); elements[this.id] = this; @@ -189,27 +199,14 @@ function loadTable(modalToClose) { lastElement = this; }); - //-- Add missing headers if no elements are in them - if (currentPlace === 1) { - $('#table-body').append(''); - $('#table-body').append(''); - } - if (currentPlace === 1 || currentPlace === 2) { - $('#table-body').append(''); - $('#table-body').append(''); - } - if (lastElement) { //-- Hide the down arrow on the last element $('[data-value="' + lastElement.id + '"]').parent().parent() .find('[data-direction="down"]').css('visibility', 'hidden'); } - - if (modalToClose !== undefined) { - modalToClose.modal('hide'); - } }, error: function(data) { + mfhAlert.errorWithLog(mfhLang.text('failed_to_load_custom_nav_elements'), data.responseJSON); console.error(data); }, complete: function() { @@ -229,6 +226,8 @@ function bindEditModal() { var element = elements[$(this).parent().parent().find('[data-property="id"]').text()]; var $modal = $('#nav-element-modal'); + $modal.find('#edit-label').show(); + $modal.find('#crate-label').hide(); $modal.find('select[name="place"]').val(element.place); $modal.find('input[name="id"]').val(element.id); $modal.find('input[name="url"]').val(element.url); @@ -272,6 +271,8 @@ function bindEditModal() { function bindCreateModal() { $('#create-button').click(function() { var $modal = $('#nav-element-modal'); + $modal.find('#edit-label').hide(); + $modal.find('#crate-label').show(); $modal.find('select[name="place"]').val(1); $modal.find('input[name="id"]').val(-1); var $textLanguages = $modal.find('[data-text-language]'); @@ -312,10 +313,12 @@ function bindDeleteButton() { url: heskUrl + '/api/v1-internal/custom-navigation/' + element.id, headers: { 'X-Internal-Call': true }, success: function() { - console.log('DELETED!'); + mfhAlert.success(mfhLang.text('custom_nav_element_deleted')); loadTable(); }, error: function(data) { + $('#overlay').hide(); + mfhAlert.errorWithLog(mfhLang.text('error_deleting_custom_nav_element'), data.responseJSON); console.error(data); } }); @@ -334,10 +337,10 @@ function bindSortButtons() { url: heskUrl + '/api/v1-internal/custom-navigation/' + element.id + '/sort/' + direction, headers: { 'X-Internal-Call': true }, success: function() { - console.log('Resorted'); loadTable(); }, error: function(data) { + mfhAlert.errorWithLog(mfhLang.text('error_sorting_custom_nav_elements'), data.responseJSON); console.error(data); $('#overlay').hide(); } diff --git a/js/modsForHesk-javascript.js b/js/modsForHesk-javascript.js index 9e9e3e26..535ec778 100644 --- a/js/modsForHesk-javascript.js +++ b/js/modsForHesk-javascript.js @@ -84,7 +84,11 @@ var loadJquery = function() $('[data-hide]').click(function() { var hide = $(this).attr('data-hide'); $('#' + hide).hide(); - }) + }); + + //-- Initialize toastr properties + toastr.options.progressBar = true; + toastr.options.closeButton = true; }; function refreshBackgroundVolatileItems() { diff --git a/js/toastr.min.js b/js/toastr.min.js new file mode 100644 index 00000000..7c0c07c2 --- /dev/null +++ b/js/toastr.min.js @@ -0,0 +1,2 @@ +!function(e){e(["jquery"],function(e){return function(){function t(e,t,n){return g({type:O.error,iconClass:m().iconClasses.error,message:e,optionsOverride:n,title:t})}function n(t,n){return t||(t=m()),v=e("#"+t.containerId),v.length?v:(n&&(v=d(t)),v)}function o(e,t,n){return g({type:O.info,iconClass:m().iconClasses.info,message:e,optionsOverride:n,title:t})}function s(e){C=e}function i(e,t,n){return g({type:O.success,iconClass:m().iconClasses.success,message:e,optionsOverride:n,title:t})}function a(e,t,n){return g({type:O.warning,iconClass:m().iconClasses.warning,message:e,optionsOverride:n,title:t})}function r(e,t){var o=m();v||n(o),u(e,o,t)||l(o)}function c(t){var o=m();return v||n(o),t&&0===e(":focus",t).length?void h(t):void(v.children().length&&v.remove())}function l(t){for(var n=v.children(),o=n.length-1;o>=0;o--)u(e(n[o]),t)}function u(t,n,o){var s=!(!o||!o.force)&&o.force;return!(!t||!s&&0!==e(":focus",t).length)&&(t[n.hideMethod]({duration:n.hideDuration,easing:n.hideEasing,complete:function(){h(t)}}),!0)}function d(t){return v=e("
").attr("id",t.containerId).addClass(t.positionClass),v.appendTo(e(t.target)),v}function p(){return{tapToDismiss:!0,toastClass:"toast",containerId:"toast-container",debug:!1,showMethod:"fadeIn",showDuration:300,showEasing:"swing",onShown:void 0,hideMethod:"fadeOut",hideDuration:1e3,hideEasing:"swing",onHidden:void 0,closeMethod:!1,closeDuration:!1,closeEasing:!1,closeOnHover:!0,extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},iconClass:"toast-info",positionClass:"toast-top-right",timeOut:5e3,titleClass:"toast-title",messageClass:"toast-message",escapeHtml:!1,target:"body",closeHtml:'',closeClass:"toast-close-button",newestOnTop:!0,preventDuplicates:!1,progressBar:!1,progressClass:"toast-progress",rtl:!1}}function f(e){C&&C(e)}function g(t){function o(e){return null==e&&(e=""),e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")}function s(){c(),u(),d(),p(),g(),C(),l(),i()}function i(){var e="";switch(t.iconClass){case"toast-success":case"toast-info":e="polite";break;default:e="assertive"}I.attr("aria-live",e)}function a(){E.closeOnHover&&I.hover(H,D),!E.onclick&&E.tapToDismiss&&I.click(b),E.closeButton&&j&&j.click(function(e){e.stopPropagation?e.stopPropagation():void 0!==e.cancelBubble&&e.cancelBubble!==!0&&(e.cancelBubble=!0),E.onCloseClick&&E.onCloseClick(e),b(!0)}),E.onclick&&I.click(function(e){E.onclick(e),b()})}function r(){I.hide(),I[E.showMethod]({duration:E.showDuration,easing:E.showEasing,complete:E.onShown}),E.timeOut>0&&(k=setTimeout(b,E.timeOut),F.maxHideTime=parseFloat(E.timeOut),F.hideEta=(new Date).getTime()+F.maxHideTime,E.progressBar&&(F.intervalId=setInterval(x,10)))}function c(){t.iconClass&&I.addClass(E.toastClass).addClass(y)}function l(){E.newestOnTop?v.prepend(I):v.append(I)}function u(){if(t.title){var e=t.title;E.escapeHtml&&(e=o(t.title)),M.append(e).addClass(E.titleClass),I.append(M)}}function d(){if(t.message){var e=t.message;E.escapeHtml&&(e=o(t.message)),B.append(e).addClass(E.messageClass),I.append(B)}}function p(){E.closeButton&&(j.addClass(E.closeClass).attr("role","button"),I.prepend(j))}function g(){E.progressBar&&(q.addClass(E.progressClass),I.prepend(q))}function C(){E.rtl&&I.addClass("rtl")}function O(e,t){if(e.preventDuplicates){if(t.message===w)return!0;w=t.message}return!1}function b(t){var n=t&&E.closeMethod!==!1?E.closeMethod:E.hideMethod,o=t&&E.closeDuration!==!1?E.closeDuration:E.hideDuration,s=t&&E.closeEasing!==!1?E.closeEasing:E.hideEasing;if(!e(":focus",I).length||t)return clearTimeout(F.intervalId),I[n]({duration:o,easing:s,complete:function(){h(I),clearTimeout(k),E.onHidden&&"hidden"!==P.state&&E.onHidden(),P.state="hidden",P.endTime=new Date,f(P)}})}function D(){(E.timeOut>0||E.extendedTimeOut>0)&&(k=setTimeout(b,E.extendedTimeOut),F.maxHideTime=parseFloat(E.extendedTimeOut),F.hideEta=(new Date).getTime()+F.maxHideTime)}function H(){clearTimeout(k),F.hideEta=0,I.stop(!0,!0)[E.showMethod]({duration:E.showDuration,easing:E.showEasing})}function x(){var e=(F.hideEta-(new Date).getTime())/F.maxHideTime*100;q.width(e+"%")}var E=m(),y=t.iconClass||E.iconClass;if("undefined"!=typeof t.optionsOverride&&(E=e.extend(E,t.optionsOverride),y=t.optionsOverride.iconClass||y),!O(E,t)){T++,v=n(E,!0);var k=null,I=e("
"),M=e("
"),B=e("
"),q=e("
"),j=e(E.closeHtml),F={intervalId:null,hideEta:null,maxHideTime:null},P={toastId:T,state:"visible",startTime:new Date,options:E,map:t};return s(),r(),a(),f(P),E.debug&&console&&console.log(P),I}}function m(){return e.extend({},p(),b.options)}function h(e){v||(v=n()),e.is(":visible")||(e.remove(),e=null,0===v.children().length&&(v.remove(),w=void 0))}var v,C,w,T=0,O={error:"error",info:"info",success:"success",warning:"warning"},b={clear:r,remove:c,error:t,getContainer:n,info:o,options:{},subscribe:s,success:i,version:"2.1.3",warning:a};return b}()})}("function"==typeof define&&define.amd?define:function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t(require("jquery")):window.toastr=t(window.jQuery)}); +//# sourceMappingURL=toastr.js.map diff --git a/language/en/text.php b/language/en/text.php index 77c69ffb..ba6d580f 100644 --- a/language/en/text.php +++ b/language/en/text.php @@ -52,8 +52,30 @@ $hesklang['resend_email_notification'] = 'Re-send Email Notification'; $hesklang['email_notification_sent'] = 'Email notification sent!'; $hesklang['email_notification_resend_failed'] = 'Error occurred when trying to send notification email.'; $hesklang['edit_category'] = 'Edit Category'; +$hesklang['custom_nav_menu_elements'] = 'Custom Nav Menu Elements'; +$hesklang['create_new'] = 'Create New'; $hesklang['custom_nav_element_deleted'] = 'Custom Navigation Element Deleted!'; $hesklang['no_custom_nav_elements_found'] = 'No custom nav menu elements found'; +$hesklang['alert_success'] = 'Success'; // Used for alert messages +$hesklang['alert_error'] = 'Error'; // Used for alert messages +$hesklang['failed_to_load_custom_nav_elements'] = 'Failed to load custom nav elements!'; +$hesklang['custom_nav_element_deleted'] = 'Custom nav element deleted!'; +$hesklang['error_deleting_custom_nav_element'] = 'Error deleting custom nav element!'; +$hesklang['error_sorting_custom_nav_elements'] = 'Error sorting custom nav elements!'; +$hesklang['custom_nav_element_created'] = 'Custom nav element created!'; +$hesklang['custom_nav_element_saved'] = 'Custom nav element saved!'; +$hesklang['homepage_block'] = 'Homepage - Block'; +$hesklang['customer_navigation'] = 'Customer Navigation'; +$hesklang['staff_navigation'] = 'Staff Navigation'; +$hesklang['custom_nav_text'] = 'Text'; +$hesklang['custom_nav_subtext'] = 'Subtext'; +$hesklang['image_url_slash_font_icon'] = 'Image URL / Font Icon'; +$hesklang['edit_custom_nav_element_title_case'] = 'Edit Custom Nav Element'; +$hesklang['create_custom_nav_element_title_case'] = 'Create Custom Nav Element'; +$hesklang['place'] = 'Place'; +$hesklang['image_type'] = 'Image Type'; +$hesklang['image_url'] = 'Image URL'; +$hesklang['font_icon'] = 'Font Icon'; // ADDED OR MODIFIED IN Mods for HESK 3.0.0 $hesklang['you_have_x_messages'] = 'You have %s new %s'; // %s: Number of new messages, "message" or "messages", depending on #
IDTextSubtextImage URL / Font IconURLActions
' + places[1] + '
' + notFoundText + '
' + places[this.place] + '
' + places[2] + '
' + notFoundText + '
' + places[3] + '
' + notFoundText + '