How to override the _createStripeToken function in odoo 12 - javascript

I'm looking for a way to override the _createStripeToken function of the payment_stripe_sca module in odoo 12.
I am doing it like this but the console.log is not displayed. If I add this console log in the original one it is displayed
PaymentForm.include({
/**
* #override
* #private
* #param {Event} ev
* #param {DOMElement} checkedRadio
* #param {Boolean} addPmEvent
*/
_createStripeToken: function (ev, $checkedRadio, addPmEvent) {
console.log("Adfadsfasdfasdfas")
}
})

You need to patch the payment form class and add the js file to the frontend assets (web.assets_frontend).
Override the _createStripeToken function:
odoo.define('stack_overflow.payment_form', function (require) {
"use strict";
var PaymentForm = require('payment.payment_form');
PaymentForm.include({
_createStripeToken: function (ev, $checkedRadio, addPmEvent) {
var self = this;
console.log("Adfadsfasdfasdfas");
return this._super.apply(this, arguments);
},
});
});
Add the file to the front end assets:
<template id="assets_frontend" inherit_id="web.assets_frontend" name="Payment Stripe SCA Assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/stack_overflow/static/src/js/payment_form.js"></script>
</xpath>
</template>
Check assets management for details.

Related

MethodNotAllowedHttpException using Href

I'm trying to verify if an api we use in work is working
with Href, using the route /test/intent/ it should execute the controller and check if its working or not
blade.php
#section('content')
<div class="container">
<div class="col-12 mt-5 text-center">
Test
</div>
</div>
#endsection
route:
Route::post('/test/intent', 'Testing\DebitTestController#intent');
the error we are getting is
MethodNotAllowedHttpException
/**
* Throw a method not allowed HTTP exception.
*
* #param array $others
* #return void
*
* #throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
/**
* Get routes from the collection by method.
*
* #param string|null $method
* #return array
*/
public function get($method = null)
{
return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []);
}
/**
enter code here
You can use url() helper if you don't want to name the route for some reason:
<a href="{{ url('admin/views/query/new_query') }}"

What resolve is doing in this situation?

New to ember, I am having trouble making sense of this code:
On the front-end, is a simple form, that is used to submit user text input as feedback
<Form #onSubmit={{perform this.submitFeedback}}>
<TextField
#multiline={{3}}
#placeholder="Additional comments"
#autoFocus={{not #shouldRenderOptions}}
#value={{this.feedbackText}}
#disabled={{this.submitFeedback.isRunning}}
#onChange={{action (mut this.feedbackText)}}
/>
<ButtonGroup>
<Button
#text="Send feedback"
#loading={{this.submitFeedback.isRunning}}
#onClick={{perform this.submitFeedback}}
/>
<Button
#text="Cancel"
#plain={{true}}
#onClick={{action #onCancel}}
/>
</ButtonGroup>
</Form>
Backing it up, on the .js Component I have:
export default class FeedbackFormComponent extends Component {
/**
* Callback when the feedback form is submitted
* Provides `feedbackText` and `wasContentUseful`
* as arguments.
*
* #type {Function}
* #public
*/
onSubmitFeedback = resolve;
#dropTask
submitFeedback = function* submitFeedback() {
let { feedbackText, wasContentUseful, onSubmitFeedback } = this;
yield onSubmitFeedback(wasContentUseful, feedbackText);
};
}
How can I track, what this submission is actually doing? What is resolve doing in a situation like this? onSubmitFeedback = resolve;
Looks like that is referencing a function that acts like Promise.resolve, according to the documentation.
The referenced function has this signature, where it also takes in 2 arguments like onSubmitFeedback does:
resolve (value, label)

Laralvel autocomplete input from database

Hello im learning Laravel and trying to make an autocompletion of search with sugestion from a database. I see a lot of people doing it with JQuery so that is what i've tried. But when i run the site, i only get one letter of suggestion, and sometimes no suggestion at all. I suspekt my routing is off so i tried dd some information in the query function, but that doesnt show up either,
MY BLADE
<!DOCTYPE html>
<html>
<head>
<title>Laravel 8 Autocomplete Search using Bootstrap Typeahead JS -ItSolutionStuff.com</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>
</head>
<body>
<div class="container">
<h1>Laravel 8 Autocomplete Search using Bootstrap Typeahead JS - ItSolutionStuff.com</h1>
<input class="typeahead form-control" type="text">
</div>
<script type="text/javascript">
var path = "{{ route('autocomplete') }}";
$('input.typeahead').typeahead({
source: function (query, process) {
return $.get(path, { query: query }, function (data) {
return process(data);
});
}
});
</script>
</body>
</html>
MY CONTROLLER
class TypeaheadController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('welcome');
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function autocomplete(Request $request)
{
dd('h');
$data = Edit::select("Adresse")
->where("Adresse","LIKE","%{$request->query}%")
->get();
return response()->json($data);
}
}
MY Routing
Route::get('search', [TypeaheadController::class, 'index'])->name('search');
Route::get('autocomplete', [TypeaheadController::class, 'autocomplete'])->name('autocomplete');
If you guys have any other suggestion on how i can do it. feel free to suggest
$request->query is a reserved function on the $request object. in order to pull the '?query=xyz' from the url in the request you would have to use the $request->query('query') function to return xyz.

JavaScript: getElementById() not working (with either table or paragraph that previously access database)

I'm stuck on a problem where i want to retrieve a html-element for use in javascript. I'm trying to use the function getElementById(), whick did/does work another element (a shopping cart in which items are placed by clicking on a picture), but not for the ones i'm currently working on (a table (or after i gave up on that a paragraph) that holds some information via "data-"-attributes (e.g. data-price) (so that those don't have to be passed/accessed via json etc)).
I always get the error that the variable i'm assigning the gotten Element to is null ("TypeError: datentabelle is null").
This is the full .js-file called "MyJS.js":
function addpizza( pizzanummer, pizzaname, preis) {
"use strict";
var warenkorb = document.getElementById("warenkorb");
var opt = document.createElement('option');
opt.value = pizzanummer;
opt.label = pizzaname;
//opt.data-datapreis = preis;
warenkorb.appendChild(opt);
var para = document.getElementById("paragraphid");
let bisherpreis = para.textContent;
let neupreis = parseFloat(bisherpreis) + parseFloat(preis);
var opt = document.createElement('option');
para.textContent = neupreis.toFixed(2);
var datentabelle = document.getElementById(0); !!This is were the assignment is supposed to happen!!
var aktpreis = datentabelle.data-preis; !!This is were the error is thrown (when "datentabelle" is first accessed)!!
//calc();
}
/*
function calc(){
//no useable body currently
}
*/
This is an excerpt of the HTML-elements code/construction
foreach($dbergebnisse as $pizza){
$aktpizzanummer = $pizza["PizzaNummer"];
$aktname = $pizza["PizzaName"];
$aktpreis = $pizza["Preis"];
$aktbilddatei = $pizza["Bilddatei"];
echo <<< test10
<p id=$aktpizzanummer data-preis=$aktpreis> idptemp </p>
<p>$aktname</p>
<p>$aktpreis €</p>
<img src=$aktbilddatei alt="margherita" width="80" height="80" onclick="addpizza($aktpizzanummer,'$aktname',$aktpreis)">
test10;
and this is the corresponding full .php-file if relevant:
<?php // UTF-8 marker äöüÄÖÜ߀
/**
* Class PageTemplate for the exercises of the EWA lecture
* Demonstrates use of PHP including class and OO.
* Implements Zend coding standards.
* Generate documentation with Doxygen or phpdoc
*
* PHP Version 5
*
* #category File
* #package Pizzaservice
* #author Bernhard Kreling, <b.kreling#fbi.h-da.de>
* #author Ralf Hahn, <ralf.hahn#h-da.de>
* #license http://www.h-da.de none
* #Release 1.2
* #link http://www.fbi.h-da.de
*/
// to do: change name 'PageTemplate' throughout this file
require_once './Page.php';
/**
* This is a template for top level classes, which represent
* a complete web page and which are called directly by the user.
* Usually there will only be a single instance of such a class.
* The name of the template is supposed
* to be replaced by the name of the specific HTML page e.g. baker.
* The order of methods might correspond to the order of thinking
* during implementation.
* #author Bernhard Kreling, <b.kreling#fbi.h-da.de>
* #author Ralf Hahn, <ralf.hahn#h-da.de>
*/
class Bestellung extends Page
{
// to do: declare reference variables for members
// representing substructures/blocks
/**
* Instantiates members (to be defined above).
* Calls the constructor of the parent i.e. page class.
* So the database connection is established.
*
* #return none
*/
protected function __construct()
{
parent::__construct();
// to do: instantiate members representing substructures/blocks
}
/**
* Cleans up what ever is needed.
* Calls the destructor of the parent i.e. page class.
* So the database connection is closed.
*
* #return none
*/
protected function __destruct()
{
parent::__destruct();
}
/**
* Fetch all data that is necessary for later output.
* Data is stored in an easily accessible way e.g. as associative array.
*
* #return none
*/
protected function getViewData()
{
// to do: fetch data for this view from the database
$angebot = array();
$SQLabfrage = "SELECT * FROM angebot";
$Recordset = $this->_database ->query ($SQLabfrage);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
if (!$Recordset)
throw new Exception("Query failed: ".$Connection->error);
//return $Recordset;
$counter = 0;
$pizza = array(); //konnte man iwie net drinnen definieren??
while ($record = $Recordset->fetch_assoc()){
$pizza["PizzaNummer"] = $record["PizzaNummer"];
$pizza["PizzaName"] = $record["PizzaName"];
$pizza["Preis"] = $record["Preis"];
$pizza["Bilddatei"] = $record["Bilddatei"];
//$angebot[0] = $pizza;
array_push($angebot, $pizza);
}
return $angebot;
}
/**
* First the necessary data is fetched and then the HTML is
* assembled for output. i.e. the header is generated, the content
* of the page ("view") is inserted and -if avaialable- the content of
* all views contained is generated.
* Finally the footer is added.
*
* #return none
*/
protected function generateView() //warum geht $record (in schleife) benutzen hier nicht, aber in getviewdata schon??
{
$dbergebnisse = $this->getViewData();
//$record = $this->$Recordset;
//$aktnummer = $record["PizzaNummer"];
$this->generatePageHeader('Bestellung');
// to do: call generateView() for all members
//<form action="https://echo.fbi.h-da.de/" method="POST">
//<form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST"> //original
//$_SESSION["testwert"] = "bla";
//<form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST">
echo <<< test1
<body>
<form action="http://127.0.0.1/pizzaservice/ewa/Kundeerbend.php" method="POST">
<h2> Bestellung</h2>
<h2> Speisekarte</h2>
test1;
foreach($dbergebnisse as $pizza){
$aktpizzanummer = $pizza["PizzaNummer"];
$aktname = $pizza["PizzaName"];
$aktpreis = $pizza["Preis"];
$aktbilddatei = $pizza["Bilddatei"];
echo <<< test10
<p id=$aktpizzanummer data-preis=$aktpreis> idptemp </p>
<p>$aktname</p>
<p>$aktpreis €</p>
<img src=$aktbilddatei alt="margherita" width="80" height="80" onclick="addpizza($aktpizzanummer,'$aktname',$aktpreis)">
test10;
}
/*
echo <<< test1
<body>
<form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST">
<h2> Bestellung</h2>
<h2> Speisekarte</h2>
*/
/*
<!-- Pizzen aus Datenbank -->
<img src="ewabild.jpg" alt="margherita" width="80" height="80">
<p>Margherita</p>
<p>4.00€</p>
<img src="ewabild.jpg" alt="salami" width="80" height="80">
<p>Salami</p>
<p>4.50€</p>
<img src="ewabild.jpg" alt="hawaii" width="80" height="80">
<p>Hawaii</p>
<p>5.50€</p>
*/
$angebotsgroesse = count($dbergebnisse); //kein code in ausgabe!! (also nicht nach echo)
echo <<< test1
<h2>Warenkorb</h2>
<select name="top[]" id= "warenkorb" size=" $angebotsgroesse " multiple>
test1;
foreach($dbergebnisse as $pizza){
$aktpizzanummer = $pizza["PizzaNummer"];
$aktname = $pizza["PizzaName"];
$aktpreis = $pizza["Preis"];
$aktbilddatei = $pizza["Bilddatei"];
echo <<< test1
<option value = "$aktpizzanummer"> $aktname </option>
test1;
}
echo "</select>";
/*
echo <<< test2
<table name = "blatabelle" id="infoetc" size=" $angebotsgroesse " multiple>
<tr>
<td>"bla</td>
</tr>
test2;
foreach($dbergebnisse as $pizza){
$aktpizzanummer = $pizza["PizzaNummer"];
$aktname = $pizza["PizzaName"];
$aktpreis = $pizza["Preis"];
$aktbilddatei = $pizza["Bilddatei"];
echo <<< test1
<tr id = "$aktpizzanummer">
<td data-name>$aktname</td>
<td data-preis>$aktpreis</td>
</tr>
test1;
}
echo "</table>";
*/
echo <<< test1
<p id="paragraphid">0</p>
<input type="hidden" name="gesamtpreis" value="14.50" />
<p><label>
<input type="text" name="Zuname" placeholder="Ihr Nachname"/>
</label></p>
<p><label>
<input type="text" name="kundenadresse" placeholder="Ihre Adresse"/>
</label></p>
<input type="reset" name="Alle löschen" value="Alle Löschen" />
<input type="button" name="Auswahl löschen" value="Auswahl Löschen" />
<input type="submit" name="bestellen" value="Bestellen" />
</form>
<script type ="text/javascript" src="MyJS.js"></script>
</body>
test1;
// to do: output view of this page
$this->generatePageFooter();
}
/**
* Processes the data that comes via GET or POST i.e. CGI.
* If this page is supposed to do something with submitted
* data do it here.
* If the page contains blocks, delegate processing of the
* respective subsets of data to them.
*
* #return none
*/
protected function processReceivedData()
{
parent::processReceivedData();
// to do: call processReceivedData() for all members
}
/**
* This main-function has the only purpose to create an instance
* of the class and to get all the things going.
* I.e. the operations of the class are called to produce
* the output of the HTML-file.
* The name "main" is no keyword for php. It is just used to
* indicate that function as the central starting point.
* To make it simpler this is a static function. That is you can simply
* call it without first creating an instance of the class.
*
* #return none
*/
public static function main()
{
//session_start();
try {
$page = new Bestellung();
$page->processReceivedData();
$page->generateView();
}
catch (Exception $e) {
header("Content-type: text/plain; charset=UTF-8");
echo $e->getMessage();
}
}
}
// This call is starting the creation of the page.
// That is input is processed and output is created.
Bestellung::main();
// Zend standard does not like closing php-tag!
// PHP doesn't require the closing tag (it is assumed when the file ends).
// Not specifying the closing ? > helps to prevent accidents
// like additional whitespace which will cause session
// initialization to fail ("headers already sent").
//? >
Thanks for any help
You should refer to data-preis via dataset,
Cou your code will be smth like:
function addPizza() {
/* Your logic */
var datentabelle = document.getElementById(0);
var aktpreis = datentabelle.dataset.preis;
}

Add link on course page depending on course custom field

I am using Moodle 2.7 and have the following custom field for the courses in the database table mdl_course_info_field:
Full name: School course
Shrot name: school
Type: Menu of choices
Choices:
Highschool course
Prepschool course
The target was to show the link on every course page, where under the settings the chechbox for Highschool course is used. In the file mymoodle/local/link/functions.js there is the link:
if($('#page-course-view-topcollmytheme .orangebar p')) {
$('#page-course-view-topcollmytheme #section-0 .content > .summary').append('<button class="highschoollink">Hig school course</button>');
}
How to check, if the checkbox is choosen an then to show the link on the course page?
You can use a renderer to display a course header:
https://tracker.moodle.org/browse/MDL-36048
So you could include the school link in the course header - here is an example:
In /course/format/formatname/lib.php
Add this function to class format_formatname
/**
* Display's a header at the top of the sections.
*
* #return renderable class
*/
public function course_content_header() {
global $DB, $PAGE, $USER;
if (!isset($PAGE)) {
return null;
}
// Only display if we are on the course-view page.
if (strpos($PAGE->pagetype, 'course-view-') !== 0) {
return null;
}
$sql = "SELECT d.data
FROM {course_info_field} f
JOIN {course_info_data} d ON d.fieldid = f.id AND d.courseid = :courseid
WHERE f.shortname = :shortname";
$params = array('courseid' => $this->courseid, 'shortname' => 'school');
$schoolname = $DB->get_field_sql($sql, $params);
$schoolurl = '';
// You should store the school url in the database somewhere.
// Using switch code for this example.
switch ($schoolname) {
case 'high school' :
$schoolurl = new moodle_url('http://www.schoolsite.com');
break;
...
}
return new format_formatname_coursecontentheader($schoolname, $schoolurl);
}
Also add this class to /course/format/formatname/lib.php
class format_formatname_coursecontentheader implements renderable {
/**
* School name
*
* #var string $schoolname
*/
public $schoolname;
/**
* School url
*
* #var string $schoolurl
*/
public $schoolurl;
/**
* Class storing information to be passed and displayed in the course content header
*
* #param string $schoolname
* #param moodle_url $schoolurl
*/
public function __construct($schoolname, $schoolurl) {
$this->schoolname = $schoolname;
$this->schoolurl = $fields->schoolurl;
}
}
Then in /course/format/formatname/renderer.php
Add this function to class format_formatname_renderer
/**
* Renders course header
*
* #param renderable $courseheader
* #return string
*/
public function render_format_formatname_coursecontentheader($courseheader) {
$output = '';
$schoolname = $courseheader->schoolname;
$schoolurl = $courseheader->schoolurl;
$link = html_writer::link($schoolurl, $schoolname);
$output .= html_writer::div($link, 'format-formatname-schoollink');
return $output;
}
I suggest you add the link to the course as a URL resource.
Then make sure 'conditional activities' are enabled for the site.
Finally edit the URL activity to restrict access to users who have the correct user profile field.
See https://docs.moodle.org/27/en/Conditional_activities_settings for more details.

Categories