From 82f9db3fa6deb1003e944d6e68eb336d5f1d80c3 Mon Sep 17 00:00:00 2001 From: Alim Ul Karim Date: Mon, 25 Apr 2016 13:21:34 +0600 Subject: [PATCH] new modifications : Hashset, inputtracker, before and after execution methods. new modifications : Hashset, inputtracker, before and after execution methods. --- JavaScript file order.txt | 59 ++-- .../Admin/Controllers/NavItemsController.js | 25 +- JavaScript-Mvc-Framework/app.config.js | 11 +- JavaScript-Mvc-Framework/app.executeAfter.js | 39 +++ JavaScript-Mvc-Framework/app.executeBefore.js | 307 ++++++++++++++++++ JavaScript-Mvc-Framework/app.global.js | 37 ++- .../app.initializeMethods.js | 175 ---------- JavaScript-Mvc-Framework/app.js | 88 ----- JavaScript-Mvc-Framework/app.run.js | 8 +- JavaScript-Mvc-Framework/attachInitialize.js | 111 +++++++ .../controllers/AppController.js | 163 ++++++++++ .../extensions/hiddenContainer.js | 93 ++++++ .../extensions/initialize.js | 46 ++- .../extensions/inputChangeTracker.js | 98 +++++- .../extensions/spinner.js | 2 +- JavaScript-Mvc-Framework/extensions/urls.js | 4 +- JavaScript-Mvc-Framework/jQueryCaching.js | 77 +++++ JavaScript-Mvc-Framework/jQueryExtend.fn.js | 9 + JavaScript-Mvc-Framework/jQueryExtend.js | 44 ++- JavaScript-Mvc-Framework/schema/hashset.js | 23 +- 20 files changed, 1107 insertions(+), 312 deletions(-) create mode 100644 JavaScript-Mvc-Framework/app.executeAfter.js create mode 100644 JavaScript-Mvc-Framework/app.executeBefore.js delete mode 100644 JavaScript-Mvc-Framework/app.initializeMethods.js create mode 100644 JavaScript-Mvc-Framework/attachInitialize.js create mode 100644 JavaScript-Mvc-Framework/controllers/AppController.js create mode 100644 JavaScript-Mvc-Framework/extensions/hiddenContainer.js create mode 100644 JavaScript-Mvc-Framework/jQueryCaching.js diff --git a/JavaScript file order.txt b/JavaScript file order.txt index 7e6c2bf..211bb0f 100644 --- a/JavaScript file order.txt +++ b/JavaScript file order.txt @@ -1,24 +1,39 @@ -"~/JavaScript-Mvc-framework\byId.js", -"~/Content/Scripts/FrontEnd/jquery.blockUI.js", +"~/Content/Scripts/jquery.blockUI.js", -"~/JavaScript-Mvc-framework/extensions/ajax.js", -"~/JavaScript-Mvc-framework/extensions/clone.js", -"~/JavaScript-Mvc-framework/extensions/constants.js", + "~/JavaScript-Mvc-framework/Prototype/Array.js", -"~/JavaScript-Mvc-framework/extensions/initialize.js", -"~/JavaScript-Mvc-framework/extensions/modal.js", -"~/JavaScript-Mvc-framework/extensions/pagination.js", -"~/JavaScript-Mvc-framework/extensions/regularExp.js", -"~/JavaScript-Mvc-framework/extensions/selectors.js", -"~/JavaScript-Mvc-framework/extensions/spinner.js", -"~/JavaScript-Mvc-framework/extensions/urls.js", -"~/JavaScript-Mvc-framework/controllers/controllers.js", -//"~/JavaScript-Mvc-framework/controllers/homeController.js", -"~/JavaScript-Mvc-framework/areas/admin/controllers/NavItemsController.js", -"~/JavaScript-Mvc-framework/controllers/initialize.js", -"~/JavaScript-Mvc-framework/jQueryExtend.js", -"~/JavaScript-Mvc-framework/jQueryExtend.fn.js", -"~/JavaScript-Mvc-framework/app.config.js", -"~/JavaScript-Mvc-framework/app.js", -"~/JavaScript-Mvc-framework/app.initializeMethods.js", -"~/JavaScript-Mvc-framework/app.run.js" + "~/JavaScript-Mvc-framework/app.js", + "~/JavaScript-Mvc-framework/app.executeBefore.js", + "~/JavaScript-Mvc-framework/app.executeAfter.js", + "~/JavaScript-Mvc-framework/jQueryCaching.js", + "~/JavaScript-Mvc-framework/attachInitialize.js", + + "~/JavaScript-Mvc-framework/schema/schema.js", + "~/JavaScript-Mvc-framework/schema/hashset.js", + "~/JavaScript-Mvc-framework/schema/url.js", + + "~/JavaScript-Mvc-framework/extensions/ajax.js", + "~/JavaScript-Mvc-framework/extensions/hiddenContainer.js", + "~/JavaScript-Mvc-framework/extensions/clone.js", + "~/JavaScript-Mvc-framework/extensions/constants.js", + "~/JavaScript-Mvc-framework/extensions/initialize.js", + "~/JavaScript-Mvc-framework/extensions/inputChangeTracker.js", + "~/JavaScript-Mvc-framework/extensions/modal.js", + "~/JavaScript-Mvc-framework/extensions/pagination.js", + "~/JavaScript-Mvc-framework/extensions/regularExp.js", + "~/JavaScript-Mvc-framework/extensions/selectors.js", + "~/JavaScript-Mvc-framework/extensions/spinner.js", + "~/JavaScript-Mvc-framework/extensions/urls.js", + + "~/JavaScript-Mvc-framework/controllers/controllers.js", + "~/JavaScript-Mvc-framework/controllers/initialize.js", + "~/JavaScript-Mvc-framework/controllers/AppController.js", + + "~/JavaScript-Mvc-framework/areas/admin/controllers/NavItemsController.js", + + "~/JavaScript-Mvc-framework/jQueryExtend.js", + "~/JavaScript-Mvc-framework/jQueryExtend.fn.js", + "~/JavaScript-Mvc-framework/app.config.js", + "~/JavaScript-Mvc-framework/app.global.js", + + "~/JavaScript-Mvc-framework/app.run.js" \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/Areas/Admin/Controllers/NavItemsController.js b/JavaScript-Mvc-Framework/Areas/Admin/Controllers/NavItemsController.js index acd29b9..1f27c1d 100644 --- a/JavaScript-Mvc-Framework/Areas/Admin/Controllers/NavItemsController.js +++ b/JavaScript-Mvc-Framework/Areas/Admin/Controllers/NavItemsController.js @@ -12,7 +12,7 @@ /// /// /// -/// +/// /// /// /// @@ -63,6 +63,7 @@ $.app.controllers.navItemsController = { // bind events self.bindEvents.saveOrderButtonClick(urlSchema.SaveOrder); + self.bindEvents.onBlurInputs($allInputs, urlSchema.SaveOrder); @@ -71,6 +72,20 @@ $.app.controllers.navItemsController = { }, bindEvents: { + onBlurInputs: function ($allInputs) { + var self = $.app.controllers.navItemsController, + tracker = self.prop.tracker; + $allInputs.on('blur', function () { + var $input = $(this), + $tr = $input.parent().parent().parent(); + console.log($tr); + if (tracker.isChanged($input)) { + $tr.addClass("changed-row"); + } else { + $tr.removeClass("changed-row"); + } + }); + }, saveOrderButtonClick: function(saveingUrl) { var $saveBtn = $.byId("save-order-btn"); var self = $.app.controllers.navItemsController, @@ -84,10 +99,11 @@ $.app.controllers.navItemsController = { for (var i = 0; i < ids.length; i++) { var id = ids[i], $form = $.byId(formIdFormat + id); - formArray[i] = $form.serializeArray(); + formArray[i] = $.serializeToJson($form); } - return formArray; + return JSON.stringify(formArray); } + $saveBtn.click(function(e) { e.preventDefault(); // changed inputs ids array, only contains id values. @@ -98,7 +114,8 @@ $.app.controllers.navItemsController = { method: "POST", // by default "GET" url: saveingUrl, data: data, // PlainObject or String or Array - dataType: "JSON" //, // "Text" , "HTML", "xml", "script" + dataType: "JSON", //, // "Text" , "HTML", "xml", "script" + contentType: "application/json", // must add this line for server json submit }).done(function (response) { if (isInTestingMode) { console.log(response); diff --git a/JavaScript-Mvc-Framework/app.config.js b/JavaScript-Mvc-Framework/app.config.js index eaaf212..60ee6df 100644 --- a/JavaScript-Mvc-Framework/app.config.js +++ b/JavaScript-Mvc-Framework/app.config.js @@ -1,4 +1,5 @@ -; $.app = $.app || {}; +/// +; $.app = $.app || {}; ; $.app.config = { /** * app configuration settings. @@ -9,6 +10,12 @@ /// /// Setup all configuration. /// - + var app = $.app; + var classes = [ + app.hiddenContainer, + app.spinner, + $.jQueryCaching + ]; + $.executeArrayOfInitilizeMethods(classes); } }; \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/app.executeAfter.js b/JavaScript-Mvc-Framework/app.executeAfter.js new file mode 100644 index 0000000..3fbd158 --- /dev/null +++ b/JavaScript-Mvc-Framework/app.executeAfter.js @@ -0,0 +1,39 @@ +/// +/// +/// +/// +/// +/// +; $.app = $.app || {}; +/** + * method which runs after all the initialization is done. + */ +$.app.executeAfter = { + /** + * method which runs after all the initialization is done. + * @returns {} + */ + documentSpinnerHide: function () { + $.app.global.documentFullSpinnerHide(); + var timer = setTimeout(function () { + $.app.global.documentFullSpinnerHide(); + clearTimeout(timer); + }, 2500); + }, + captureAnchorAndShowSpinner: function () { + var $anchors = $.findCached("a:link"); + $anchors.click(function (e) { + var $link = $(this), + href = $link.attr("href"); + if (!$.isEmpty(href)) { + var startsWith = href[0]; + if (startsWith !== "#") { + e.preventDefault(); + $.app.global.documentFullSpinnerShow("... Please Wait ..."); + window.location = $link.attr("href"); + } + } + }); + }, + +}; \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/app.executeBefore.js b/JavaScript-Mvc-Framework/app.executeBefore.js new file mode 100644 index 0000000..a886d23 --- /dev/null +++ b/JavaScript-Mvc-Framework/app.executeBefore.js @@ -0,0 +1,307 @@ +/// +/// +/// +/// +/// +; $.app = $.app || {}; +/** +* runs all the methods after initialize method. +*/ +$.app.executeBefore = { + /** + * runs all the methods after initialize method. + */ + toasterComponentSetup: function () { + if (!$.isEmpty(toastr)) { + toastr.options = { + "closeButton": false, + "debug": false, + "newestOnTop": true, + "progressBar": true, + "positionClass": "toast-bottom-left", + "preventDuplicates": true, + "showDuration": "300", + "hideDuration": "1000", + "timeOut": "5000", + "extendedTimeOut": "1000", + "showEasing": "swing", + "hideEasing": "linear", + "showMethod": "fadeIn", + "hideMethod": "fadeOut" + } + } + }, + toolTipShow: function () { + var $tooltipItems = $('.tooltip-show'); + if ($tooltipItems.length > 0) { + $tooltipItems.tooltip({ container: 'body' }); + } + + }, + seoHide: function () { + var $seoHideItems = $(".seo-hide"); + if ($seoHideItems.length > 0) { + $seoHideItems.hide(); + } + }, + menuEnable: function () { + $().jetmenu(); + var menuPage = $("#menu-item-edit-page"); + if (menuPage.length > 0) { + var div = $("#hasDropdownDiv"); + div.hide(); + $("#HasDropDown").click(function () { + if (this.checked) { + div.show('slow'); + } else { + div.hide('slow'); + } + }); + } + }, + bootstrapTableComponentEnable: function () { + var $tables = $("table.bootstrap-table-do"); + if ($tables.length > 0) { + $tables.bootstrapTable(); + } + }, + datePickerComponentEnable: function () { + if ($.isFunc($.datetimepicker)) { + $(".datetimepicker-start").datetimepicker({ + pickDate: true, //en/disables the date picker + pickTime: true, //en/disables the time picker + useMinutes: true, //en/disables the minutes picker + useSeconds: true, //en/disables the seconds picker + useCurrent: true, //when true, picker will set the value to the current date/time + minuteStepping: 1, //set the minute stepping + defaultDate: "", //sets a default date, accepts js dates, strings and moment objects + disabledDates: [], //an array of dates that cannot be selected + enabledDates: [], //an array of dates that can be selected + sideBySide: true //show the date and time picker side by side + + }); + + $(".datepicker-start").datetimepicker({ + pickDate: true, //en/disables the date picker + pickTime: false, //en/disables the time picker + useMinutes: false, //en/disables the minutes picker + useSeconds: false, //en/disables the seconds picker + useCurrent: true, //when true, picker will set the value to the current date/time + minuteStepping: 1, //set the minute stepping + defaultDate: "", //sets a default date, accepts js dates, strings and moment objects + disabledDates: [], //an array of dates that cannot be selected + enabledDates: [], //an array of dates that can be selected + sideBySide: true //show the date and time picker side by side + }); + } + }, + tagComponentEnable: function () { + var $processForm = $.byId("server-validation-form"); + if ($processForm.length > 0) { + var $createdTags = $(".tag-inputs"); + if ($createdTags.length > 0) { + var $tokenField = $processForm.find("[name='__RequestVerificationToken']"), + token = $tokenField.val(); + for (var i = 0; i < $createdTags.length; i++) { + var $tagsInput = $($createdTags[0]), + urlToPost = $tagsInput.attr("data-url"); + // + $tagsInput.tagsinput({ + freeInput: true, + trimValue: true, + typeahead: { + source: function (query) { + return $.post(urlToPost, { id: query, __RequestVerificationToken: token }).done(function (response) { + //console.log("tags:"); + //console.log("response:"); + //console.log(response); + }); + } + }, + onTagExists: function (item, $tag) { + if ($.isEmpty($tag)) { + $tag.hide.fadeIn(); + } + } + }); + } + } + + } + }, + transactionStatusEnable: function () { + var $transaction = $.byId("transaction-container"), + hideTimeOut = parseInt($transaction.attr("data-hide-duration")); + + var hideStatus = function () { + $transaction.attr("data-shown", "true"); + $transaction.hide(500); + }; + var timer = setTimeout(hideStatus, hideTimeOut); + + var stopTimer = function () { + clearTimeout(timer); + } + + $transaction.click(function () { + stopTimer(); + hideStatus(); + }); + }, + loadWow: function () { + var wow = new WOW({ + boxClass: 'wow', // animated element css class (default is wow) + animateClass: 'animated', // animation css class (default is animated) + offset: 100, // distance to the element when triggering the animation (default is 0) + mobile: false // trigger animations on mobile devices (true is default) + }); + wow.init(); + }, + + ratingComponentEnable: function () { + var $frontPageRatings = $.findCached(".rating-5-front"); + if ($frontPageRatings.length > 0) { + $frontPageRatings.rating({ + showClear: false, + showCaption: false + }); + } + + var $detailPageRatingDisplayItems = $.findCached(".rating-5-page-details"); + if ($detailPageRatingDisplayItems.length > 0) { + $detailPageRatingDisplayItems.rating({ + showClear: false, + showCaption: true, + starCaptions: { + 0: "0", + 0.5: "0.5", + 1: "1", + 1.5: "1.5", + 2: "2", + 2.5: "2.5", + 3: "3", + 3.5: "3.5", + 4: "4", + 4.5: "4.5", + 5: "5" + }, + starCaptionClasses: { + 0: 'label label-danger', + 0.5: 'label label-danger', + 1: 'label label-danger', + 1.5: 'label label-warning', + 2: 'label label-warning', + 2.5: 'label label-info', + 3: 'label label-info', + 3.5: 'label label-primary', + 4: 'label label-primary', + 4.5: 'label label-success', + 5: 'label label-success' + } + }); + } + }, + + owlCaroselComponentEnable: function () { + var ownComponentEnable = $.findCachedId("owl-carousel-component"); + if (ownComponentEnable.length > 0) { + $("div.app-suggested-list-items-mobile,div.featured-apps-list-items").owlCarousel({ + responsiveClass: true, + navigation: true, + navigationText: [ + "", + "" + ], + items: 1, //10 items above 1000px browser width + //itemsDesktop: [1152, 6], //5 items between 1000px and 901px + //itemsDesktopSmall: [900, 4], // betweem 900px and 601px + //itemsTablet: [600, 3], //2 items between 600 and 0 + //itemsMobile: [450, 2], + itemsCustom: [370, 1] + }); + + var $suggestionCarosel = $(".owl-list"); + if ($suggestionCarosel.length > 0) { + $suggestionCarosel.owlCarousel({ + navigation: true, + navigationText: [ + "", + "" + ], + items: 7, //10 items above 1000px browser width + itemsDesktop: [1152, 6], //5 items between 1000px and 901px + itemsDesktopSmall: [966, 5], // betweem 900px and 601px + itemsTabletSmall: [730, 4], + itemsTablet: [600, 3], //2 items between 600 and 0 + //itemsCustom: [[0, 2], [435, 3], [450, 2], [600, 3], [730, 4], [900, 5], [950, 6]], // [[740, 6], [1000, 8], [1200, 10], [1600, 16]] + itemsMobile: [450, 2] + //itemsScaleUp: false + + }); + } + + var $appsPreview = $("#apps-preview"); + if ($appsPreview.length > 0) { + $appsPreview.owlCarousel({ + slideSpeed: 300, + paginationSpeed: 400, + singleItem: true, + items: 1, + itemsDesktop: false, + itemsDesktopSmall: false, + itemsTablet: false, + itemsMobile: false, + stopOnHover: true, + navigation: true, // Show next and prev buttons + pagination: false, + autoHeight: true, + navigationText: ["", ""] + }); + } + + } + }, + + revolutionGalleryComponentEnable: function () { + var gallery = $.findCachedId("revolution-gallery-component"); + if (gallery.length > 0) { + var $frontPageGallyery = $(".tp-banner"); + if ($frontPageGallyery.length > 0) { + $frontPageGallyery.show().revolution({ + dottedOverlay: "none", + delay: 5000, + startwidth: 960, + startheight: 320, + hideThumbs: 10, + fullWidth: "off", + navigationType: "bullet", + navigationStyle: "preview2", + forceFullWidth: "off" + }); + } + } + }, + + enableIsotopComponent: function () { + //filtering through isotop + var $required = $.findCachedId("isotop-component"); + if ($required.length > 0) { + var $isotopContainer = $("ul.search-page-apps-list"); + if ($isotopContainer.length > 0) { + var $filterIsotopItems = $('.filter li a'); + if ($filterIsotopItems.length > 0) { + $filterIsotopItems.click(function () { + $('.filter').find("li a").removeClass('active'); + $(this).addClass('active'); + var selector = $(this).attr('data-filter'); + + $isotopContainer.isotope({ + filter: selector + }); + return false; + }); + } + } + } + } +}; \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/app.global.js b/JavaScript-Mvc-Framework/app.global.js index 9377f60..514d594 100644 --- a/JavaScript-Mvc-Framework/app.global.js +++ b/JavaScript-Mvc-Framework/app.global.js @@ -2,7 +2,42 @@ $.app.global = { /** * global methods collection - * execute methods as per necessary, these methods will not run automatically. + * execute methods as per necessary, + * ** these methods will NOT run automatically. ** */ + documentFullSpinnerHide: function () { + var self = $.app.global; + var $bodyStart = $.findCachedId("body-start"); + var fixedClass = "body-fixed"; + var flexible = "body-flexible"; + if ($bodyStart.length > 0) { + if ($bodyStart.hasClass(fixedClass)) { + var $loadingBar = $.findCachedId("loading-bar-full-screen"); + $bodyStart.removeClass(fixedClass).addClass(flexible); + $loadingBar.addClass("animated").removeClass("fadeIn").addClass("fadeOut"); + setTimeout(function () { + $loadingBar.hide(); + $bodyStart.removeClass(fixedClass).addClass(flexible); + }, 1500); + } + } + }, + + documentFullSpinnerShow: function (message) { + var $bodyStart = $.findCachedId("body-start"); + var fixedClass = "body-fixed"; + var flexible = "body-flexible"; + if (!message) { + message = "...Please wait..."; + } + if ($bodyStart.length > 0) { + var $content = $.findCachedId("full-screen-spinner-content"); + var $loadingBar = $.findCachedId("loading-bar-full-screen"); + $bodyStart.removeClass(flexible).addClass(fixedClass); + $content.html(message); + $loadingBar.addClass("animated").removeClass("fadeOut").addClass("fadeIn"); + $loadingBar.show(); + } + } }; \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/app.initializeMethods.js b/JavaScript-Mvc-Framework/app.initializeMethods.js deleted file mode 100644 index 44faab5..0000000 --- a/JavaScript-Mvc-Framework/app.initializeMethods.js +++ /dev/null @@ -1,175 +0,0 @@ -; $.app = $.app || {}; -$.app.initializeMethods = { - /** - * runs all the methods after initialize method. - */ - initialize: function () { - var self = $.app.initializeMethods; - - var keys = Object.keys(self); - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - if (key !== "initialize") { - // execute all other than "initialize" method - var functionsOrMethods = self[key]; - $.executeFunction(functionsOrMethods); - } - } - }, - toasterComponentSetup: function () { - if (!$.isEmpty(toastr)) { - toastr.options = { - "closeButton": false, - "debug": false, - "newestOnTop": true, - "progressBar": true, - "positionClass": "toast-bottom-left", - "preventDuplicates": true, - "showDuration": "300", - "hideDuration": "1000", - "timeOut": "5000", - "extendedTimeOut": "1000", - "showEasing": "swing", - "hideEasing": "linear", - "showMethod": "fadeIn", - "hideMethod": "fadeOut" - } - } - }, - toolTipShow: function () { - var $tooltipItems = $('.tooltip-show'); - if ($tooltipItems.length > 0) { - $tooltipItems.tooltip({ container: 'body' }); - } - - }, - seoHide: function () { - var $seoHideItems = $(".seo-hide"); - if ($seoHideItems.length > 0) { - $seoHideItems.hide(); - } - }, - menuEnable: function () { - $().jetmenu(); - var menuPage = $("#menu-item-edit-page"); - if (menuPage.length > 0) { - var div = $("#hasDropdownDiv"); - div.hide(); - $("#HasDropDown").click(function () { - if (this.checked) { - div.show('slow'); - } else { - div.hide('slow'); - } - }); - } - }, - bootstrapTableComponentEnable: function () { - var $tables = $("table.bootstrap-table-do"); - if ($tables.length > 0) { - $tables.bootstrapTable(); - } - }, - datePickerComponentEnable: function () { - if ($.isFunc($.datetimepicker)) { - $(".datetimepicker-start").datetimepicker({ - pickDate: true, //en/disables the date picker - pickTime: true, //en/disables the time picker - useMinutes: true, //en/disables the minutes picker - useSeconds: true, //en/disables the seconds picker - useCurrent: true, //when true, picker will set the value to the current date/time - minuteStepping: 1, //set the minute stepping - defaultDate: "", //sets a default date, accepts js dates, strings and moment objects - disabledDates: [], //an array of dates that cannot be selected - enabledDates: [], //an array of dates that can be selected - sideBySide: true //show the date and time picker side by side - - }); - - $(".datepicker-start").datetimepicker({ - pickDate: true, //en/disables the date picker - pickTime: false, //en/disables the time picker - useMinutes: false, //en/disables the minutes picker - useSeconds: false, //en/disables the seconds picker - useCurrent: true, //when true, picker will set the value to the current date/time - minuteStepping: 1, //set the minute stepping - defaultDate: "", //sets a default date, accepts js dates, strings and moment objects - disabledDates: [], //an array of dates that cannot be selected - enabledDates: [], //an array of dates that can be selected - sideBySide: true //show the date and time picker side by side - }); - } - }, - tagComponentEnable: function () { - var $processForm = $.byId("server-validation-form"); - if ($processForm.length > 0) { - var $createdTags = $(".tag-inputs"); - if ($createdTags.length > 0) { - var $tokenField = $processForm.find("[name='__RequestVerificationToken']"), - token = $tokenField.val(); - for (var i = 0; i < $createdTags.length; i++) { - var $tagsInput = $($createdTags[0]), - urlToPost = $tagsInput.attr("data-url"); - // - $tagsInput.tagsinput({ - freeInput: true, - trimValue: true, - typeahead: { - source: function (query) { - return $.post(urlToPost, { id: query, __RequestVerificationToken: token }).done(function (response) { - //console.log("tags:"); - //console.log("response:"); - //console.log(response); - }); - } - }, - onTagExists: function (item, $tag) { - if ($.isEmpty($tag)) { - $tag.hide.fadeIn(); - } - } - }); - } - } - - } - }, - transactionStatusEnable: function () { - var $transaction = $.byId("transaction-container"), - hideTimeOut = parseInt($transaction.attr("data-hide-duration")); - - var hideStatus = function () { - $transaction.attr("data-shown", "true"); - $transaction.hide(500); - }; - var timer = setTimeout(hideStatus, hideTimeOut); - - var stopTimer = function () { - clearTimeout(timer); - } - - $transaction.click(function () { - stopTimer(); - hideStatus(); - }); - }, - loadWow: function () { - //var options = { - // scaleColor: false, - // trackColor: 'rgba(266,144,0,0.0)', - // barColor: '#ff7200', - // lineWidth: 2, - // lineCap: 'butt', - // size: 253 - //}; - - - var wow = new WOW({ - boxClass: 'wow', // animated element css class (default is wow) - animateClass: 'animated', // animation css class (default is animated) - offset: 100, // distance to the element when triggering the animation (default is 0) - mobile: false // trigger animations on mobile devices (true is default) - }); - wow.init(); - } -}; \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/app.js b/JavaScript-Mvc-Framework/app.js index 3175bfa..6f0d659 100644 --- a/JavaScript-Mvc-Framework/app.js +++ b/JavaScript-Mvc-Framework/app.js @@ -21,92 +21,4 @@ ; $.app = $.app || {}; $.app = { isDebugging: true, - $hiddenContainer: null, - $hiddenFieldDictionary: [], - hiddenFieldNamesDictionary: [], - initHiddenContainer: function() { - /// - /// Initialize hidden container if exist. - /// - /// returns hidden container. - var app = $.app; - app.$hiddenContainer = $.byId("hidden-fields-container"); - app.$hiddenFieldDictionary = []; - app.hiddenFieldNamesDictionary = []; - return app.$hiddenContainer; - }, - isHiddenContainerExist: function() { - return !$.isEmpty($.app.$hiddenContainer); - }, - _getHiddenFieldDictionary: function(nameOfHiddenField) { - /// - /// Get dictionary hidden field values. - /// - /// - /// null or jquery obejct. - - if (nameOfHiddenField) { - var namesDictionary = $.app.hiddenFieldNamesDictionary; - for (var i = 0; i < namesDictionary.length; i++) { - var hiddenName = namesDictionary[i]; - if (hiddenName === nameOfHiddenField) { - return $.app.$hiddenFieldDictionary[i]; - } - } - } - return null; - }, - _addHiddenFieldToDictionary: function($field) { - /// - /// Only adds the item to the dictionary ($hiddenFieldDictionary, hiddenFieldNamesDictionary) - /// - /// jQuery object. - /// - var app = $.app; - app.$hiddenFieldDictionary.push($field); - app.hiddenFieldNamesDictionary.push($field.attr("name")); - }, - getHiddenField: function(nameOfHiddenField) { - /// - /// Get the hidden field value, if possible get it from dictionary object. - /// Make sure that you put every hidden field inside #hidden-fields-container container - /// - /// - /// get attribute values $returnedObject.attr() or null - var app = $.app; - if (app.isHiddenContainerExist()) { - var $container = app.$hiddenContainer, - $field = app._getHiddenFieldDictionary(nameOfHiddenField); - if ($field) { - // not null - return $field; - } else { - // is null the get id from DOM - $field = $.byId(nameOfHiddenField); - if ($field.length === 0) { - $field = $container.find("[name='" + nameOfHiddenField + "']"); - } - app._addHiddenFieldToDictionary($field); - return $field; - } - } - return null; - }, - setHiddenValue: function(nameOfHiddenField, val) { - /// - /// Get the hidden field value, if possible get it from dictionary object. - /// Make sure that you put every hidden field inside #hidden-fields-container container - /// - /// - /// get attribute values $returnedObject.attr() or null - var app = $.app; - if (app.isHiddenContainerExist()) { - var $field = app.getHiddenField(nameOfHiddenField); - if ($field.length > 0) { - $field.val(val); - return $field; - } - } - return null; - } }; \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/app.run.js b/JavaScript-Mvc-Framework/app.run.js index 52a3d75..2c857cc 100644 --- a/JavaScript-Mvc-Framework/app.run.js +++ b/JavaScript-Mvc-Framework/app.run.js @@ -7,8 +7,14 @@ /// /// /// +/// ; $.app = $.app || {}; $.app.initialize = $.app.initialize || {}; $(document).ready(function () { $.app.initialize(); // initialize everything -}); \ No newline at end of file +}); + +window.onload= function() { + var app = $.app; + $.attachAndExecuteInitialize(app.executeAfter); +} \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/attachInitialize.js b/JavaScript-Mvc-Framework/attachInitialize.js new file mode 100644 index 0000000..2647bd8 --- /dev/null +++ b/JavaScript-Mvc-Framework/attachInitialize.js @@ -0,0 +1,111 @@ +/// +/// +/// +/// +/// + +/** + * Attach and initial method with the class and execute the method. + * @param {} $object : attach a initial method to excute all the methods inside that class. + * @param {} force : if force then it will attach the initial method and execute if exist or not. + * @returns {} + */ +$.attachInitialize = function ($object, force) { + /// + /// Attach a initializer method which will call all the other method except for initialize. + /// + /// Json object + /// Force to add this new method. + var name = "initialize"; + + var initMethod = function () { + var self = $object; + var keys = Object.keys(self); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + if (key !== name) { + // execute all other than "initialize" method + var functionsOrMethods = self[key]; + $.executeFunction(functionsOrMethods); // execute only if it is function. + } + } + } + if (!$.isEmpty($object)) { + var initialize = $object[name]; + if (force === true) { + $object[name] = initMethod; + } else if ($.isEmpty(initialize)) { + $object[name] = initMethod; + } + } +} + +$.attachAndExecuteInitialize = function($object, force) { + var name = "initialize"; + $.attachInitialize($object, force); + $object[name].apply(); +}; + +/** + * Attach initialize methods to array of elements. + * @param {} array of json classes + * @param {} force + * @returns {} + */ +$.attachInitializeToArray = function (array, force) { + /// + /// Attach a initializer method which will call all the other method except for initialize. + /// + /// Json object + /// Force to add this new method.\ + if (!$.isEmpty(array)) { + for (var i = 0; i < array.length; i++) { + var element = array[i]; + $.attachInitialize(element, force); + } + } + +} + +/** + * Attach initialize methods to array of elements and then execute the initialize method. + * @param {} array of json classes + * @param {} force + * @returns {} + */ +$.attachInitializeToArrayAndExecute = function (array, force) { + /// + /// Attach a initializer method which will call all the other method except for initialize. + /// + /// Json object + /// Force to add this new method. + var name = "initialize"; + if (!$.isEmpty(array)) { + for (var i = 0; i < array.length; i++) { + var element = array[i]; + $.attachInitialize(element, force); + element[name].apply(); + } + } +} + +/** + * excute initialize methods from the array of elements. + * @param {} array of json classes + * @param {} force + * @returns {} + */ +$.executeArrayOfInitilizeMethods = function (array) { + /// + /// Attach a initializer method which will call all the other method except for initialize. + /// + /// Json object + /// Force to add this new method. + var name = "initialize"; + if (!$.isEmpty(array)) { + for (var i = 0; i < array.length; i++) { + var element = array[i]; + element[name].apply(); + } + } +} diff --git a/JavaScript-Mvc-Framework/controllers/AppController.js b/JavaScript-Mvc-Framework/controllers/AppController.js new file mode 100644 index 0000000..0684aa4 --- /dev/null +++ b/JavaScript-Mvc-Framework/controllers/AppController.js @@ -0,0 +1,163 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// + +;$.app.controllers = $.app.controllers || {}; +$.app.controllers.appController = { + // any thing related to controllers. + pageId: "app-controller", + $pageElement: null, + prop: { + /// populated from bindEvents.orderingTextBoxChange + tracker: null, + formId: "form-id-", + youtubePlayableBtnId: "apps-preview" + }, + isDebugging: true, + initialize: function () { + var controllers = $.app.controllers, + current = controllers.appController; + if (controllers.isCurrentPage(current)) { + controllers.execute(current); + } + }, + getPage: function() { + return $.app.controllers.appController.$pageElement; + }, + config : function() { + + }, + actions: { + /// + /// Represents the collection of actions exist inside a controller. + /// + SingleAppDisplay: function () { + /// + /// Represents list action page. + /// Refers to the data-action attribute. + /// + /// + var self = $.app.controllers.appController, + $page = self.getPage(), + prop = self.prop, + urlSchema = $.app.urls.getGeneralUrlSchema(false, ["SaveOrder"]); // pass nothing will give Create,Edit,Delete,Index url + // urlSchema.edit will give edit url. + + + // bind events + self.bindEvents.youtubePlayBtnClick(); + + + + $.frontEndAppDetailsPage = { + $showMoreBtnContainer: [], + $showMoreBtns: [], + $showLessBtns: [], + $moreExcert: [], + execute: function () { + this.$showMoreBtnContainer = $(".show-more-btns-container"); + this.$showMoreBtns = $(".see-more-btn"); + this.$showLessBtns = $(".less-btn"); + this.$moreExcert = $(".more"); + if (this.$moreExcert.length > 0) { + this.$moreExcert.hide(); + } + + var $numberElement = $(".app-viewed-numbers"); + if ($numberElement.length > 0) { + $numberElement.number(true); + } + + this.$showMoreBtns.click(function () { + var $this = $(this); + var moreReference = $this.attr("data-ref"); + var dataId = $this.attr("data-id"); + var dataRefSelector; + var dataIdSelector = _.isUndefined(dataId) === false ? "[data-id='" + dataId + "']" : ""; + if (_.isUndefined(moreReference) === false) { + dataRefSelector = "[data-ref='" + moreReference + "']" + dataIdSelector + ":first"; + + var $specificMoreExcertFound = $.frontEndAppDetailsPage.$moreExcert.filter(dataRefSelector); + if ($specificMoreExcertFound.length > 0) { + $specificMoreExcertFound.show("slow"); + $specificMoreExcertFound.css("display", "inline"); + } + var $moreBtnContainer = $.frontEndAppDetailsPage.$showMoreBtnContainer.filter(dataRefSelector); + if ($moreBtnContainer.length > 0) { + $moreBtnContainer.hide("slow"); + } + } + }); + + this.$showLessBtns.click(function () { + var $this = $(this); + var moreReference = $this.attr("data-ref"); + var dataId = $this.attr("data-id"); + var dataRefSelector; + var dataIdSelector = _.isUndefined(dataId) === false ? "[data-id='" + dataId + "']" : ""; + if (_.isUndefined(moreReference) === false) { + dataRefSelector = "[data-ref='" + moreReference + "']" + dataIdSelector + ":first"; + + var $specificMoreExcertFound = $.frontEndAppDetailsPage.$moreExcert.filter(dataRefSelector); + if ($specificMoreExcertFound.length > 0) { + $specificMoreExcertFound.hide("slow"); + } + var $moreBtnContainer = $.frontEndAppDetailsPage.$showMoreBtnContainer.filter(dataRefSelector); + if ($moreBtnContainer.length > 0) { + $moreBtnContainer.show("slow"); + } + } + }); + } + }; + $.frontEndAppDetailsPage.execute(); + + // create tracker + + } + }, + + bindEvents: { + youtubePlayBtnClick: function () { + var self = $.app.controllers.appController, + $page = self.getPage(), + prop = self.prop; + + var $youtubeVideoContainer = $.findCachedId(prop.youtubePlayableBtnId); + if ($youtubeVideoContainer.length === 1) { + $youtubeVideoContainer.find(".playable-btn").click(function () { + var $iframe = $youtubeVideoContainer.find("iframe"); + var $this = $(this); + if ($iframe.length === 1) { + $iframe[0].src += "?rel=0&controls=1&autoplay=1"; + $this.hide("slow"); + $this.unbind("click");//or some other way to make sure that this only happens once + } + }); + } + } + } + +} + diff --git a/JavaScript-Mvc-Framework/extensions/hiddenContainer.js b/JavaScript-Mvc-Framework/extensions/hiddenContainer.js new file mode 100644 index 0000000..6ca2cf4 --- /dev/null +++ b/JavaScript-Mvc-Framework/extensions/hiddenContainer.js @@ -0,0 +1,93 @@ +; $.app = $.app || {}; +$.app.hiddenContainer = { + $hiddenContainer: null, + $hiddenFieldDictionary: [], + hiddenFieldNamesDictionary: [], + initialize: function () { + /// + /// Initialize hidden container if exist. + /// + /// returns hidden container. + var app = $.app.hiddenContainer; + self.$hiddenContainer = $.byId("hidden-fields-container"); + self.$hiddenFieldDictionary = -1; + self.$hiddenFieldDictionary = []; + self.hiddenFieldNamesDictionary = -1; + self.hiddenFieldNamesDictionary = []; + return self.$hiddenContainer; + }, + isHiddenContainerExist: function () { + return !$.isEmpty($.app.hiddenContainer.$hiddenContainer); + }, + _getHiddenFieldDictionary: function (nameOfHiddenField) { + /// + /// Get dictionary hidden field values. + /// + /// + /// null or jquery obejct. + var self = $.app.hiddenContainer; + if (nameOfHiddenField) { + var namesDictionary = self.hiddenFieldNamesDictionary; + for (var i = 0; i < namesDictionary.length; i++) { + var hiddenName = namesDictionary[i]; + if (hiddenName === nameOfHiddenField) { + return self.$hiddenFieldDictionary[i]; + } + } + } + return null; + }, + _addHiddenFieldToDictionary: function ($field) { + /// + /// Only adds the item to the dictionary ($hiddenFieldDictionary, hiddenFieldNamesDictionary) + /// + /// jQuery object. + /// + var app = $.app.hiddenContainer; + self.$hiddenFieldDictionary.push($field); + self.hiddenFieldNamesDictionary.push($field.attr("name")); + }, + getHiddenField: function (nameOfHiddenField) { + /// + /// Get the hidden field value, if possible get it from dictionary object. + /// Make sure that you put every hidden field inside #hidden-fields-container container + /// + /// + /// get attribute values $returnedObject.attr() or null + var self = $.app.hiddenContainer; + if (self.isHiddenContainerExist()) { + var $container = self.$hiddenContainer, + $field = self._getHiddenFieldDictionary(nameOfHiddenField); + if ($field) { + // not null + return $field; + } else { + // is null the get id from DOM + $field = $.byId(nameOfHiddenField); + if ($field.length === 0) { + $field = $container.find("[name='" + nameOfHiddenField + "']"); + } + self._addHiddenFieldToDictionary($field); + return $field; + } + } + return null; + }, + setHiddenValue: function (nameOfHiddenField, val) { + /// + /// Get the hidden field value, if possible get it from dictionary object. + /// Make sure that you put every hidden field inside #hidden-fields-container container + /// + /// + /// get attribute values $returnedObject.attr() or null + var app = $.app.hiddenContainer; + if (self.isHiddenContainerExist()) { + var $field = self.getHiddenField(nameOfHiddenField); + if ($field.length > 0) { + $field.val(val); + return $field; + } + } + return null; + } +} \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/extensions/initialize.js b/JavaScript-Mvc-Framework/extensions/initialize.js index e004410..74b8a6e 100644 --- a/JavaScript-Mvc-Framework/extensions/initialize.js +++ b/JavaScript-Mvc-Framework/extensions/initialize.js @@ -1,17 +1,53 @@ -; $.app = $.app || {}; +/// +/// +/// +; $.app = $.app || {}; + +$.app.initilizeClasses = [ + $.app.executeBefore +]; + $.app.initialize = function () { /// /// Run all modules. /// First runs config.setup() then all initialize methods in all the controllers.js. /// Then run app.initializeMethods.initialize(); /// - + var app = $.app; - app.initHiddenContainer(); app.config.setup(); // runs all configuration before running all initialize methods. - app.initializeMethods.initialize(); // initialize and run everything in the initializeMethods file. + + $.attachInitializeToArrayAndExecute(app.initilizeClasses); + // run controller module - app.spinner.initialize(); // runs all controllers modules. app.controllers.initialize(); // runs all controllers modules. +}; +$.app.initializeController = function (controller) { + /// + /// Run only the controller methods + initialize hidden container , spinner. + /// First runs config.setup() then all initialize methods in all the controllers.js. + /// Then run app.initializeMethods.initialize(); + /// + + var app = $.app; + app.config.setup(); // runs all configuration before running all initialize methods. + // run controller module + controller.initialize(); // runs all controllers modules. }; + +$.app.initializeControllerWithExcuteBeforeMethods = function (controller) { + /// + /// Run only the controller methods + initialize hidden container , spinner. + /// First runs config.setup() then all initialize methods in all the controllers.js. + /// Then run app.initializeMethods.initialize(); + /// + + var app = $.app; + app.config.setup(); // runs all configuration before running all initialize methods. + + $.executeArrayOfInitilizeMethods(app.initilizeClasses); + + // run controller module + controller.initialize(); // runs all controllers modules. +}; \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/extensions/inputChangeTracker.js b/JavaScript-Mvc-Framework/extensions/inputChangeTracker.js index 2ac6352..80877c8 100644 --- a/JavaScript-Mvc-Framework/extensions/inputChangeTracker.js +++ b/JavaScript-Mvc-Framework/extensions/inputChangeTracker.js @@ -19,7 +19,8 @@ $.app.inputChangeTracker = { list: { $inputs: null, // array - initalTexts: null // array + initalTexts: null, // array + idsOrNames: null // array }, createTracker: function ($inputs) { @@ -32,9 +33,53 @@ $.app.inputChangeTracker = { var list = tracker.list; list.$inputs = $inputs; list.initalTexts = $inputs.toArrayWithValues(); + list.idsOrNames = tracker.getAllInputsIdsOrNameArray(); return tracker; }, + isChanged: function ($input) { + var item = this.getInputfromListWithInitialText($input); + if (item !== null) { + var currentText = item.$input.val(); + if (item.initText !== currentText) { + return true; + } + } + return false; + }, + getInputfromListWithInitialText: function ($input) { + var textArr = this.list.initalTexts, + findingId = this.getInputIdOrName($input); + for (var i = 0; i < textArr.length; i++) { + var currentInputId = this.list.idsOrNames[i]; + if (findingId === currentInputId) { + return { + $input: $input, + initText: textArr[i] + } + } + } + return null; + }, + getInputIdOrName: function ($input) { + var name; + if (!$.isEmpty($input.length)) { + name = $input.attr("id"); + if ($.isEmpty(name)) { + name = $input.attr("name"); + } + return name; + } else { + name = $input.id; + if ($.isEmpty(name)) { + name = $input.getAttribute("name"); + } + } + return name; + }, + getInputIdOrNameByIndex: function (index) { + return this.list.idsOrNames[index]; + }, getChangedInputs: function () { /// /// Get all inputs array which are changed at moment of calling this method. @@ -49,6 +94,26 @@ $.app.inputChangeTracker = { currentText = input.value, previousValue = list.initalTexts[i]; if (currentText !== previousValue) { + // different + changedInputsList.push(input); + } + } + return $(changedInputsList); + }, + getUnchangedInputs: function () { + /// + /// Get all inputs array which are changed at moment of calling this method. + /// + /// + var list = this.list, + $inputs = this.list.$inputs, + len = $inputs.length; + var changedInputsList = []; + for (var i = 0; i < len; i++) { + var input = $inputs[i], + currentText = input.value, + previousValue = list.initalTexts[i]; + if (currentText === previousValue) { // different. changedInputsList.push(input); } @@ -68,6 +133,37 @@ $.app.inputChangeTracker = { } return attrArray; }, + getUnchangedInputsAttrArray: function (attr) { + /// + /// Get an array of the given attribute values for changed inputs. + /// + /// Give a attr name. + /// Get an array of the given attribute values for changed inputs. + var $changedInputs = this.getUnchangedInputs(); + var attrArray = new Array($changedInputs.length); + for (var i = 0; i < $changedInputs.length; i++) { + attrArray[i] = $changedInputs[i].getAttribute(attr); + } + return attrArray; + }, + getAllInputsIdsOrNameArray: function () { + /// + /// Get an array of the given attribute values for changed inputs. + /// + /// Give a attr name. + /// Get an array of the given attribute values for changed inputs. + var $inputs = this.list.$inputs; + var attrArray = new Array($inputs.length); + for (var i = 0; i < $inputs.length; i++) { + var input = $inputs[i]; + var idOrName = input.id; + if ($.isEmpty(idOrName)) { + idOrName = input.getAttribute("name"); + } + attrArray[i] = idOrName; + } + return attrArray; + }, setChangedInputsAttr: function (attr, value) { /// /// Set common attribute value to all the changed input elements. diff --git a/JavaScript-Mvc-Framework/extensions/spinner.js b/JavaScript-Mvc-Framework/extensions/spinner.js index a9deccf..cef25ba 100644 --- a/JavaScript-Mvc-Framework/extensions/spinner.js +++ b/JavaScript-Mvc-Framework/extensions/spinner.js @@ -5,7 +5,7 @@ spinnerDisplayTypeId: 1, type: { HtmlTemplate: 1, // renders spinner from Html element - JsTemplate: 2 // render Html by generating Html from javascript. + JsTemplate: 2 // render Html by generating Html from JavaScript. }, initialize: function () { var self = $.app.spinner; diff --git a/JavaScript-Mvc-Framework/extensions/urls.js b/JavaScript-Mvc-Framework/extensions/urls.js index 05a8eb7..3b961be 100644 --- a/JavaScript-Mvc-Framework/extensions/urls.js +++ b/JavaScript-Mvc-Framework/extensions/urls.js @@ -8,8 +8,8 @@ /// /// /// -/// -/// +/// +/// /// ; $.app = $.app || {}; $.app.urls = { diff --git a/JavaScript-Mvc-Framework/jQueryCaching.js b/JavaScript-Mvc-Framework/jQueryCaching.js new file mode 100644 index 0000000..15cd111 --- /dev/null +++ b/JavaScript-Mvc-Framework/jQueryCaching.js @@ -0,0 +1,77 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +; +$.jQueryCaching = { + hashset: null, + /** + * + * @param {} capacity : default is 350 + * @returns {} + */ + initialize: function (capacity, force) { + var hashset = $.app.schema.hashset; + + if (!capacity) { + capacity = 350; + } + var self = $.jQueryCaching; + if (self.hashset === null || force === true) { + self.hashset = hashset.create(capacity); + } + } +} + +$.findCached = function (selector, force) { + /// + /// get jquery searched items, if exist in the + /// + /// + var self = $.jQueryCaching; + var $e; + if (force === true) { + $e = $(selector); + self.hashset.addUnique(selector, $e, true); + return $e; + } else { + var item = self.hashset.getItemObject(selector); + if (item === null) { + $e = $(selector); + self.hashset.addUnique(selector, $e, true); + return $e; + } + return item.value; + } +} +$.findCachedId = function (id, force) { + /// + /// get jquery searched items, if exist in the + /// + /// + var self = $.jQueryCaching; + var $e; + if (force === true) { + $e = $.byId(id); + self.hashset.addUnique(id, $e, true); + return $e; + } else { + var item = self.hashset.getItemObject(id); + if (item === null) { + $e = $.byId(id); + self.hashset.addUnique(id, $e, true); + return $e; + } + return item.value; + } +} \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/jQueryExtend.fn.js b/JavaScript-Mvc-Framework/jQueryExtend.fn.js index 488dd2e..34ac2f5 100644 --- a/JavaScript-Mvc-Framework/jQueryExtend.fn.js +++ b/JavaScript-Mvc-Framework/jQueryExtend.fn.js @@ -44,5 +44,14 @@ $.fn.extend({ array[i] = this[i].value; } return array; + }, + multiformSerialize: function () { + var len = this.length, + array = []; + for (var i = 0; i < len; i++) { + var $from = $(this[i]); + array.push($.serializeToJson($from)); + } + return array; } }); \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/jQueryExtend.js b/JavaScript-Mvc-Framework/jQueryExtend.js index 5960b33..e46f9b4 100644 --- a/JavaScript-Mvc-Framework/jQueryExtend.js +++ b/JavaScript-Mvc-Framework/jQueryExtend.js @@ -215,7 +215,7 @@ $.getHiddenField = function(name) { /// /// Name of the field /// - return $.app.getHiddenField(name); + return $.app.hiddenContainer.getHiddenField(name); }; $.getHiddenValue = function(name) { @@ -224,7 +224,7 @@ $.getHiddenValue = function(name) { /// /// Name of the field /// Get string value of the hidden field. If not found then empty string "". - var $field = $.app.getHiddenField(name); + var $field = $.app.hiddenContainer.getHiddenField(name); if (!$.isEmpty($field)) { return $field.val(); } @@ -238,7 +238,7 @@ $.setHiddenValue = function(name, val) { /// Name of the field /// value of the field /// Get string value of the hidden field. If not found then empty string "". - return $.app.setHiddenValue(name, val); + return $.app.hiddenContainer.setHiddenValue(name, val); }; @@ -340,3 +340,41 @@ $.hideEmptyFields = function($container) { } } }; + +/** + * + * @param {} arrayOfSelectors : Pass array of selectors + * @returns {} jquery elements + */ +$.getjQueryElementsByArrayOfSelectors = function (arrayOfSelectors) { + /// + /// Get jquery elements by passing array of selectors. + /// + /// + /// + var results = []; + for (var i = 0; i < arrayOfSelectors.length; i++) { + var selector = arrayOfSelectors[i]; + var $elems = $(selector); + for (var j = 0; j < $elems.length; j++) { + var elem = $elems[i]; + results.push(elem); + } + } + return $(results); +} + +/** + * Convert single form to json object. + * @param {} $singleForm + * @returns {} + */ +$.serializeToJson = function($singleForm) { + var result = {}; + var formItemsArray = $singleForm.serializeArray(); + for (var i = 0; i < formItemsArray.length; i++) { + var item = formItemsArray[i]; + result[item.name] = item.value; + } + return result; +} \ No newline at end of file diff --git a/JavaScript-Mvc-Framework/schema/hashset.js b/JavaScript-Mvc-Framework/schema/hashset.js index 2adf332..bb5a67a 100644 --- a/JavaScript-Mvc-Framework/schema/hashset.js +++ b/JavaScript-Mvc-Framework/schema/hashset.js @@ -42,7 +42,7 @@ } throw new Error("No id parameter given to set."); }, - setItemByIndex: function (index,id, items) { + setItemByIndex: function (index, id, items) { /// /// Add items uniquely by the given id and item is the hash item could be array or json or anything. /// @@ -58,7 +58,7 @@ } } }, - addUnique: function (id, items) { + addUnique: function (id, items, modifyIfExist) { /// /// Add items uniquely by the given id and item is the hash item could be array or json or anything. /// @@ -67,10 +67,14 @@ /// Returns if the item is added to the list. If not unique then returns false. var isIdEmpty = (id === undefined || id === null); if (isIdEmpty === false) { - if (this.isIdExist(id) === false) { + var index = this.getItemIndex(id); + if (index === -1) { // item not found in the existing list. this.add(id, items); return true; + } else if (modifyIfExist) { + this.setItemByIndex(index, id, items); + return true; } } else { throw new Error("No id parameter given, so can't add new item to the hash-list."); @@ -84,8 +88,8 @@ /// /// var isIdEmpty = (id === undefined || id === null); - console.log(this); - console.log(this.list); + // console.log(this); + // console.log(this.list); if (isIdEmpty === false) { var list = this.list, count = list.count, @@ -111,14 +115,19 @@ /// /// /// - return this.list.ids.indexOf(id) > -1; + return this.getItemIndex(id) > -1; }, getItemIndex: function (id) { /// /// Find and get the item from the list by id. /// /// - return this.list.ids.indexOf(id); + for (var i = 0; i < this.list.count; i++) { + if (this.list.ids[i] === id) { + return i; + } + } + return -1; }, getItemValue: function (id) { ///