Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
97f98d7e
Commit
97f98d7e
authored
10 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Plain Diff
Merge pull request #1955 from frederic34/patch-2
Ajax On/Off for product tosell and tobuy
parents
79c6d506
99dde1ad
Branches
develop
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
htdocs/core/ajax/productonoff.php
+52
-0
52 additions, 0 deletions
htdocs/core/ajax/productonoff.php
htdocs/core/lib/ajax.lib.php
+88
-0
88 additions, 0 deletions
htdocs/core/lib/ajax.lib.php
htdocs/product/card.php
+10
-2
10 additions, 2 deletions
htdocs/product/card.php
with
150 additions
and
2 deletions
htdocs/core/ajax/productonoff.php
0 → 100644
+
52
−
0
View file @
97f98d7e
<?php
/*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/ajax/productonoff.php
* \brief File to set tosell and tobuy for product
*/
if
(
!
defined
(
'NOTOKENRENEWAL'
))
define
(
'NOTOKENRENEWAL'
,
'1'
);
// Disables token renewal
if
(
!
defined
(
'NOREQUIREMENU'
))
define
(
'NOREQUIREMENU'
,
'1'
);
if
(
!
defined
(
'NOREQUIREHTML'
))
define
(
'NOREQUIREHTML'
,
'1'
);
if
(
!
defined
(
'NOREQUIREAJAX'
))
define
(
'NOREQUIREAJAX'
,
'1'
);
if
(
!
defined
(
'NOREQUIRESOC'
))
define
(
'NOREQUIRESOC'
,
'1'
);
if
(
!
defined
(
'NOREQUIRETRAN'
))
define
(
'NOREQUIRETRAN'
,
'1'
);
require
'../../main.inc.php'
;
require_once
DOL_DOCUMENT_ROOT
.
'/core/class/genericobject.class.php'
;
$action
=
GETPOST
(
'action'
,
'alpha'
);
$id
=
GETPOST
(
'id'
,
'int'
);
$value
=
GETPOST
(
'value'
,
'int'
);
$object
=
new
GenericObject
(
$db
);
/*
* View
*/
top_httphead
();
print
'<!-- Ajax page called with url '
.
$_SERVER
[
"PHP_SELF"
]
.
'?'
.
$_SERVER
[
"QUERY_STRING"
]
.
' -->'
.
"
\n
"
;
// Registering new values
if
(
!
empty
(
$action
)
&&
!
empty
(
$id
)
&&
$user
->
rights
->
produit
->
creer
)
{
if
(
$action
==
'setstatus'
)
$object
->
setValueFrom
(
'tosell'
,
$value
,
'product'
,
$id
);
else
if
(
$action
==
'setstatus_buy'
)
$object
->
setValueFrom
(
'tobuy'
,
$value
,
'product'
,
$id
);
}
This diff is collapsed.
Click to expand it.
htdocs/core/lib/ajax.lib.php
+
88
−
0
View file @
97f98d7e
...
@@ -459,3 +459,91 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0,
...
@@ -459,3 +459,91 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0,
return
$out
;
return
$out
;
}
}
/**
* On/off button for product tosell or tobuy
*
* @param int $id Id product to set
* @param string $code Name of constant : status or status_buy
* @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid'))
* @return void
*/
function
ajax_productonoff
(
$id
,
$code
,
$input
=
array
())
{
require_once
DOL_DOCUMENT_ROOT
.
'/product/class/product.class.php'
;
global
$conf
,
$langs
,
$db
;
$object
=
new
Product
(
$db
);
$object
->
fetch
(
$id
);
$out
=
'<script type="text/javascript">
$(function() {
var input = '
.
json_encode
(
$input
)
.
';
// Set constant
$("#set_'
.
$code
.
'").click(function() {
$.get( "'
.
DOL_URL_ROOT
.
'/core/ajax/productonoff.php", {
action: \'set'
.
$code
.
'\',
value: \'1\',
id: \''
.
$id
.
'\'
},
function() {
$("#set_'
.
$code
.
'").hide();
$("#del_'
.
$code
.
'").show();
// Enable another element
if (input.disabled && input.disabled.length > 0) {
$.each(input.disabled, function(key,value) {
$("#" + value).removeAttr("disabled");
if ($("#" + value).hasClass("butActionRefused") == true) {
$("#" + value).removeClass("butActionRefused");
$("#" + value).addClass("butAction");
}
});
// Show another element
} else if (input.showhide && input.showhide.length > 0) {
$.each(input.showhide, function(key,value) {
$("#" + value).show();
});
}
});
});
// Del constant
$("#del_'
.
$code
.
'").click(function() {
$.get( "'
.
DOL_URL_ROOT
.
'/core/ajax/productonoff.php", {
action: \'set'
.
$code
.
'\',
value: \'0\',
id: \''
.
$id
.
'\'
},
function() {
$("#del_'
.
$code
.
'").hide();
$("#set_'
.
$code
.
'").show();
// Disable another element
if (input.disabled && input.disabled.length > 0) {
$.each(input.disabled, function(key,value) {
$("#" + value).attr("disabled", true);
if ($("#" + value).hasClass("butAction") == true) {
$("#" + value).removeClass("butAction");
$("#" + value).addClass("butActionRefused");
}
});
// Hide another element
} else if (input.showhide && input.showhide.length > 0) {
$.each(input.showhide, function(key,value) {
$("#" + value).hide();
});
}
});
});
});
</script>'
;
if
(
$code
==
'status'
)
{
$out
.
=
'<span id="set_'
.
$code
.
'" class="linkobject '
.
(
$object
->
$code
==
1
?
'hideobject'
:
''
)
.
'">'
.
img_picto
(
$langs
->
trans
(
"ProductStatusNotOnSell"
),
'switch_off'
)
.
'</span>'
;
$out
.
=
'<span id="del_'
.
$code
.
'" class="linkobject '
.
(
$object
->
$code
==
1
?
''
:
'hideobject'
)
.
'">'
.
img_picto
(
$langs
->
trans
(
"ProductStatusOnSell"
),
'switch_on'
)
.
'</span>'
;
}
if
(
$code
==
'status_buy'
)
{
$out
.
=
'<span id="set_'
.
$code
.
'" class="linkobject '
.
(
$object
->
$code
==
1
?
'hideobject'
:
''
)
.
'">'
.
img_picto
(
$langs
->
trans
(
"ProductStatusNotOnBuy"
),
'switch_off'
)
.
'</span>'
;
$out
.
=
'<span id="del_'
.
$code
.
'" class="linkobject '
.
(
$object
->
$code
==
1
?
''
:
'hideobject'
)
.
'">'
.
img_picto
(
$langs
->
trans
(
"ProductStatusOnBuy"
),
'switch_on'
)
.
'</span>'
;
}
return
$out
;
}
This diff is collapsed.
Click to expand it.
htdocs/product/card.php
+
10
−
2
View file @
97f98d7e
...
@@ -1420,12 +1420,20 @@ else
...
@@ -1420,12 +1420,20 @@ else
// Status (to sell)
// Status (to sell)
print
'<tr><td>'
.
$langs
->
trans
(
"Status"
)
.
' ('
.
$langs
->
trans
(
"Sell"
)
.
')</td><td colspan="2">'
;
print
'<tr><td>'
.
$langs
->
trans
(
"Status"
)
.
' ('
.
$langs
->
trans
(
"Sell"
)
.
')</td><td colspan="2">'
;
if
(
!
empty
(
$conf
->
use_javascript_ajax
)
&&
$user
->
rights
->
produit
->
creer
)
{
print
ajax_productonoff
(
$object
->
id
,
'status'
);
}
else
{
print
$object
->
getLibStatut
(
2
,
0
);
print
$object
->
getLibStatut
(
2
,
0
);
}
print
'</td></tr>'
;
print
'</td></tr>'
;
// Status (to buy)
// Status (to buy)
print
'<tr><td>'
.
$langs
->
trans
(
"Status"
)
.
' ('
.
$langs
->
trans
(
"Buy"
)
.
')</td><td colspan="2">'
;
print
'<tr><td>'
.
$langs
->
trans
(
"Status"
)
.
' ('
.
$langs
->
trans
(
"Buy"
)
.
')</td><td colspan="2">'
;
if
(
!
empty
(
$conf
->
use_javascript_ajax
)
&&
$user
->
rights
->
produit
->
creer
)
{
print
ajax_productonoff
(
$object
->
id
,
'status_buy'
);
}
else
{
print
$object
->
getLibStatut
(
2
,
1
);
print
$object
->
getLibStatut
(
2
,
1
);
}
print
'</td></tr>'
;
print
'</td></tr>'
;
// Batch number management (to batch)
// Batch number management (to batch)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment