File manager - Edit - /home/missmand/public_html/learning/old/main/inc/lib/javascript/mm_script.js
Back
// General very important stuff var couple_id; var couple_type; var is_tchat_loaded = false; var is_left_loaded = false; var debug = false; function logIfDebug(msg) { if (debug) console.log(msg); } function getCurrentTime(currentdate) { return currentdate.getMinutes() + ":" + currentdate.getSeconds(); } function setCouple (id, type) { logIfDebug('Couple loaded. Values : (' + id + ', ' + type + ')'); couple_id = id; couple_type = type; } // Tchat methods var deleted_id_list = []; function scrollDown(wrapper) { if (wrapper) { var height = wrapper.prop("scrollHeight"); wrapper.scrollTop(height); } else { console.log('Error, wrapper is not defined'); } } function getScrollDown(wrapper) { if (wrapper.prop("scrollHeight") !== wrapper.scrollTop()) {return wrapper.scrollTop();} return; // This returns undefined } function refreshTchat() { var randomId = Math.floor((Math.random()*9)+1); var currentdate = new Date(); logIfDebug(randomId + ' Appel à refreshTchat ' + getCurrentTime(currentdate)); $.ajax({type: "GET", url: "refresh_tchat.php", data: "action=refresh", timeout: 3500, beforeSend: function() { if (!is_tchat_loaded) $("#mm_tchat").html("Chargement en cours..."); }, complete: function (xhr, status) { var currentdate = new Date(); logIfDebug(randomId + " Appel à refreshTchat completed with status " + status + ". " + getCurrentTime(currentdate)); is_tchat_loaded = true; }, success: function(msg, status, xhr) { var height = getScrollDown($(".mm_tchat_display")); $("#mm_tchat").html(msg.length < 5 ? '<em class="mm_info">Rédigez des messages grâce au champ text ci-dessous.</em>' : msg); deleted_id_list.forEach(function(element) { $('.mm_log_item[id=' + element + ']').hide(); }); $('button.mm_option').click(function() { var action = $(this).attr('data-action'); var id = $(this).attr('data-id'); if (id === 0) { logIfDebug('Found id = 0 in button.mm_option'); } log_action(action, id); }); $('.mm_log_item').click(function() { var id = $(this).attr('id'); mmIdAdd(id); logIfDebug('log n°' + id + ' clicked'); $(this).hide(); $.ajax({type: "POST", url: "../cooperation/delete_log.php", data: "id=" + id, success: function() { // Delete elems in the list that have been deleted by the user // But are still returned by the server // (Because the delete query has not been taken into account yet) mmIdDelete(id); } }); }); scrollDown($("#mm_tchat")); } }); } var global_refresh_tchat_interval; var refreshRightHandle; function mmStartRefreshTchat(interval, couple_id, couple_type) { logIfDebug('Entree dans refresh tchat'); global_refresh_tchat_interval = interval; setCouple(couple_id, couple_type); mmRestartRefreshTchat(); } function mmRestartRefreshTchat() { logIfDebug('Démarrage de Refresh Tchat'); refreshTchat(); refreshRightHandle = setInterval ( function() { refreshTchat(); }, global_refresh_tchat_interval ); } function mmPauseRefreshTchat() { logIfDebug('Pause RefreshTchat'); clearInterval(refreshRightHandle); refreshLeftHandle = 0; } function mmIdAdd(id) { deleted_id_list.push(id); } function mmIdDelete(id) { deleted_id_list.splice(deleted_id_list.indexOf(id),1); } // Tool methods function refreshLeft(callback){ var randomId = Math.floor((Math.random()*9)+1); var currentdate = new Date(); logIfDebug(randomId + ' Appel à refreshLeft ' + getCurrentTime(currentdate)); $.ajax({type: "GET", url: "refresh_left.php", data: { tab: global_current_tab }, timeout: 3500, beforeSend: function() { if (!is_left_loaded) $(".mm_coop_left_items_wrapper").html("Chargement en cours..."); }, complete: function (xhr, status) { var currentdate = new Date(); logIfDebug(randomId + " Appel à refreshLeft completed with status " + status + ". " + getCurrentTime(currentdate)); is_left_loaded = true; }, success: function(msg){ var currentdate = new Date(); logIfDebug(randomId + " Answer received from refresh_left.php " + getCurrentTime(currentdate)); // var height = getScrollDown($(".mm_coop_left_items_wrapper")); $(".mm_coop_left_items_wrapper *").each(function() {$(this).remove();}); // remove content $(".mm_coop_left_items_wrapper").html(msg); $('div.mm_img[data-action]').click(function() { var id = $(this).attr('data-id'); var action = $(this).attr('data-action'); img_click($(this), id, action); }); $(".cliquable").click(function() { cliquable_click($(this)); }); if (callback && callback instanceof Function) { callback(); } var wrapper = $(".mm_coop_left_items_wrapper"); if (wrapper.children().length > 8) { // TODO assumes items_wrapper === 500 wrapper.css('overflow', 'auto'); } else { wrapper.css('overflow', 'hidden'); } } }); } function mmSliderDisplayVal(target) { var s2_val = target.slider("option", "value"); if (s2_val === 0) { // Case value not set yet s2_val = target.attr('data-value'); target.slider("option", "value", s2_val); // This line triggers a "change" event } else { logIfDebug('Value (' + target.attr('data-id') + '): ' + s2_val); target.find("a").html('<p class="mm_slider_text">' + s2_val + '</p>'); target.parent().find("input").attr('value', s2_val); } } function mmSliderStuff() { logIfDebug('Création des sliders'); var initSlider = { min: 1, max: 5, step:1, create: function() {mmSliderDisplayVal($(this));}, change: function() {mmSliderDisplayVal($(this));} }; $('.mm_coop_left_item').each(function() { var ceci = $(this); logIfDebug('Création des sliders pour la question n°' + ceci.attr('data-id')); ceci.find("#mm_slider1").slider(initSlider).slider('disable'); ceci.find("#mm_slider2").slider(initSlider); }); logIfDebug('Création du bouton'); $("#mm_eval_submit_button").button(); } function mmPauseRefreshLeft() { logIfDebug('Pause RefreshLeft'); clearInterval(refreshLeftHandle); refreshLeftHandle = 0; } var global_web_path; var global_current_tab; var global_interval; var refreshLeftHandle; function mmStartRefreshLeft(web_path, current_tab, interval) { // Set global variables global_web_path = web_path; global_current_tab = current_tab; global_interval = interval; // Refresh refreshLeft(); // Set Timeout mmRestartRefreshLeft(); } function mmRestartRefreshLeft() { logIfDebug('Restart RefreshLeft'); refreshLeftHandle = setInterval ( function() {refreshLeft();}, global_interval ); } function img_click (target, id, action) { switch (action) { case 'delete': // Delete target.attr('class', 'mm_img mm_img_loading'); img_delete(id, action); break; case 'edit': // Edition img_edit(id); break; case 'validate': // Validate target.attr('class', 'mm_img mm_img_loading'); img_validate(id); break; } } function img_edit(id) { logIfDebug('edit ' + id); var edit = $('.edit_details[id="' + id + '"]'); var details = $('.details[id="' + id + '"]'); if (edit.is(':hidden')) { closeAll(); details.hide(); $('.edit_details[id="' + id + '"] input:text:visible:first').focus(); edit.show(); $('.edit_details[id="' + id + '"] input:text:visible:first').parent().find(".title").focus(); mmPauseRefreshLeft(); } else { edit.hide(); details.show(); mmRestartRefreshLeft(); } } function img_validate(id) { logIfDebug('validate ' + id); var target_url = global_web_path + "main/cooperation/tool_ajax_do.php"; $.ajax({type: "GET", url: target_url, data: {action: 'validate', id: id, couple_id: couple_id, couple_type: couple_type}, success : function() { refreshLeft(); } }); } function img_delete(id, action) { logIfDebug(action + ' ' + id); var target_url = global_web_path + "main/cooperation/tool_ajax_do.php"; $.ajax({type: "GET", url: target_url, data: {action: action, id: id, couple_id: couple_id, couple_type: couple_type}, success : function() { refreshLeft(); } }); } function closeAll() { $('.edit_details').each(function() { var id = $(this).attr('id'); var edit = $('.edit_details[id="' + id + '"]'); edit.hide(); var details = $('.details[id="' + id + '"]'); details.show(); }); } function mm_test() { logIfDebug('test'); } // Actions on Logs function log_action(action, id) { logIfDebug('log_action : action = ' + action + ', id = ' + id); switch (action) { case 'validate' : img_validate(id); break; case 'edit' : set_current_tab_to_item_then_edit(id); break; case 'delete' : case 'force_delete' : img_delete(id, action); break; case 'restore' : logIfDebug('delete ' + id); var target_url = global_web_path + "main/cooperation/tool_ajax_do.php"; $.ajax({type: "GET", url: target_url, data: {action: 'restore', id: id, couple_id: couple_id, couple_type: couple_type}, success : function() { refreshLeft(); } }); break; } } function set_current_tab_to_item_then_edit(id) { // Find the type of tool_item.id = id var target_url = global_web_path + "main/cooperation/tool_ajax_do.php"; $.ajax({type: "GET", url: target_url, data: {action: 'get_tab', id: id}, success : function(content) { if (content > 0) global_current_tab = content; refreshLeft(function() { img_edit(id); set_current_tab(content); $('.edit_details#' + id).parent().mouseover(); }); } }); } function set_current_tab(i) { $('nav.mm_tabs > a.mm_tab_selected').removeClass('mm_tab_selected').addClass('mm_tab'); $('nav.mm_tabs > a:eq(' + i + ')').addClass('mm_tab_selected').removeClass('mm_tab'); } function form_replace_tchat(form_id) { // Prevent the tchat to refresh mmPauseRefreshTchat(); // Display the new right panel with questions $.ajax({type: "GET", url: "refresh_tchat.php", data: {action: 'form', id: form_id}, success: function(msg){ $('#mm_column_right').html(msg); }}); } function form_redraw_tchat() { mmRestartRefreshTchat(); } function form_set_state (id, state) { logIfDebug('setting state of ' + id + ' to ' + state); var target_url = "tool_ajax_do.php"; var button = $('#buttons>div#verrou[data-id="' + id + '"]'); couple_id = button.attr('data-couple_id'); couple_type = button.attr('data-couple_type'); $.ajax({type: "POST", url: target_url, data: {action: 'set_state', id: id, state: state, couple_id: couple_id, couple_type: couple_type}, success: function(msg) { button.toggleClass('mm_img_lock'); button.toggleClass('mm_img_unlock'); button.attr('title', button.hasClass('mm_img_lock') ? 'hide the form to user' : 'display the form to user'); button.attr('alt', button.hasClass('mm_img_lock') ? 'hide the form to user' : 'display the form to user'); newState = (state + 1) % 2; button.attr('onclick', "form_set_state(" + id + ", " + newState + ")"); logIfDebug('id ' + id + ' set to ' + state); } }); } function mm_save_form(form_id, answers) { var target_url = global_web_path + "main/cooperation/tool_ajax_do.php"; $.ajax({type: "POST", url: target_url, data: {action: 'save_form', id: id} + answers }); }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings