Change Odoo 11 Title Bar - javascript

I want to change the page title in the browser for odoo
i add a .JS in new module but this for Odoo 9
openerp.title_365 = function(instance){
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
instance.web.WebClient.include({
start: function() {
this.set('title_part', {"zopenerp": "My_title"});
return this._super();
},
});
}
I found that in this link,
how to change to odoo 11

Use below js code.
Note: Do not forget to change the module name.
odoo.define('<your module name>.AbstractWebClient', function (require) {
"use strict";
var ActionManager = require('web.ActionManager');
var concurrency = require('web.concurrency');
var core = require('web.core');
var config = require('web.config');
var crash_manager = require('web.crash_manager');
var data_manager = require('web.data_manager');
var Dialog = require('web.Dialog');
var Loading = require('web.Loading');
var mixins = require('web.mixins');
var NotificationManager = require('web.notification').NotificationManager;
var RainbowMan = require('web.rainbow_man');
var session = require('web.session');
var Widget = require('web.Widget');
var AbstractWebClient = require('web.AbstractWebClient');
AbstractWebClient.include({
init: function (parent) {
this.client_options = {};
mixins.ServiceProvider.init.call(this);
this._super(parent);
this.origin = undefined;
this._current_state = null;
this.menu_dm = new concurrency.DropMisordered();
this.action_mutex = new concurrency.Mutex();
this.set('title_part', {"zopenerp": "My Title"});
},
})
});

You can change title on login page follow these setps
Activate developer mode
Go to User Interface and click views
Search layout and select web.layout template
Change title from here
Edit title as per you need

Related

template sdk for creating templates using javascript/jquery

I am trying to create an sdk in javscript/jquery for creating templates based on user input, such as the type of templates - profile template, dialog template. These templates require data from an ajax call for their creation.
User Input should include some config param and type of templates.
Since I don't have much experience creating sdk's, I am trying to create a scalable and flexible sdk which can adopt some more functionalities and properties in future.
I am stuck on the problem that what is the basic and best way to create an javascript/jquery sdk?
var dialogTemplate , var = template2 I have added sample templates. The requirement is when user passes template/templates name in tmpConfig.config.type create that particular template/templates by fetching their data simultaneously for each template/templates.Suppose, when call 'dialog template' create dialog template. when call 'dialog template' and 'template2' create both and append it. These template name can be send in array in config.
Below is what I have tried:-
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="mySDK.js"></script>
</head>
<body>
// container for templates
<div id="tmpBox"></div>
</body>
<script type="text/javascript">
const tmpConfig = {
config: {
type: ['dialog','template2',...,...,....]
},
boxId: '#tmpBox'
};
var mySDK= new tmpSDK(tmpConfig );
mySDK.createtemplate(); // create template
</script>
</html>
mySDK.js
function tmpSDK(confg){
// implementation of sdk
this.config = confg;
}
tmpSDK.prototype.createtemplate= function(){
var idsToAppendTemplate = this.config.boxId;
var templateTypes = this.config.type;
// checking number of templates to create
for(var i=0 ; i < templateTypes.length; i++){
if(templateTypes === 'dialog'){
createDialog(idsToAppendTemplate )
}else if(templateTypes === 'template2'){
createTemplate2 (idsToAppendTemplate )
}
}
}
function getData(ajaxConfig){
$.ajax(){
return data;
}
}
// different templates html defined below:-
var dialogTemplate = function(data){
// play with data
var html = '<div class='dialog-template'>MY Dialog Template</div>';
return html;
}
var template2 = function(data){
// play with data
var html = '<div class='template2'>MY Template2</div>';
return html;
}
tmpSDK.prototype.createDialog = function(id){
var ajaxConfig = {
'url' : 'http://dialog endponts/',
....
}
var data = getData(ajaxConfig);
$(id).append(dialogTemplate(data)); // var dialogTemplate
}
tmpSDK.prototype.createTemplate2 = function(id){
var ajaxConfig = {
'url' : 'http://template2endponts/',
....
}
var data = getData(ajaxConfig);
$(id).append(template2(data) ); //// var template2
}
Please, consider to create your sdk as jQuery module with Class using.
(function ( $ ) {
$.fn.mySdk = function(options) {
const element = $(this);
const sdk = new MySdk(options, element);
element.data('plugin-my-sdk', sdk);
return $(this);
};
$.fn.getMySdk = function() {
const element = $(this);
return element.data('plugin-my-sdk');
};
class MySdk {
constructor(options, element) {
this.element = element;
this.settings = $.extend({
type: 'dialog',
}, options );
this.fetchTemplate().done(this.applyTemplate.bind(this));
}
fetchTemplate() {
return $.post({
url: `${document.location.origin}/your-endpoint-for-getting-template`,
data: {
'id': this.element.attr('id'),
'type': this.settings.type
}
});
}
applyTemplate(template) {
this.element.html(template);
}
apiMethod() {
const yourElement = this.element;
const yourElementId = this.element.attr('id');
const yourType = this.settings.type;
}
}
}( jQuery ));
// This snippet - is example of using your sdk
jQuery(function ($) {
const element = $('#tmpBox');
element.mySdk({
type: 'dialog'
});
const sdk = element.getMySdk();
sdk.apiMethod();
});
What this snippet do?
Wrap jQuery function for creating a not global scope and for avoiding jQuery conflict with $ function name
Uses MySdk class for the element.
This works for the case when there is only one jquery element in collection taking by the selector. In this case - const element = $('#tmpBox'); is taking only one element.
This snippet
this.settings = this.settings = $.extend({
type: 'dialog',
}, options );
merges default options with your options. If there is no option in your options object - then default option will be used
If you need to use jquery collection
For example, your sdk element is $('.tmpBox') where is there are more than 1 element - please, consider to use in mySdk each function for init every element.
const elements = $(this);
element.each(function(){
// init for every element;
})

After refresh the page image is not show in the view in AngularJS?

I have to upload a image in AnguarJS using firebase but problem is that the image is properly uploaded as well as i have to store the imageURL into the localStorage but after refresh the page image is remove i don't uderstand what the problem
$scope.backgroundImageURL = [];
$scope.currentUserObject = {};
$scope.uploadBackgroundImage = function(event) {
//Get the userDetail of the current logged in user
$scope.currentUserObject = localStorage.getItem('userName');
//Get the value from the input field and assign into the fireabse node
var userProductImg = $("#getImageAttribute")[0].files[0];
var PRODUCT_STORAGE_REF = firebase.storage().ref('user/image');
//get the date as well as put the imageURL from node
var rn = new Date().getTime().toString();
var task = PRODUCT_STORAGE_REF.child("loggedInUserObject").child($scope.currentUserObject).child(rn).put(userProductImg).then(function(snapshot) {
$timeout(function(){
$scope.backgroundImageURL.push(snapshot.downloadURL);
localStorage.setItem('userImageURL', $scope.backgroundImageURL);
}, 50);
})
}
<input type="file" id="getImageAttribute" ng-click="$event = $event" ng- model="display" multiple onchange="angular.element(this).scope().uploadBackgroundImage(event)"
/>
<span ng-repeat="imgURL in backgroundImageURL">
<img src="{{imgURL}}">
</span>
?
try using ng-src instead of src attribute as it will refresh the image if the there is a dynamic change in bacground img url.
You can more about this from here: https://www.w3schools.com/angular/ng_ng-src.asp
or
you can try this too : https://docs.angularjs.org/api/ng/directive/ngSrc
After refresh the page, your image array is empty:
$scope.backgroundImageURL = [];
You need a method to get images from the storage and assign them to your backgroundImageURL array, and this method has to be called as soon as you load the page.
Your code might be something like the following:
$scope.backgroundImageURL = [];
$scope.currentUserObject = {};
$scope.loadResources();
$scope.loadResources = function() {
$scope.backgroundImageURL = localStorage.getItem('userImageURL');
$scope.currentUserObject = localStorage.getItem('userName');
}
$scope.uploadBackgroundImage = function(event) {
//Get the userDetail of the current logged in user
$scope.currentUserObject = localStorage.getItem('userName');
//Get the value from the input field and assign into the fireabse node
var userProductImg = $("#getImageAttribute")[0].files[0];
var PRODUCT_STORAGE_REF = firebase.storage().ref('user/image');
//get the date as well as put the imageURL from node
var rn = new Date().getTime().toString();
var task = PRODUCT_STORAGE_REF.child("loggedInUserObject").child($scope.currentUserObject).child(rn).put(userProductImg).then(function(snapshot) {
$timeout(function(){
$scope.backgroundImageURL.push(snapshot.downloadURL);
localStorage.setItem('userImageURL', $scope.backgroundImageURL);
}, 50);
})
}

add a button sapui5 javascript

New to sapui5, and I'm trying to make a change to an existing development and add another button to this UI.
Here is my coding, I am trying to add oAssetBtn2 to the UI, the other button already works??
Currently, I am getting the error:
AppController.js:2283 Custom code error: Error: adding element with duplicate id 'assetBtn-Custom2'
Error: Error: adding element with duplicate id 'assetBtn-Custom2'
ASSETCREATE = function() {
var oAssetBtn2 = sap.ui.getCore().byId('assetBtn-Custom2');
};
ASSETCREATE.prototype.CUSTOM_POST_EXIT = function(methodName, view,
controller,methodSignature, dialog) {
if (view == 'accountLineDetails') {
sap.ui.getCore().byId('CategoryListDetAS').setProperty('enabled',false);
this.accounting =
sap.ui.getCore().byId("accAssignment").getController().accounting;
var oFormModel = this.accounting.callMethod("_getFormModel");
var oModel = oFormModel.oData ;
jQuery.sap.require("sap.ui.commons.MessageBox");
var oBtnLayout =
sap.ui.getCore().byId(sap.ui.getCore().byId('saveBtn').getParent().getId());
var oAssetBtn = sap.ui.getCore().byId('assetBtn-Custom');
// Add the "Create Multiple Asset" button in the footer layout
jQuery.sap.require("sap.ui.commons.MessageBox");
var oBtnLayout2 =
sap.ui.getCore().byId(sap.ui.getCore().byId('cancelBtn').getParent().getId());
var oAssetBtn2 = sap.ui.getCore().byId('assetBtn-Custom2');
<%
data: lv_langu type sy-langu.
lv_langu = sy-langu.
%>
var lv_language = "" ;
var lv_text = "";
var lv_multiple_txt = "";
if( lv_language == "F" ){
lv_text = "Créer Immo";
lv_multiple_txt = "Créer Plusieurs Actifs";
}
else{
lv_text = "Create Asset";
lv_multiple_txt = "Create Multiple Assets";
}
var oAssetBtn2 = new sap.ui.commons.Button({
id : "assetBtn-Custom2",
text : lv_multiple_txt,
tooltip : Appcc.getText("Create many Assets")
});
if (!oAssetBtn) {
var oAssetBtn = new sap.ui.commons.Button({
id : "assetBtn-Custom",
text : lv_text,
tooltip : Appcc.getText("Creates an Asset")
});
thanks fellow coders!
View of the error in Chrome:
err
For adding a button to your app, you must bind it to your view or viewing page. How are you going to do this [Layout/view name].addContent([button name]);
in your case it will be
oBtnLayout2.addContent(oAssetBtn2);

Sahi unable to run the for loop

I have been using a test tool call Sahi.
So basically I transferred one of my file, Example.sah , from one computer to another computer. When I run it on my another computer, it can't read the for loop for the code below. I have changed it to while loop and it doesn't work either. However, the codes below worked on my previous computer.
-----------------------------------CODES----------------------------------------
var $userinfo = _readExcelFile("C:/Work/Example.xls");
var $userinfo1 = _readExcelFile("C:/Work/CheckExample.xls");
var $i=0
for ($i++; $i<$userinfo;){
var $Id = $userinfo[$i][0];
var $Int = $userinfo[$i][1];
var $Int2 = $userinfo[$i][2];
var $BigInt1 = $userinfo[$i][3];
var $BigInt2 = $userinfo[$i][4];
var $Double1 = $userinfo[$i][5];
var $Double2 = $userinfo[$i][6];
_click(_link("Edit"));
_click(_link("New"));
_setValue(_textbox("Title"), $Id);
_setValue(_numberbox("TestInt001"), $Int);
_setValue(_numberbox("TestInt002"), $Int2);
_setValue(_numberbox("TestBigint001"), $BigInt1);
_setValue(_numberbox("TestBigint002"), $BigInt2);
_setValue(_numberbox("TestDouble001"), $Double1);
_setValue(_numberbox("TestDouble002"), $Double2);
_click(_cell(0));
_doubleClick(_cell(0));
_click(_submit("Ok"));
var $Idx = $userinfo1[$i][0];
var $Intx = $userinfo1[$i][1];
var $Int2x = $userinfo1[$i][2];
var $BigInt1x = $userinfo1[$i][3];
var $BigInt2x = $userinfo1[$i][4];
var $Double1x = $userinfo1[$i][5];
var $Double2x = $userinfo1[$i][6];
_assertContainsText($Idx, _link($Id));
_assertContainsText($Intx, _cell($Int));
_assertContainsText($Int2x, _cell($Int2));
_assertContainsText($BigInt1x, _cell($BigInt1));
_assertContainsText($BigInt2x, _cell($BigInt2));
_assertEqual($Double1x, _getText(_cell($Double1)));
_assertEqual($Double2x, _getText(_cell($Double2)));
}
--------------------------OUTPUT----------------------------------------------
------------------- Stopped Playback: SUCCESS-------------------
I feel your error is in the below section :
var $i=0
for ($i++; $i<$userinfo;){
You can try replacing it with this
for ($var $i=0;$i<$userinfo;$i++){

How to fetch the name from JavaScript? JavaScript creates new input on every click

I am creating a new input-box by clicking on a link with the help of Javascript.
Here's the Javascript code:
<script>
var instance = 1;
function myFunction(event) {
instance++;
var DivAllPrime=document.getElementById("divPrime");
var newLabel1 = document.createElement("label");
newLabel1.id = "label" + instance;
newLabel1.innerHTML = 'label '+instance;
newLabel1.className="col-md-4 formLineHeight";
var newInput2=document.createElement("input");
newInput2.id="ingredient"+instance;
newInput2.name="ingredient"+instance;
newInput2.className="form-control ";
newInput2.placeholder="Ingredient";
newInput2.name="ingredient"+instance;
var newDiv2=document.createElement("div");
newDiv2.className="col-md-3 marginBottom10";
newDiv2.appendChild(newInput2);
DivAllPrime.appendChild(newLabel1);
DivAllPrime.appendChild(newDiv2);
var newInput4=document.createElement("input");
newInput4.className="form-control ";
newInput4.name="totalunit"+instance;
newInput4.placeholder="Unit";
newInput4.type="text";
var newDiv3=document.createElement("div");
newDiv3.className="col-md-2 marginBottom10";
newDiv3.appendChild(newInput4);
DivAllPrime.appendChild(newDiv3);
var newInput5=document.createElement("select");
newInput5.id="unit"+instance;
newInput5.name="unit"+instance;
newInput5.className="form-control ";
var newDiv4=document.createElement("div");
newDiv4.className="col-md-2 marginBottom10";
var newInput6=document.createElement("option");
newInput6.value="gram";
newInput6.innerHTML="Gram";
newInput6.selected=true;
newInput5.appendChild(newInput6);
var newInput7=document.createElement("option");
newInput7.value="ml";
newInput7.innerHTML="ML";
newInput5.appendChild(newInput7);
newDiv4.appendChild(newInput5);
DivAllPrime.appendChild(newDiv4);
return false;
}
</script>
This line sets the name of the new input dynamically:
newInput4.name="totalunit"+instance;
How can I get the name and send it to the servlet?

Categories

Resources