Kendo MVC call javascript from a template - model-view-controller

I have a telerik mvc grid (NOT JAVASCRIPT) with groupable() turned on. The column i am grouping by has a link in it. No big deal since that's easy on a column template. However, header templates don't allow access to data from a column different that the one the grouping is set on, and our links are all based on the "ID" column (hidden) whereas the grouping is on the "Name" column.
Can I call javascript from the header template to get the data I need?
here is an example of what has worked
.Groupable()
.Selectable()
.Columns(columns =>
{
columns.Template(#<text></text>).ClientTemplate("#= rowCommandsUndelete(data, false, true) #").Title(" ").Width(100);
columns.Bound(m => m.Active)
.Title("Active?")
.ClientTemplate("#= ActiveState(data.Active) #")
.Width(85);
columns.Bound(m => m.Origin.Name)
.ClientGroupHeaderTemplate("<a href='www.google.com'>link </a>")
.ClientTemplate("<div id='#=data.ID#'></div><a href='/Origins?id=#=data.Origin.ID#'>#=data.Origin.Name#</a>") //Empty div with "data.ID" is required (see JavaScript section below)
.Width(300);
and this doesn't work and gives an error: Uncaught TypeError: Cannot read property 'ID' of undefined
columns.Bound(m => m.Origin.Name)
.ClientGroupHeaderTemplate("<a href='www.google.com'> #=data.Origin.ID#</a>")

the final answer is thanks to sandro. On an ajax page, use clientgroupheadertemplate like this on a column:
columns.Bound(m => m.Origin.Name)
.ClientGroupHeaderTemplate("#=buildHeader( value )#")
buildheader is a javascript function, and value is a built-in value in the header. Here's the javascript function:
function buildHeader(value) {
return "<h4><u><a href='\origins?OriginName=" + encodeURIComponent(value) + "'>" + value + "</a></u></h4>";
}
value contained the string from the column and i was able to create a link this way and set it to the column header. I have also successfully called javascript now from a footer to trigger something after a calculation.

It's groupHeaderTemplate configuration.
Example:
$("#grid").kendoGrid({
columns: [
{ field: "name" },
{ field: "link",
groupHeaderTemplate: "<a href=#=value# target='_blank'>google.com</a>"
}
],
dataSource: {
data: [
{ name: "Jane Doe", link: "https://google.com" },
{ name: "John Doe", link: "https://google.com" }
],
group: { field: "link" }
}
});

Related

Cypress how to stored input data and parse for verification

I have a table form at webpage. User filled up and hit upload then result firm is displayed.
Table a input abc
Table b input 123
I want to verify the data is displayed at result page.
How do i store the value abc 123 for verification? To avoid linear coding, i do not want to rewrite those values again and to prevent if test data changed, i just need to change once.
To test the tables/forms, iterate the expected results.
it('tests form', () => {
const expected = [
[ 'a', 'abc' ],
[ 'b', '123' ],
]
expected.forEach(exp => {
cy.get(`table#${exp[0]}`) // construct selector
.find('input')
.invoke('val')
.should('eq', exp[1]) // verify
})
})
You can create a json file and save it under fixtures like data.json:
{
"tableA": {
"name": "table a",
"selector": "input"
"value": "abc",
"checkbox": "be.checked"
},
"tableB": {
"name": "table b",
"selector": "input"
"value": 123,
"checkbox": "not.be.checked"
}
}
And in your tests you can write:
describe('Some page', () => {
beforeEach(function() {
// "this" points at the test context object
cy.fixture('data.json').then((data) => {
this.data = data
})
})
it('has user', function() {
expect(this.data.tableA.name).to.equal('table a')
expect(this.data.tableA.selector).to.equal('input')
expect(this.data.tableA.value).to.equal('abc')
cy.get('selector').should(this.data.tableA.checkbox)
})
})
Important Note:
If you store and access the fixture data using this test context
object, make sure to use function () { ... } callbacks. Otherwise the
test engine will NOT have this pointing at the test context.

Add/modify text between parentheses

I'm trying to make a classified text, and I'm having problem turning
(class1 (subclass1) (subclass2 item1 item2))
To
(class1 (subclass1 item1) (subclass2 item1 item2))
I have no idea to turn text above to below one, without caching subclass1 in memory. I'm using Perl on Linux, so any solution using shell script or Perl is welcome.
Edit: I've tried using grep, saving whole subclass1 in a variable, then modify and exporting it to the list; but the list may get larger and that way will use a lot of memory.
I have no idea to turn text above to below one
The general approach:
Parse the text.
You appear to have lists of space-separated lists and atoms. If so, the result could look like the following:
{
type => 'list',
value => [
{
type => 'atom',
value => 'class1',
},
{
type => 'list',
value => [
{
type => 'atom',
value => 'subclass1',
},
]
},
{
type => 'list',
value => [
{
type => 'atom',
value => 'subclass2',
},
{
type => 'atom',
value => 'item1',
},
{
type => 'atom',
value => 'item2',
},
],
}
],
}
It's possible that something far simpler could be generated, but you were light on details about the format.
Extract the necessary information from the tree.
You were light on details about the data format, but it could be as simple as the following if the above data structure was created by the parser:
my $item = $tree->{value}[2]{value}[1]{value};
Perform the required modifications.
You were light on details about the data format, but it could be as simple as the following if the above data structure was created by the parser:
my $new_atom = { type => 'atom', value => $item };
push #{ $tree->{value}[1]{value} }, $new_atom;
Serialize the data structure.
For the above data structure, you could use the following:
sub serialize {
my ($node) = #_;
return $node->{type} eq 'list'
? "(".join(" ", map { serialize($_) } #{ $node->{value} }).")"
: $node->{value};
}
Other approaches could be available depending on the specifics.

Chartkick w/ Highcharts column_chart, specify visibility by series

On Highcharts it is possible to hide by default some selected series :
new Highcharts.Chart({
"chart": {"type":"column","renderTo":"chart-1"},
"categories":["10-2017","11-2017"],
"series": [
{"name":"Metric 1","data":[653.13,683.13]},
{"name":"Metric 2","data":[6.87,6.87], "visible": false}
]})
However, I'm using Chartkick Ruby gem, and I cannot generate the code above.
<%= column_chart([
{ name:"Metric 1", data: { "10-2017" => 653.13, "11-2017" => 683.13 } },
{ name:"Metric 2", data: { "10-2017" => 6.87, "11-2017" => 6.87 }, visible: false }
]) %>
With this erb code snippet, the visible: false option is ignored.
Is there a way (maybe using the library parameter) to acheive this goal?
I agree, it is probably a bug or an unimplemented issue with ChartKick.
I fixed it by manually running this JS code after initialization of column_chart:
var chart = Chartkick.charts["chart-1"].getChartObject();
chart.series[1].setVisible(false);
Verify if chart-1 is the correct ID of your chart.

Kendo column filtering icon shows additional dot in IE

I got this small but strange error while implementing kendo column filters. My filtering icon has an additional dot in IE. In all other browsers everything looks fine. I don't know how to delete or at least hide this small additional dot.
Here is the screenshot from IE:
and here is how it should look like:
I used a regular kendo filtering implementation, example of the code is below:
var MyGrid = function($div) {
var base = $div.data('baseurl');
var columns = [
{ field: 'userName', title: 'User Name'},
{ field: 'age', type:'number', title: 'Age' }];
grid($div, columns, {
datasource: datasource(base + '/double', ViewBackbone.options()),
options: {
filterable : {
extra: false,
operators: {
string: {
contains: "Contains",
startswith: "Starts with",
eq: "Equals"
},
number: {
eq: "Is equal",
gt: "Greater than",
lt: "Less than"
}
},
messages: {
info: "Choose an option",
filter:"Filter",
clear: "Clear"
}
},
}
});
};
The problem was solved by fixing the width property to the columns header. So in your css you have to specify the width to be more than 100%. I set up mine to be 115% and the dot disapeered.

The merge tags in mandrill don't work in codeigniter

I use Mandrill plugin for Codeigniter.
I created HTML template through Mandrill account, named fess1 with merge tag FNAME, after I published it.
Example:
...
<p>
<span>Hi *|FNAME|*,<br></span>
</p>
....
Now I try to send mail from codeigniter like:
private function sendMailMandrill($owner_name,$business_name,$owner_email){
$message = array('dest_mail' => $owner_email);
$message['to'] = array(array('email' => 'mim#wefi.com'));
$mergeVars[] = array(
'rcpt' => array(array('email' => 'mim#wefi.com')),
'vars' => array(
array(
'name' => 'FNAME',
'content' => 'Fessy'
)
)
);
$message['merge'] = true;
$template_name = 'fess1';
$template_content = array( // I don't know what I need to provide here, left it empty
array(
'name' => 'example name',
'content' => 'example content'
)
);
$message['merge_vars'] = $mergeVars;
return $this->mandrill->messages_send_template($template_name, $template_content, $message);
}
The result:
I get the mail, based on fess1 template, but with the tag *|FNAME|*.
Sounds like Mandrill didn't recognize the merge tag.
I used mandrill->messages_send_template but since my template stored into Mandrill account I have no clue what I need to provide for $template_content.
So I wrote dummy info there.
Did I miss something?
Thank you,
[EDIT]
From logs this is what I send:
{
"template_name": "fess1",
"template_content": [
{
"name": "example name",
"content": "example content"
}
],
"message": {
"owner_name": "עידו",
"business_name": "פלאפל מוסקו",
"dest_mail": "maxim#wifi.com",
"to": [
{
"email": "maxim#wifi.com"
}
],
"merge": "true",
"merge_vars": [
{
"rcpt": [
{
"email": "maxim#wifi.com"
}
],
"vars": [
{
"name": "FNAME",
"content": "Fessy"
}
]
}
]
},
"key": "xxxxxxxxxxxxxxxx"
}
You can provide blank information for the template_content parameter. That parameter allows you to use mc:edit regions in your template. It is a required parameter, but a blank array will suffice if all of the content is in your template in Mandrill.
As for whether the merge_vars were recognized, the first thing we recommend is inspecting the API Logs for your account (Settings > API Logs) since that will show you the JSON that Mandrill received. You can then compare that to the expected JSON format from the Mandrill API docs: https://mandrillapp.com/api/docs/messages.JSON.html#method=send-template
It looks like your arrays may not be nested as expected. Once you view the JSON that's being generated as compared with the expected format, you can also view the PHP documentation for the Mandrill PHP client. It may not be identical to the CodeIgniter plugin, but should give you an idea of how the merge_vars parameter would be structured in PHP: https://mandrillapp.com/api/docs/messages.php.html
In mergeVars you created array instead key:value. Change it to:
'rcpt' => 'mim#wefi.com',

Resources