Skip to content

Commit

Permalink
// Javascript cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien Metzger committed Jan 2, 2014
1 parent 5ac1a1f commit b7bc157
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 227 deletions.
22 changes: 7 additions & 15 deletions admin-dev/themes/default/js/admin-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
* International Registered Trademark & Property of PrestaShop SA
*/

$( document ).ready(function() {
$(document).ready(function() {

$("[name^='checkBoxShopGroupAsso_theme']").change(function(){

$(this).parents('.tree-folder').find("[name^='checkBoxShopAsso_theme']").each(function(){
var id = $(this).attr('value');
var checked = $(this).prop('checked');
Expand All @@ -39,7 +38,6 @@ $( document ).ready(function() {
toggleShopModuleCheckbox(id, checked);
});

//nav side bar
function navSidebar(){
//$('body.page-topbar').removeClass('page-topbar').addClass('page-sidebar');
//$('#nav-topbar').attr('id','nav-sidebar');
Expand Down Expand Up @@ -70,7 +68,7 @@ $( document ).ready(function() {
$('.expanded').removeClass('expanded');
});
}
//nav top bar

function navTopbar(){
//$('body').removeClass('page-sidebar').addClass('page-topbar').removeClass('page-sidebar-closed');
$('#nav-sidebar').attr('id','nav-topbar');
Expand Down Expand Up @@ -137,6 +135,7 @@ $( document ).ready(function() {
$(this).addClass('expanded');
}
});

//get click for item which has submenu
navigation.on('click.submenu','.maintab.has_submenu a.title', function(e){
e.preventDefault();
Expand All @@ -149,6 +148,7 @@ $( document ).ready(function() {
navigation.append(submenu);
submenu.show();
});

navigation.on('click.back','#nav-mobile-submenu-back',function(e){
e.preventDefault();
submenu.remove();
Expand All @@ -170,7 +170,6 @@ $( document ).ready(function() {
}
}

//nav switch - not used for now
function navSwitch(){
if ($('body').hasClass('page-sidebar')){
navTopbar();
Expand All @@ -179,7 +178,6 @@ $( document ).ready(function() {
}
}

//init menu
function initNav(){
if ($('body').hasClass('page-sidebar')){
navSidebar();
Expand All @@ -188,23 +186,18 @@ $( document ).ready(function() {
navTopbar();
}
}

initNav();
// tooltips
$('.label-tooltip, .help-tooltip').tooltip();

//modal
$('.label-tooltip, .help-tooltip').tooltip();
$("#error-modal").modal("show");

//scroll top
function animateGoTop() {
if ($(window).scrollTop())
{
if ($(window).scrollTop()) {
$('#go-top:hidden').stop(true, true).fadeIn();
$('#go-top:hidden').removeClass('hide');
} else {
} else
$('#go-top').stop(true, true).fadeOut();
}
}

$("#go-top").on('click',function() {
Expand All @@ -216,7 +209,6 @@ $( document ).ready(function() {
animateGoTop();
});


function toggleShopModuleCheckbox(id_shop, toggle){
var formGroup = $("[for='to_disable_shop"+id_shop+"']").parent();
if (toggle === true)
Expand Down
1 change: 0 additions & 1 deletion classes/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class MediaCore
'ui.resizable' => array('fileName' => 'jquery.ui.resizable.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true),
'ui.selectable' => array('fileName' => 'jquery.ui.selectable.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true),
'ui.sortable' => array('fileName' => 'jquery.ui.sortable.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true),
'ui.accordion' => array('fileName' => 'jquery.ui.accordion.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => true),
'ui.autocomplete' => array('fileName' => 'jquery.ui.autocomplete.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.position', 'ui.menu'), 'theme' => true),
'ui.button' => array('fileName' => 'jquery.ui.button.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => true),
'ui.dialog' => array('fileName' => 'jquery.ui.dialog.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.position','ui.button'), 'theme' => true),
Expand Down
1 change: 0 additions & 1 deletion classes/controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,6 @@ public function setMedia()
$this->addJS(array(
_PS_JS_DIR_.'admin.js',
_PS_JS_DIR_.'tools.js',
_PS_JS_DIR_.'ajax.js',
_PS_JS_DIR_.'toolbar.js',
_PS_JS_DIR_.'jquery/plugins/timepicker/jquery-ui-timepicker-addon.js'
));
Expand Down
3 changes: 1 addition & 2 deletions controllers/admin/AdminProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1325,8 +1325,7 @@ public function postProcess()
{
$this->addJqueryUI(array(
'ui.core',
'ui.widget',
'ui.accordion',
'ui.widget'
));

$this->addjQueryPlugin(array(
Expand Down
171 changes: 171 additions & 0 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,75 @@ $(document).ready(function()
$('#'+list_id+'-empty-filters-alert').show();
}
});

var message = $('.toolbarHead');
var view = $(window);

// bind only if message exists. placeholder will be its parent
view.bind("scroll resize", function(e)
{
message.each(function(el){
if (message.length)
{
placeholder = $(this).parent();
if (e.type == 'resize')
$(this).css('width', $(this).parent().width());

placeholderTop = placeholder.offset().top;
var viewTop = view.scrollTop() + 15;
// here we force the toolbar to be "not fixed" when
// the height of the window is really small (toolbar hiding the page is not cool)
window_is_more_than_twice_the_toolbar = view.height() > message.parent().height() * 2;
if (!$(this).hasClass("fix-toolbar") && (window_is_more_than_twice_the_toolbar && (viewTop > placeholderTop)))
{
$(this).css('width', $(this).width());
// fixing parent height will prevent that annoying "pagequake" thing
// the order is important : this has to be set before adding class fix-toolbar
$(this).parent().css('height', $(this).parent().height());
$(this).addClass("fix-toolbar");
}
else if ($(this).hasClass("fix-toolbar") && (!window_is_more_than_twice_the_toolbar || (viewTop <= placeholderTop)) )
{
$(this).removeClass("fix-toolbar");
$(this).removeAttr('style');
$(this).parent().removeAttr('style');
}
}
});
}); // end bind

// if count errors
$('#hideError').on('click', function(e)
{
e.preventDefault();
$('.error').hide('slow', function (){
$('.error').remove();
});
return false;
});

// if count warnings
$(document).on('click', '#linkSeeMore', function(e){
e.preventDefault();
$('#seeMore').show();
$(this).hide();
$('#linkHide').show();
return false;
});
$(document).on('click', '#linkHide', function(e){
e.preventDefault();
$('#seeMore').hide();
$(this).hide();
$('#linkSeeMore').show();
return false;
});
$(document).on('click', '#hideWarn', function(e){
e.preventDefault();
$('.warn').hide('slow', function (){
$('.warn').remove();
});
return false;
});
});


Expand Down Expand Up @@ -1195,3 +1264,105 @@ function ajaxStates (id_state_selected)
});
}
}

var query;
var lang = Array();

function setLang(array_lang) { lang = array_lang; }

function getQuery() {
var result;

result = query;
if (result == null) {
if (window.XMLHttpRequest)
result = new XMLHttpRequest();
else if (window.ActiveXObject)
result = new ActiveXObject('Microsoft.XMLHTTP');
}
return result;
}

function onQueryChange() {
if (query.readyState == 4 && query.status == 200)
document.getElementById('ajax_confirmation').innerHTML = '<span class="green bold">'+lang[0]+'</span>';
}

function request_failed() { alert(lang[1]); }

function showActivity() {
document.getElementById('ajax_confirmation').innerHTML = '<span class="bold">'+lang[2]+'</span>';
}

function check_for_all_accesses(tabsize, tabnumber)
{
var i = 0;
var res = 0;
var right = 0;
var rights = new Array('view', 'add', 'edit', 'delete', 'all');

while (i != parseInt(tabsize) + 1)
{
if ($('#view'+i).prop('checked') == false || $('#edit'+i).prop('checked') == false || $('#add'+i).prop('checked') == false || $('#delete'+i).prop('checked') == false)
$('#all'+i).attr('checked', false);
else
$('#all'+i).attr('checked', "checked");
i++;
}
right = 0;
while (right != 5)
{
res = 0;
i = 0;
while (i != tabsize)
{
if ($('#'+rights[right]+i).prop('checked') == true)
res++;
i++;
}
if (res == tabnumber - 1)
$('#'+rights[right]+'all').attr('checked', "checked");
else
$('#'+rights[right]+'all').attr('checked', false);
right++;
}
}

function perfect_access_js_gestion(src, action, id_tab, tabsize, tabnumber, table)
{
if (id_tab == '-1' && action == 'all')
{
$(table+' .add').attr('checked', src.checked);
$(table+' .edit').attr('checked', src.checked);
$(table+' .delete').attr('checked', src.checked);
$(table+' .view').attr('checked', src.checked);
$(table+' .all').attr('checked', src.checked);
}
else if (action == 'all')
$(table+' .'+id_tab).attr('checked', src.checked);
else if (id_tab == '-1')
$(table+' .'+action).attr('checked', src.checked);
check_for_all_accesses(tabsize, tabnumber);
}

function ajax_power(src, action, id_tab, id_profile, token, tabsize, tabnumber)
{
query = getQuery();
perfect_access_js_gestion(src, action, id_tab, tabsize, tabnumber);
if (query != null) {
try {
query.open('POST', 'index.php?tab=AdminAccess', true);
query.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
query.onreadystatechange = onQueryChange;
query.send('submitAddaccess=1&action='+action+'&perm='+parseInt(src.checked ? '1' : status = '0')+'&id_tab='+parseInt(id_tab)+'&id_profile='+parseInt(id_profile)+'&token='+token);
showActivity();
}
catch(exc) {
request_failed();
}
}
else
alert(lang[3]);
}

function redirect(new_page) { window.location = new_page; }
Loading

0 comments on commit b7bc157

Please sign in to comment.