NEW expend/collapse list of social networks

This commit is contained in:
Laurent Destailleur 2023-01-20 13:36:23 +01:00
parent b78eebaae2
commit f054dabbdf
6 changed files with 116 additions and 103 deletions

View File

@ -856,9 +856,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '</tr>';
}
// Social network
if (isModEnabled('socialnetworks')) {
showSocialNetwork();
$object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4));
}
// Visibility
@ -1128,8 +1128,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '</tr>';
}
// Social network
if (isModEnabled('socialnetworks')) {
showSocialNetwork();
$object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4));
}
// Visibility
@ -1584,55 +1585,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
}
}
/**
* Show social network part if the module is enabled with hiding functionality
*
* @return void
*/
function showSocialNetwork()
{
global $socialnetworks, $object, $form, $object, $langs;
echo '<script type="text/javascript">$("document").ready(function() {toogleSocialNetwork(false); });</script>';
print '<tr><td>&nbsp;</td><td><a id="lnk" href="javascript:toogleSocialNetwork(true)"></a></td></tr>';
foreach ($socialnetworks as $key => $value) {
if ($value['active']) {
print '<tr class="soc_network">';
print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
print '<td colspan="3">';
if (!empty($value['icon'])) {
print '<span class="fa '.$value['icon'].'"></span>';
}
print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ?GETPOST($key, 'alphanohtml') : (!empty($object->socialnetworks[$key]) ? $object->socialnetworks[$key] : "")).'">';
print '</td>';
print '</tr>';
} elseif (!empty($object->socialnetworks[$key])) {
print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
}
}
print '<script type="text/javascript">
function toogleSocialNetwork(chgCookieState) {
const lnk = $("#lnk");
const items = $(".soc_network");
var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_SOCIALNETWORKS_SHOW=true")) == true;
if (!chgCookieState) cookieState = !cookieState ;
if (cookieState) {
items.hide();
lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("ShowSocialNetwork")).'...");
if(chgCookieState) {document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=false; SameSite=Strict"};
} else {
items.show();
lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("HideSocialNetwork")).'");
if(chgCookieState) {document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=true; SameSite=Strict";}
}
}
</script>';
}
llxFooter();

View File

@ -32,6 +32,7 @@
* \brief File of contacts class
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonsocialnetworks.class.php';
/**
@ -39,6 +40,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
*/
class Contact extends CommonObject
{
use CommonSocialNetworks;
/**
* @var string ID to identify managed object
*/

View File

@ -0,0 +1,102 @@
<?php
/* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/class/commonincoterm.class.php
* \ingroup core
* \brief File of the superclass of object classes that support incoterm (customer and supplier)
*/
/**
* Superclass for social networks
*/
trait CommonSocialNetworks
{
/**
* Show social network part if the module is enabled with hiding functionality
*
* @param array $socialnetworks Array of social networks
* @param int $colspan Colspan
* @return void
*/
public function showSocialNetwork($socialnetworks, $colspan = 4)
{
global $object, $form, $langs;
$nbofnetworks = count($socialnetworks);
$nbactive = 0;
foreach ($socialnetworks as $key => $value) {
if (!empty($object->socialnetworks[$key])) {
$nbactive++;
}
}
if ($nbofnetworks > 1) {
print '<tr><td><br><a class="paddingtop paddingbottom socialnetworklnk" id="socialnetworklnk" href="javascript:toogleSocialNetwork(true)"></a></td>';
print '<td'.($colspan ? ' colspan="'.($colspan-1).'"' : '').'>';
print '<br><a class="paddingtop paddingbottom socialnetworklnk" href="javascript:toogleSocialNetwork(true)"><span class="badge badge-secondary socialnetworklnk">'.$nbactive.'</span></a>';
print '</td>';
print '</tr>';
}
foreach ($socialnetworks as $key => $value) {
if ($value['active'] || $nbofnetworks == 1) {
print '<tr class="soc_network">';
print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
print '<td colspan="3">';
if (!empty($value['icon'])) {
print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>';
}
print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100 maxwidth300 widthcentpercentminusx" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key])).'">';
print '</td>';
print '</tr>';
} elseif (!empty($object->socialnetworks[$key])) {
print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
}
}
print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
if ($nbofnetworks > 1) {
print '<script type="text/javascript">
$("document").ready(function() { toogleSocialNetwork(false); });
jQuery(".socialnetworklnk").onClick(function() {
console.log("Click on link");
toogleSocialNetwork(true);
});
function toogleSocialNetwork(chgCookieState) {
const lnk = $("#socialnetworklnk");
const items = $(".soc_network");
var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_SOCIALNETWORKS_SHOW=true")) == true;
if (!chgCookieState) cookieState = !cookieState ;
if (cookieState) {
items.hide();
lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("ShowSocialNetworks")).'...");
if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=false; SameSite=Strict"};
} else {
items.show();
lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("HideSocialNetworks")).'...");
if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=true; SameSite=Strict";}
}
}
</script>';
}
}
}

View File

@ -500,4 +500,6 @@ CurrentOutstandingBillLate=Current outstanding bill late
BecarefullChangeThirdpartyBeforeAddProductToInvoice=Be carefull, depending on your product price settings, you should change thirdparty before adding product to POS.
EmailAlreadyExistsPleaseRewriteYourCompanyName=email already exists please rewrite your company name
TwoRecordsOfCompanyName=more than one record exists for this company, please contact us to complete your partnership request
CompanySection=Company section
CompanySection=Company section
ShowSocialNetworks=Show social networks
HideSocialNetworks=Hide social networks

View File

@ -1663,7 +1663,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// Social networks
if (isModEnabled('socialnetworks')) {
showSocialNetwork();
$object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4));
}
// Prof ids
@ -2381,7 +2381,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// Social network
if (isModEnabled('socialnetworks')) {
showSocialNetwork();
$object->showSocialNetwork($socialnetworks, ($conf->browser->layout == 'phone' ? 2 : 4));
}
// Prof ids
@ -3299,54 +3299,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
}
}
/**
* Show social network part if the module is enabled with hiding functionality
*
* @return void
*/
function showSocialNetwork()
{
global $socialnetworks, $object, $form, $object, $langs;
echo '<script type="text/javascript">$("document").ready(function() {toogleSocialNetwork(false); });</script>';
print '<tr><td>&nbsp;</td><td><a id="lnk" href="javascript:toogleSocialNetwork(true)"></a></td></tr>';
foreach ($socialnetworks as $key => $value) {
if ($value['active']) {
print '<tr class="soc_network">';
print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
print '<td colspan="3">';
if (!empty($value['icon'])) {
print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>';
}
print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100 maxwidth300 widthcentpercentminusx" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key])).'">';
print '</td>';
print '</tr>';
} elseif (!empty($object->socialnetworks[$key])) {
print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
}
}
print '<script type="text/javascript">
function toogleSocialNetwork(chgCookieState) {
const lnk = $("#lnk");
const items = $(".soc_network");
var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_SOCIALNETWORKS_SHOW=true")) == true;
if (!chgCookieState) cookieState = !cookieState ;
if (cookieState) {
items.hide();
lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("ShowSocialNetwork")).'...");
if(chgCookieState) {document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=false; SameSite=Strict"};
} else {
items.show();
lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("HideSocialNetwork")).'");
if(chgCookieState) {document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=true; SameSite=Strict";}
}
}
</script>';
}
// End of page
llxFooter();

View File

@ -40,6 +40,7 @@
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonsocialnetworks.class.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
@ -49,6 +50,7 @@ require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
class Societe extends CommonObject
{
use CommonIncoterm;
use CommonSocialNetworks;
/**
* @var string ID to identify managed object