Dynamic style on RML documents - odoo

What I need is to have every second row of a table to have a different background colour. I have successfully created my method that can be called from the rml document and returns the hex colour. What I need is a way on rml side to set the background-colour attribute of the tr tag to the return value of my method. How can this be done ? I have been using the official documentation and looking specifically at the chapter 11 Conditional formatting but I do not see anything. Essentially what I want to do it the following:
<tr style="background-colour: [[_get_colour(index)]];" />
_get_colour will return a string that will contain the hex value of a colour
Edit: As it turns out the docIf RML tags that are used for conditional formatting are not implemented in openerp v7 according to this and I have to resort to a different solution.

Can't test this at the moment, but here's an idea that might work:
Make two <tr> for each iteration (1 for each style). In one of them, check if the index is even or removeParentNode('tr'), in the other, check if the index is odd or removeParentNode('tr'). This way only one or the other table row will display on each iteration, but not both.
Example (untested):
<tr style="style1">[[ (index%2 == 0 and display.content) or removeParentNode('tr')]]</tr>
<tr style="style2">[[ (index%2 != 0 and display.content) or removeParentNode('tr')]]</tr>

I found an example of that problem being solved in an rml in the system. I ended up resolving the issue with the following:
<tr>[[ setTag('tr','tr',{'style': 'Move_Line_Contect_Assign_State_background' if picking.move_lines.index(move_lines) % 2 else 'Move_Line_Contect_Assign_State'}) ]]

Related

Vue.js get element by id/ref

I have a custom component called 'menu-entry':
<menu-entry v-for="field in fields" :id:"field.id" :ref="field.id" v-bind:key="field.id" v-bind:class="[classArray]" v-bind:field="field" v-on:clicked="menuEntryClicked">
</menu-entry>
I need to get one of them (for example field.id = 2) and remove an item from the classArray.
this.$refs[2] is working for HTML elements, but not for custom elements.
this.$el.querySelector isnt working either.
is there another way to remove an item from the classArray of a specific element?
Your question it is not clear but you are trying to set id and ref to field.id so following this logic it is not necessary to do though.
You can just send the id to the method you are executing like below:
<menu-entry
v-for="field in fields"
v-bind:key="field.id"
v-bind:class="[classArray]"
v-bind:field="field"
v-on:clicked="menuEntryClicked(field.id)" // <= send the id here
>
</menu-entry>
I am not sure if i helped but regarding your question, now you can figoure out which id of element is clicked and remove it from classArray or whatever you want
2 is not a valid id selector when you use document.querySelector('#2'); maybe you can use document.getElementById('2') instead - it can work.

How do I pre-select rows in a DataTable based on the value in a column?

Situation:
I have a pandas dataframe which I convert into an html table via df.to_html(). I then add the DataTables class to the table. This DataTables-table has the following columns:
ID | X | Y | Val |...More columns...| Selection_Criteria |...More columns...
The values in Selection_Criteria can be either 1 or 0. I know that with:
$('#ProductList').DataTable( {
...
"fnInitComplete": function(oSettings, json) { $('#ProductList tbody tr:eq(0)').click(); }
});
(Source: http://code.datatables.net/forums/discussion/38171/automatic-select-of-the-first-row-on-reload)
..it is theoretically possible to select the first row. (In reality, I have not been able to simulate a click for the first row.)
But my question goes more towards: How do I automatically pre-select ALL rows where the value is 1 in Selection_Criteria? What is the best approach? Should this be done client/server side?
In pandas the term "select"(ing) means to screen out that which was not selected for. I know that in a table on a web page, selected can mean being highlighted to stand out from the others. There are a couple of ways you can do this on the server side. You could display two tables, one for each state of Selection_Criteria. This would save you the hassle of trying to select individual rows out of a table in the first place (which would be done with Javascript, not Pandas). While pandas has the ability to add a class to the resulting html, the class is applied to the element.
If you are using jquery you are going to use these pieces. as you haven't put example data I can't be exact.
replace x in the next line with the number of columns the Selection_Criteria=1 is across the table
$( "tr td:nth-child(x):contains('1')" ).addClass('selected');
There are solutions on the backend using beautifulsoup and css selectors, or lxml.etree with xpath selectors. But jquery is going to be the most concise with this problem.
#Aliester. Thank you for the pointer!
This helped me find the solution to my own question. What I did:
1.) Identify row index that I want to select when the table loads.
2.) Pass the index to js.
3.) Loop over the indices and apply the following command to each index entry:
table.row(':eq('+hit_index_row+')').select();
So I am using the API to select each individual row. This works for me and hopefully could be helpful to others as well. It may be a bit hacky, so more elegant suggestions are welcome!
You can do this by providing a function for the "rowCallback" option when initializing the DataTable. https://datatables.net/reference/option/rowCallback
Also it is generally better to use the API methods to select rows instead of just changing the class. I found that the DataTable + Select libraries keep an internal collection of selected row indexes (just current page if serverside processing is on) instead of using the class to resolve selected items.
So while the display will look right, if you just change the class, if you rely on any of the API methods to get selected items later on there will be issues. Additionally just changing the class on the row will not fire any of the "select" events on the table so you can't rely on those either.

Xpages djCurrencyTextBox with fractional=false

Since clean 8.5.3 Domino has problem with localized numbers with space as thousand separators, I decided to switch to djCurrencyTextBox. But as don't want to display fractional part, I'm struggling with it too. Even on 9.0.1 test server.
If I create simple field using:
<xe:djCurrencyTextBox id="djCurrencyTextBox1" value="#{document1.currency}">
<xe:this.constraints>
<xe:djNumberConstraints fractional="false">
</xe:djNumberConstraints>
</xe:this.constraints>
</xe:djCurrencyTextBox>
It does not recognize any number entered. ( I get message that value is not valid even when I enter just 1)
When add it as dojo attribute directly, it works as expected
<xe:djCurrencyTextBox id = "djCurrencyTextBox1"
value ="#{document1.currency}" >
<xe:this.dojoAttributes>
<xp:dojoAttribute name ="data-dojo-props"
value ="constraints:{fractional:false}" >
</xp:dojoAttribute>
</xe:this.dojoAttributes>
</xe:djCurrencyTextBox >
Any ideas what can cause the issue?
This is a known issue that is not fixed in 9.0.1
Using the first example above, no matter what value you set on the fractional constraint (enable/disable/auto/true/false), the textbox only ever accepts a value with fractional part included (e.g. 567.89), which is incorrect for disable & false values. The second example works as expected with fractional set to true or false.
This is because, looking at the page source, the html output for the first example is:
<input dojoType="dijit.form.CurrencyTextBox" constraints="{"fractional":"false"}" id="view:_id1:djCurrencyTextBox1" name="view:_id1:djCurrencyTextBox1">
The """ parts should not be included in the constraints.
Whereas with the 2nd example, there is no such issue:
<input dojoType="dijit.form.CurrencyTextBox" data-dojo-props="constraints:{fractional:false}" id="view:_id1:djCurrencyTextBox2" name="view:_id1:djCurrencyTextBox2">
As this has not yet been fixed in 9.0.1, all you can do is utilise the workaround that you have posted for the time being.
UPDATE: The fix for this issue is in Release 9 of the v901 XPages Extension Library on OpenNTF

Confluence-how to add auto incrementing column to a table

I would like to have a template with a table which has first column with auto incremented number. When you hit tab in the last cell in the last row a new row is created (as it is now in Confluence's tables) and in first column number is incremented automatically.
I was looking for some macros (but I don't want to buy anything) and found only this one: https://marketplace.atlassian.com/plugins/org.swift.confluence.tablesorter which can't be used as a separate one without buying other plugins.
I was thinking about making my own macro and I would be grateful for pointing me direction where to start (I read confluence guide about macros). Do I need to use Velocity for that?
We have Confluence 4.3.6 installed
I haven't worked with velocity for a while and don't have a project around to test, but i think this should work for you:
#set($rowNumber = 0)
<table>
#foreach( $product in $allProducts )
<tr>
<td>$rowNumber</td>
<!-- your stuff goes here -->
<tr>
#set($rowNumber = $rowNumber +1)
#end
</table>

Selenium RC Having problems with XPath for a table

I'm trying to select an element given by:
/html/body[#id='someid']/form[#id='formid']/div[#id='someid2']/div[#id='']/div[#id='']/div[#id='']/table/tbody[#id='tableid']/tr[7]/td[2]
Now the html of that row I'm trying to select looks like this:
<tr>
<td class="someClass">some text</td>
<td class="someClass2">my required text for verifying</td>
</tr>
I need to check whether my required text for verifying exists in the page.
I used selenium.isTextPresent("my required text for verifying"); and it doesnt work
So now I tried with selenium.isElementPresent("//td[contains(text(),'my required text for verifying')]")
This works sometimes but occassionally gives random failures.
Tried with selenium.isElementPresent(//*[contains(text(),'my required text for verifying')]) too..
How do I verify this text on the page using selenium?
The problem is not with the page taking time to load. I took screenshots before the failure occurs and found that the page was fully loaded so that shouldnt be the problem.
Could someone please suggest any way to select this element or any way to validate this text on the screen?
Try locating it by CSS:
assertText(selenium.getText("css=.someClass2"), "my required text for verifying");
The above should give a better failure message than isElementPresent, but you can still use that with CSS locators:
assertTrue(selenium.isElementPresent("css=.someClass2"));
If there is an issue with the load times you could try waiting for the element to be present:
selenium.waitForCondition("var value = selenium.isElementPresent('css=.someClass2'); value == true", "60000");
Some other XPath locators that might work for you, if you prefer not to use CSS locators:
//td[contains(#class, 'someClass2')
xpath=id('tableid')/tr[7]/td[2]
xpath=id('tableid')/descendant::td[contains(#class, 'someClass2')][7]
I've never heard of selenium; but your initial XPath is unnecessarily fragile and verbose.
If an element has an id, it's unique; using such a long XPath just to select a particular element is unnecessary; just select the last element with the id. Further, I see that you're occasionally selecting xyz[#id=''] - if you're trying to select elements without id attributes, you can do `xyz[not(#id)] instead.
Assuming your initial XPath is basically correct, it would suffice to do something like this:
//tbody[#id='tableid']/tr[7]/td[2]
However, using a specific row and column number like that is asking for trouble if ever anyhow changes details of the html. Also, it's atypical to have id's on tbody elements, perhaps the table element has the id?
Finally, you may be running into space-normalization issues. In xml, multiple consecutive spaces are often considered equivalent to a single space, and you're not accounting for that. In particular, if the xhtml is pretty-printed and contains a line-break in the middle of your sought-after text, it won't work.
//td[contains(normalize-space(text()),'my required text for verifying')]
Finally, text() explicitly selects
child text nodes - so the above xpath won't select elements where the text isn't the immediate child of td (e.g. <td><b>my required text for verifying</b></td>) won't match. Perhaps you mean to look up the concatenated text vale of all descendents:
//td[contains(normalize-space(string(.)),'my required text for verifying')]
Finally, type conversion can be implicit in XPath, so string(.) can be replaced by . in the above, leading to the version:
//td[contains(normalize-space(.),'my required text for verifying')]
This may be slow on large documents since it needs to normalize the spaces and perform a string search for each td element. If you run into perf problems, try to be more specific about which td elements need to be inspected, or, if you don't care where the text occurs, try to reduce the number of "calls" to normalize-space by normalizing the entire doc in one go (e.g. via /*[contains(normalize-space(.),'my required text for verifying')]).