$(document).ready(function (e) { //Show result message if the message exists if ($("#overlay_form").html()) { show_msg(); } // Hide show more button if playlists are less than 8 if ($(".thumb").length < 8) { $("#show-more").hide() } //Empty the selected songs on successful submit if ($("#hdnSubmitPlayListResult").val()) { if ($("#hdnSubmitPlayListResult").val() == 'success') { ////Empty playlist songs //sessionStorage.PlaylistSongs = ''; //sessionStorage.PlaylistCount = 0; //Open playlist tab after successful submit $("#main_tab1 li:nth-child(1)").removeClass("activeLi"); $("#main_tab1 li:nth-child(2)").addClass("activeLi"); $(".tab").hide(); $("#tab2").show(); $("#Counter1 .listNum").text(sessionStorage.PlaylistCount); // disable button if enabled on success if ($("#btn-submit-playlist").attr("disabled") == undefined) { disablePlaylistSubmit(); } } } //$('.Songstable').find('tr').each(function (i) { // table numbering // $(this).children('td:eq(0)').text(i / 2 + 1 + ". "); //}); ////////////////////////////////////////////////////// // song type //////////// $("#songType").change(function () { var selectVal = $('#songType option:selected').val(); if (selectVal == 'أخرى') { $(".hiddenText").slideDown(); } else { $(".hiddenText").slideUp(); } }); ///////////////////////// $("#main_tab1").find("li").click(function (e) { $(this).addClass("activeLi"); $(this).siblings().removeClass("activeLi"); $(".tab").hide(); $("#tab" + ($(this).index() + 1)).show(); $("#Counter1 .listNum").text(sessionStorage.PlaylistCount); }); if (sessionStorage.PlaylistName) { $("#PlaylistTitle").val(sessionStorage.PlaylistName); } //Load selected songs to hidden field $("#audio-ids").val(sessionStorage.PlaylistSongs); // Get the songs details list if songs are added to playlist if (sessionStorage.PlaylistCount > 0) { // if selected var songsIds = sessionStorage.PlaylistSongs; $.ajax({ // desktop div url: "/GetAllSongsList", data: { resources: songsIds, mobile: false }, success: function (result) { if (result != '') { $(".songs-loading").hide(); $("#Songstable").html(result); //$("#Counter1 .listNum").text(($(".Songstable tr").length + 1) / 2); ////the circule counter // if new songs added to either playlist or suggested songs //$('#Songstable, #addedTable').bind("DOMSubtreeModified", function () { enablePlaylistSubmit() }); //enable playlist submit on change $("#form1 :input").bind("change", function () { enablePlaylistSubmit() }); } IntializeDropBox('.show-sharing', '.share_this'); } }); //$.ajax({ // mobile div // url: "/GetAllSongsList", // data: { resources: songsIds, mobile: true }, // success: function (result) { // if (result != '') { // $(".songs-loading").hide(); // $("#SongstableMobile").html(result); // } // } //}); } else { $(".songs-loading").hide(); $('#Songstable').html('ليس لديك اغاني مختارة*'); //$('#SongstableMobile').html('ليس لديك اغاني مختارة*'); } // Delete rows on songs table $("#songsTable").on("click", ".deleteIcon", function () { $("#Counter1 .listNum").text(parseInt($("#Counter1 .listNum").text()) - 1); // Decrement counter $(this).parents('.file_info').remove(); enablePlaylistSubmit(); return false; }); //Delete rows on suggested song table $("#addedTable").on("click", ".deleteIcon", function () { $("#Counter2 .listNum").text(parseInt($("#Counter2 .listNum").text()) - 1); // Decrement counter $(this).closest('tr').remove(); enablePlaylistSubmit(); return false; }); countWords(); // Hide show more button if playlists count is less than 8 if ($("#tab1 section:first-child").html()) { if (($("#tab1 section:first-child").html().match(/
/g) || []).length < 8) { $("#show-more").hide(); } } }); //Load playlists in the playlist summary page function loadMorePlaylists() { var start = $("#hdn-playlist-start").val(); // get current limit value from the page $('#show-more').addClass('form-loader'); $.ajax({ url: "/GetPlaylists", data: { start: start, limit: 8 }, success: function (result) { if (result != '') { $($("#tab1 section")[0]).append(result); $("#hdn-playlist-start").val(parseInt($("#hdn-playlist-start").val()) + 8); // increment the limit hdn field on the page var count = (result.match(/
/g) || []).length if (count < 8) { $("#show-more").hide(); // hide loadmore button } $('#show-more').removeClass('form-loader'); } else { $("#show-more").hide(); } } }) } //count word in input function countWords() { var wordCounts = {}; $(".max-words-input").keyup(function () { var matches = this.value.match(/\b/g); wordCounts[this.id] = matches ? matches.length / 2 : 0; var finalCount = 0; $.each(wordCounts, function (k, v) { finalCount += v; }); if (finalCount > 10) { if (!$('.word-validation')[0]) { $(this).parents('.form_row').append('الرجاء ادخال اقل من 10 كلمات'); } } else { $(this).parents('.form_row').find('.word-validation').remove(); } }).keyup(); } // function used to submit the playlist form function submitPlaylist() { if (!validateCapchaImage()) { return false; } if ($('#playlist-form').valid() == true) { //Check words count on title field var wordCount = $("#PlaylistTitle").val().split(' ').length; if (wordCount > 10) {// return false if more than 10 $("#PlaylistTitle").focus(); return false; } //Update the playlist name in session storage sessionStorage.PlaylistName = $("#PlaylistTitle").val(); if (sessionStorage.PlaylistCount > 0) { var suggestedInputText = ''; //Add suggested songs to form $("#addedTable tr").each(function (i, v) { if (v.childNodes.length > 0) { suggestedInputText += '
  • ' + $(v).find('td')[1].innerHTML + ' / ' + $(v).find('td')[2].innerHTML + ' / ' + $(v).find('td')[3].innerHTML + '
  • '; } }); $("#suggested-songs").val(suggestedInputText); // check if title exists $.ajax({ url: "/PlaylistExists", data: { title: $("#PlaylistTitle").val() }, success: function (result) { if (result != '') { if (result =="True") { $($("#PlaylistTitle").parent().next().children()[0]).attr("class", "field-validation-error").html("العنوان مستخدم"); $("#PlaylistTitle").focus(); return false; } else { $('#playlist-form').submit(); disablePlaylistSubmit(); } } } }); } else { $('#Songstable').css('color', 'red'); return false; } } if ($('.field-validation-error')[0]) { $(this).animate({ scrollTop: 0 }, 'slow'); } }; // This function will delete song from submit playlist function deleteSong(resourceId) { sessionStorage.PlaylistSongs = sessionStorage.PlaylistSongs.replace(resourceId, '').replace(",,", ','); // remove the songId from storage and remove empty places sessionStorage.PlaylistCount = parseInt(sessionStorage.PlaylistCount) - 1; $("#audio-ids").val(sessionStorage.PlaylistSongs); $(".playlist-count").html(sessionStorage.PlaylistCount); } function addSuggestedSong() { var count = parseInt($("#Counter2 .listNum").text()); if (count < 20) { // 20 songs limit if ($("#suggested-title").val() != '') { var wordCount = $("#suggested-title").val().split(' ').length; if (wordCount > 10) { $("#suggested-title").focus(); return false; } var suggestedTitle = $("#suggested-title").val(); } else { $("#suggested-title").focus(); return false; } if ($("#suggested-name").val() != '' && $("#suggested-name").val().length < 31) { var suggestedName = $("#suggested-name").val(); } else { $("#suggested-name").focus(); return false; } if ($("#songType").val() == 'أخرى') { if ($("#suggested-others").val() != '') { var suggestedCategory = $("#suggested-others").val(); } else { $("#suggested-others").focus(); return false; } } else { var suggestedCategory = $("#songType").val(); } var songsCount = $('#addedTable tr[class="tableRow"]').length; var appendText = '' + (songsCount + 1) + '.' + suggestedTitle + '' + suggestedName + '' + suggestedCategory + ''; $("#addedTable tbody").append(appendText); enablePlaylistSubmit(); // empty the fields $("#suggested-title").val(''); $("#suggested-name").val(''); $("#suggested-others").val(''); // Increment Counter $("#Counter2 .listNum").text(count + 1); } } // This function will delete song from the song suggestion in playlist submit function deleteSuggestedSong() { alert("to be implemented"); //sessionStorage.PlaylistSongs.indexOf(resourceId); } // This fucntion will disable the submit playlist button function disablePlaylistSubmit() { $("#btn-submit-playlist").attr("disabled", "disabled"); $("#btn-submit-playlist").css("cursor", "default"); $(".submitButton:first").css("background-color", "grey"); $(".submitButton:first button").css("background-color", "grey"); $(".submitButton:first").css("cursor", "default"); } // This fucntion will enable the submit playlist button function enablePlaylistSubmit() { $("#btn-submit-playlist").removeAttr("disabled"); $("#btn-submit-playlist").css("cursor", "pointer"); $(".submitButton:first").css("background-color", "#EB941B"); $(".submitButton:first button").css("background-color", "#EB941B"); $(".submitButton:first").css("cursor", "pointer"); } function resetPlaylist() { //Empty playlist songs sessionStorage.PlaylistSongs = ''; sessionStorage.PlaylistCount = 0; sessionStorage.PlaylistName = ''; $("#playlist-form").find("input[type=text]").val(""); $("#Songstable").html("ليس لديك اغاني مختارة*"); $("#addedTable tbody").html(""); $(".listNum").html("0"); $('.playlist-count').html(0); enablePlaylistSubmit(); } function PlaylistTitleExists(title) { var extists = false; $.ajax({ url: "/PlaylistExists", data: { title: title }, success: function (result) { if (result != '') { extists = result } } }); return extists; }