How to use custom CSS in an Odoo 10 POS addon - css

My custom CSS isn't being loaded when I launch the POS app, but it's loaded into web.assets_backend.1.css in the dashboard. My custom Javascript is being loaded correctly. Is this the correct way to load the CSS? Thanks for your help.
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<template id="assets_backend" inherit_id="web.assets_backend" name="donation_assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/donation/static/src/css/donation.css" />
<script type="text/javascript" src="/donation/static/src/js/donation.js"></script>
<script type="text/javascript" src="/donation/static/src/js/jquery.sglide.js"></script>
<script type="text/javascript" src="/donation/static/src/js/sGlide.js"></script>
<script type="text/javascript" src="/donation/static/src/js/donation_frontend.js"></script>
</xpath>
</template>
</data>
</odoo>

My Javascript and CSS are now being added to the point_of_sale.assets files. It turns out that my QWeb template file in static/src/xml/ had errors which caused some of the Odoo app files to not be found. It might also be the reason why Odoo didn't update web.assets_backend.js and the point_of_sale.assets js and css files.
Here's my updated XML assets file:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets" inherit_id="point_of_sale.assets" name="donation assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/donation/static/lib/jquery.sglide.js"></script>
<script type="text/javascript" src="/donation/static/lib/sGlide.js"></script>
<script type="text/javascript" src="/donation/static/src/js/donation.js"></script>
</xpath>
<xpath expr="//link[#id='pos-stylesheet']" position="after">
<link rel="stylesheet" href="/donation/static/src/css/donation.css" />
</xpath>
</template>
</odoo>

Not sure, but did you add the point_of_sale module in the dependencies of your donation module?
If not add "depends" : ["point_of_sale"], to the dict in your _openerp_.py. Add more dependencies if needed.
Now the point_of_sale module and it's assets gets loaded first.
Edit: Try inherit_id="point_of_sale.assets" instead of inherit_id="web.assets_backend". That could do it for you.

You need to update the path of css file in three places.
1.inherit_id="web.assets_backend"
2.inherit_id="web.assets_frontend"
3.inherit_id="point_of_sale.assets"
In the templates which inherites the above templates.
The code is shown below.
<template id="assets_backend" name="sub_menu assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/pos_update/static/src/css/mypos.css"/>
</xpath>
</template>
<template id="assets_frontend" name="sub_menu assets front" inherit_id="web.assets_frontend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/pos_update/static/src/css/mypos.css"/>
</xpath>
</template>
<data>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/pos_update/static/src/css/mypos.css"/>
<script type="text/javascript" src="/pos_update/static/src/js/cancel.js"></script>
</xpath>
</template>
</data>
You also need to ensure that if you want to modify an existing template then the stylesheet name must not be changed.
If you want to create a stylesheet for your template the you only need to set the path of stylesheet in only one place, ie in the main template file in which you are setting the path of js file.
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/pos_update/static/src/css/mypos.css"/>
<script type="text/javascript" src="/pos_update/static/src/js/cancel.js"></script>
</xpath>
</template>

Related

Insert Javascript files into odoo without replacing others

I try to build an odoo module with a recent fullcalendar version.
My module works as design with this import:
<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
<data>
<template id="schedule_tpl" name="web_schedule assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/web_schedule/static/src/css/web_fullcalendar.css"/>
<link rel="stylesheet" href="/web_schedule/static/lib/fullcalendar/css/fullcalendar.min.css"/>
<link rel="stylesheet" href="/web_schedule/static/src/css/scheduler.min.css"/>
<script type="text/javascript" src="/web_schedule/static/src/js/moment.min.js"></script>
<script type="text/javascript" src="/web_schedule/static/lib/fullcalendar/js/fullcalendar.min.js"></script>
<script type="text/javascript" src="/web_schedule/static/src/js/scheduler.min.js"></script>
<script type="text/javascript" src="/web_schedule/static/lib/fullcalendar/js/fr.js"></script>
<script type="text/javascript" src="/web_schedule/static/src/js/web_schedule.js"></script>
</xpath>
</template>
</data>
</openerp>
Problem, the calendar avalaible in messaging does not work anymore, I have issues with date format and so on. If i uninstall my custom module, this calendar works fine.
So, how i can import fullcalendar files to be used only in my module ?
thanks

Import css and js to spring mvc jsp page

I have added following configurations, but it wont apply the css and js. Is there anythy i need to add other than these
Config.xml
<mvc:resources mapping="/resources/**" location="/resources/" />
jspfile
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:url value="/resources/css/metro.css" var="metro" />
<spring:url value="/resources/css/metro-schemes.css" var="metroschemes" />
<spring:url value="/resources/css/metro-icons.css" var="metroicons" />
<link href="${metro}" rel="stylesheet">
<link href="${metroschemes}" rel="stylesheet">
<link href="${metroicons}" rel="stylesheet">
<script src="${jquery}"></script>

How to add the css files in a separate html file in spring using tiles

I wanted to create the seperate css files and wanted to use it, Instead of duplicating the css file again.
Using this method i can reuse the cssfilecommon.html by calling it and also if i want some other css required i can add it in the seperate page and call only for that page
<tiles:insertAttribute name="cssfilecommon" /> - common css file
<tiles:insertAttribute name="pagespecific" /> - some other css file
--
can we do this, please let me know if any one tried..
layout file
<!DOCTYPE html>
<html xmlns:tiles="http://www.thymeleaf.org">
<head>
**<tiles:insertAttribute name="cssfile" />**
</head>
<body>
<div tiles:include="header">Header Block</div>
<div tiles:substituteby="body">Body Block</div>
<div tiles:substituteby="footer">Footer Block</div>
</body>
</html>
titles-def.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://struts.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="home" template="basiclayout/layout" >
<put-attribute name="cssfilecommon" value="bout/cssfilecommon"/>
<put-attribute name="header" value="bout/header"/>
<put-attribute name="menu" value="bout/Menu"/>
<put-attribute name="footer" value="bout/footer"/>
</definition>
--
cssfilecommon.html
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link href="css/jquery-ui-1.10.3.custom.css" th:href="#{css/jquery-ui-1.10.3.custom.css}" rel="stylesheet" type="text/css" />
<link href="css/ui.jqgrid.css" th:href="#{css/ui.jsd.css}" rel="stylesheet" type="text/css"/>
Yes, with plain tiles you could do this:
Layout file:
<head>
<tiles:insertAttribute name="cssfilecommon" />
<tiles:insertAttribute name="pagespecific" ignore="true" />
</head>
titles-def.xml file:
<definition name="home" template="basiclayout/layout" >
<put-attribute name="cssfilecommon" value="bout/cssfilecommon"/>
<put-attribute name="pagespecific" value="bout/pagespecific"/>
...
</definition>
Note the usage of ignore attribute:
If this attribute is set to true, and the attribute specified by the
name does not exist, simply return without writing anything. The
default value is false, which will cause a runtime exception to be
thrown.
But, as I see you are using Thymeleaf, which probably doesn't support it yet: #17
A other smart suggestion, you can declare in your tiles-def.xml an list and in this list you can simple push all your css files you need in your site, just like this:
<put-list-attribute name="jsList" cascade="true">
<add-attribute value="/Project/basic/css/basic.css" />
<add-attribute value="/Project/case2/css/example2.js" />
<add-attribute value="/Project/special/css/example3.css" />
</put-list-attribute>
after this in your jsp file you can easily iterate over your list with the following (You need the jstl taglib):
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
...
<tiles:importAttribute name="cssList"/>
...
<c:forEach items="${cssList}" var="cs">
<link href="${cs}" rel="stylesheet" type="text/css" media="screen">
</c:forEach>
i know it's like the same what #Slava Semushin say but i would that you know you can work with lists.
For example if you work with jqxwidgets you need to bind special javascripts for the elements and if you don't need all the javascript for each site, you can handle this case, with this suggestion.

extjs4 files cannot been loaded

I'm using extjs4 and spring mvc (Java EE).
when I run project I can't see anything on browser.
I add this code on my servlet dispatcher:
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
And when I run it this is the error shown:
28 avr. 2013 21:15:30 org.springframework.web.servlet.DispatcherServlet noHandlerFound
ATTENTION: No mapping found for HTTP request with URI [/CR/application/view/Viewport.js]
in DispatcherServlet with name 'mvc-dispatcher'
28 avr. 2013 21:15:30 org.springframework.web.servlet.DispatcherServlet noHandlerFound
ATTENTION: No mapping found for HTTP request with URI [/CR/Ext4Example/view/login/LoginForm.js]
in DispatcherServlet with name 'mvc-dispatcher'
Ext4Example is the name of my extjs application
and this is my app.js
Ext.Loader.setConfig({enabled: true});
Ext.application({
name: 'Ext4Example',
appFolder: 'application',
controllers: [
'Login'
],
autoCreateViewport: true
});
and this my index.jsp page
<!DOCTYPE html>
<html >
<head>
<!-- Ext JS Files -->
<link rel="stylesheet" href="./resources/ext-4.0/resources/css/ext-all.css"/>
<link rel="stylesheet" href="./resources//css/main.css"/>
<script src="./resources/ext-4.0/ext-all.js"></script>
<!-- App Files -->
<script type="text/javascript" src="./resources/application/app.js"></script>
<script type="text/javascript" src="./resources/application/view/Viewport.js"></script>
<script type="text/javascript" src="./resources/application/view/login/CenterPanel.js"></script>
<script type="text/javascript" src="./resources/application/view/login/create-rd.js"></script>
<script type="text/javascript" src="./resources/application/view/login/HomePage.js"></script>
<script type="text/javascript" src="./resources/application/view/login/LoginForm.js"></script>
<script type="text/javascript" src="./resources/application/view/login/WestMenu.js"></script>
<script type="text/javascript" src="./resources/application/controller/Login.js"></script>
<script type="text/javascript" src="./resources/application/model/Login.js"></script>
<script type="text/javascript" src="./resources/application/store/Login.js"></script>
</head>
<body background="./resources/images/gray.jpg">
</body>
</html>
Can any one explain the error to me?
When I click Ctrl+U and I click on the files URL I can see the code source.
And what if you use the spring tag? Something like that :
<spring:url value="/resources/application/view/Viewport.js" var="some_url"/>
<script type="text/javascript" src="${some_url}"></script>

Codeigniter CSS and Javascript files usage

I am writing a webpage with CI.I use the latest version. I need to learn how to imply CSS and Javascript files. I use nivoslider , jquery and many css files. I use application directory as
+application
+views
+pages
-home.php
+templates
-header.php
-footer.php
+system
+user_guide.
Can you explain how to enable js and Css files. I made a research but my mind is blown away with the versions of codeigniter.
this is my header.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN
""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Kırmızı Eğitim Merkezi</title>
<meta name="description" content="Empire - XHTML Template" />
<!-- CSS -->
<link href='./fonts/sansation.css' rel="stylesheet" type="text/css" />
<!-- Get any font from here easily: http://www.google.com/webfonts -->
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<link href="./fancybox/jquery.fancybox-1.3.4.css" rel="stylesheet"
type="text/css" />
<link href="./css/nivo-slider.css" rel="stylesheet" type="text/css" />
<!-- UPDATE BROWSER WARNING IF IE 7 OR LOWER -->
<!--[if lt IE 8]><link href="css/stop_ie.css" rel="stylesheet"
type="text/css" /><![endif]--><!-- JAVASCRIPTS -->
<script type="text/javascript" src="./js/jquery.min.js">
</script><script type="text/javascript"
src="./js/jquery-ui-1.8.17.custom.min.js">
</script><script type="text/javascript"
src="./fancybox/jquery.fancybox-1.3.4.pack.js">
</script><script type="text/javascript" src="./js/jquery.nivo.slider.js">
</script><script type="text/javascript" src="./js/jquery.bgslider.js">
</script><script type="text/javascript" src="./js/preloader.js">
</script><script type="text/javascript" src="./js/farbtastic.js">
</script><script type="text/javascript" src="./js/basic.js">
</script>
Can you advice me a way to use them ?
First, you need to place JS and CSS files somewhere like:
+ assets
+ js
+ css
Then you need to call them:
<link href='<?php echo base_url(); ?>assets/css/cssfile.css' rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery.min.js">

Resources