Skip to content

Commit

Permalink
#266 [Session] add: JS action on fk_soc and fk_project
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jul 28, 2023
1 parent 7c1dad7 commit 227412b
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 2 deletions.
23 changes: 23 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');

const paths = {
js_backend : ['js/dolimeet.js', 'js/modules/*.js']
};

gulp.task('js_backend', function() {
return gulp.src(paths.js_backend)
.pipe(concat('dolimeet.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./js/'));
});

/** Watch */
gulp.task('default', function() {
gulp.watch(paths.js_backend[1], gulp.series('js_backend'));
});
120 changes: 120 additions & 0 deletions js/dolimeet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.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/>.
*
* Library javascript to enable Browser notifications
*/

/**
* \file js/dolimeet.js
* \ingroup dolimeet
* \brief JavaScript file for module DoliMeet
*/

'use strict';

if (!window.dolimeet) {
/**
* Init DoliMeet JS
*
* @memberof DoliMeet_Init
*
* @since 1.2.0
* @version 1.2.0
*
* @type {Object}
*/
window.dolimeet = {};

/**
* Init scriptsLoaded DoliMeet
*
* @memberof DoliMeet_Init
*
* @since 1.2.0
* @version 1.2.0
*
* @type {Boolean}
*/
window.dolimeet.scriptsLoaded = false;
}

if (!window.dolimeet.scriptsLoaded) {
/**
* DoliMeet init
*
* @memberof DoliMeet_Init
*
* @since 1.2.0
* @version 1.2.0
*
* @returns {void}
*/
window.dolimeet.init = function() {
window.dolimeet.load_list_script();
};

/**
* Load all modules' init
*
* @memberof DoliMeet_Init
*
* @since 1.2.0
* @version 1.2.0
*
* @returns {void}
*/
window.dolimeet.load_list_script = function() {
if (!window.dolimeet.scriptsLoaded) {
let key = undefined, slug = undefined;
for (key in window.dolimeet) {
if (window.dolimeet[key].init) {
window.dolimeet[key].init();
}
for (slug in window.dolimeet[key]) {
if (window.dolimeet[key] && window.dolimeet[key][slug] && window.dolimeet[key][slug].init) {
window.dolimeet[key][slug].init();
}
}
}
window.dolimeet.scriptsLoaded = true;
}
};

/**
* Refresh and reload all modules' init
*
* @memberof DoliMeet_Init
*
* @since 1.2.0
* @version 1.2.0
*
* @returns {void}
*/
window.dolimeet.refresh = function() {
let key = undefined;
let slug = undefined;
for (key in window.dolimeet) {
if (window.dolimeet[key].refresh) {
window.dolimeet[key].refresh();
}
for (slug in window.dolimeet[key]) {
if (window.dolimeet[key] && window.dolimeet[key][slug] && window.dolimeet[key][slug].refresh) {
window.dolimeet[key][slug].refresh();
}
}
}
};
$(document).ready(window.dolimeet.init);
}
1 change: 1 addition & 0 deletions js/dolimeet.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions js/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
//Silence is golden apple
2 changes: 2 additions & 0 deletions js/modules/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is golden
94 changes: 94 additions & 0 deletions js/modules/session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.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/>.
*
* Library javascript to enable Browser notifications
*/

/**
* \file js/session.js
* \ingroup dolimeet
* \brief JavaScript session file for module DoliMeet
*/

/**
* Init session JS
*
* @memberof DoliMeet_Session
*
* @since 1.2.0
* @version 1.2.0
*
* @type {Object}
*/
window.dolimeet.session = {};

/**
* Session init
*
* @memberof DoliMeet_Session
*
* @since 1.2.0
* @version 1.2.0
*
* @returns {void}
*/
window.dolimeet.session.init = function() {
window.dolimeet.session.event();
};

/**
* Session event
*
* @memberof DoliMeet_Session
*
* @since 1.2.0
* @version 1.2.0
*
* @returns {void}
*/
window.dolimeet.session.event = function() {
$(document).on('change', '#fk_soc', window.dolimeet.session.reloadField);
};

/**
* Session reload field
*
* @memberof DoliMeet_Session
*
* @since 1.2.0
* @version 1.2.0
*
* @returns {void}
*/
window.dolimeet.session.reloadField = function() {
let form = document.getElementById('session_form');
let formData = new FormData(form);

let token = window.saturne.toolbox.getToken();
let querySeparator = window.saturne.toolbox.getQuerySeparator(document.URL);

let field = formData.get('fk_soc');

$.ajax({
url: document.URL + querySeparator + "fk_soc=" + field + "&token=" + token,
type: "POST",
processData: false,
contentType: false,
success: function(resp) {
$('.field_fk_project').replaceWith($(resp).find('.field_fk_project'));
},
error: function() {}
});
};
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"main": "index.js",
"scripts": {
"update": "npm install",
"start": "node node_modules/gulp/bin/gulp.js"
},
"author": "Evarisk",
"contributors": [
{
"name": "Evarisk",
"email": "technique@evarisk.com"
}
],
"license": "GPLv3",
"devDependencies": {
"gulp": "^4.0.0",
"gulp-autoprefixer": "^6.0.0",
"gulp-concat": "latest",
"gulp-line-ending-corrector": "^1.0.3",
"gulp-rename": "latest",
"gulp-sass": "latest",
"sass": "latest",
"gulp-uglify": "latest",
"gulp-watch": "latest"
}
}
12 changes: 10 additions & 2 deletions view/session/session_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@

print load_fiche_titre($langs->trans('New' . ucfirst($object->element)), '', 'object_' . $object->picto);

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?object_type=' . $object->element . '">';
print '<form method="POST" id="session_form" action="' . $_SERVER['PHP_SELF'] . '?object_type=' . $object->element . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="add">';
if ($backtopage) {
Expand Down Expand Up @@ -320,6 +320,10 @@
$fromType = GETPOSTISSET('fromtype') ? GETPOST('fromtype', 'alpha') : ''; // element type.
$fromID = GETPOSTISSET('fromid') ? GETPOST('fromid', 'int') : 0; //element id.

if (GETPOST('fk_soc')) {
$object->fields['fk_project']['type'] = 'integer:Project:projet/class/project.class.php:0:(fk_soc:=:' . GETPOST('fk_soc') . ')';
}

if (!empty($fromType)) {
switch ($fromType) {
case 'thirdparty' :
Expand Down Expand Up @@ -368,7 +372,7 @@
if (($id || $ref) && $action == 'edit') {
print load_fiche_titre($langs->trans('Modify' . ucfirst($object->element)), '', 'object_' . $object->picto);

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?object_type=' . $object->element . '">';
print '<form method="POST" id="session_form" action="' . $_SERVER['PHP_SELF'] . '?object_type=' . $object->element . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
Expand All @@ -383,6 +387,10 @@

print '<table class="border centpercent tableforfieldedit">';

if (GETPOST('fk_soc')) {
$object->fields['fk_project']['type'] = 'integer:Project:projet/class/project.class.php:0:(fk_soc:=:' . GETPOST('fk_soc') . ')';
}

// Common attributes.
require_once DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';

Expand Down

0 comments on commit 227412b

Please sign in to comment.