Nested If Else Kendo UI - kendo-ui

I am writting Nested If else as follows:
What wrong with the code:
#if(item.ATTACHMENTS == 'Aftermarket'){#
#if(item.IS_ATT_AM_UPDATED == 'Y'){#
<img id="AftermarketBlueCircle" src="#Url.Content("~/Content/Images/BlueCircle.png")" />
#}
else{#
<img id="AftermarketHalfCircle" src="#Url.Content("~/Content/Images/HalfBlueCircle.jpg")" /> +
#}#
else{#
#if(item.IS_ATT_TS_UPDATED == 'Y'){#
<img id="AftermarketBlueCircle" src="#Url.Content("~/Content/Images/BlueCircle.png")" />
#}
else{#
<img id="AftermarketHalfCircle" src="#Url.Content("~/Content/Images/HalfBlueCircle.jpg")" /> +
#}#
#}#
Please suggest
Thanks in Advance !!!

#if(item.ATTACHMENTS == 'Aftermarket'){#
#if(item.IS_ATT_AM_UPDATED == 'Y'){#
<img id="AftermarketBlueCircle" src="#Url.Content("~/Content/Images/BlueCircle.png")" />
#}
else{#
<img id="AftermarketHalfCircle" src="#Url.Content("~/Content/Images/HalfBlueCircle.jpg")" />
#}#
#}
else{#
#if(item.IS_ATT_TS_UPDATED == 'Y'){#
<img id="AftermarketBlueCircle" src="#Url.Content("~/Content/Images/BlueCircle.png")" />
#}
else{#
<img id="AftermarketHalfCircle" src="#Url.Content("~/Content/Images/HalfBlueCircle.jpg")" />
#}#
#}#

Related

Image not found on <img src={{ asset(...) }}

This is my blade Looks like :
<img src="{{ asset('/assets/img/logo.png') }}" alt="logo" width="60px" height="60px">
And here's my folder structure
When i try to view the blade, its fine. But when i try to Export as PDF with Laravel-Excel, the error coming up
http://localhost:8000/assets/img/logo.png not found!
I already change asset() to url() and without laravel function but the error still coming, any suggestions?
Try this
{{ asset('assets/img/logo.png') }}
without the initial "/"
https://laravel.com/docs/8.x/helpers#method-asset
Have you try this
<img src="/assets/img/logo.png" alt="logo" width="60px" height="60px" />
OR
<img src="{{URL::asset('/assets/img/logo.png')}}" alt="logo" width="60px" height="60px" />
Please try these!
Solved
<img src="{{ public_path('assets/img/logo.png') }}" ... />

How to insert data to the database using Django and AJAX?

I have a simple webpage that allows the user to enter data using form.
I am using Django with Ajax in order to enter the new records into the database.
The problem is that once the user choose the webpage the system display the below error:
MultiValueDictKeyError at /addperson/ 'na'
Request Method: GET
Request URL: http://127.0.0.1:8000/addperson/
Django Version: 2.1.3
Exception Type: MultiValueDictKeyError
Exception Value: 'na'
Exception Location: C:\Users\LT GM\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\datastructures.py in getitem, line 79
Python Executable: C:\Users\LT GM\AppData\Local\Programs\Python\Python37\python.exe
Python Version: 3.7.1
Python Path: ['C:\Users\LT ' 'GM\Downloads\Django-Related-DropDowns-master\Django-Related-DropDowns-master', 'C:\Users\LT GM\AppData\Local\Programs\Python\Python37\python37.zip', 'C:\Users\LT GM\AppData\Local\Programs\Python\Python37\DLLs', 'C:\Users\LT GM\AppData\Local\Programs\Python\Python37\lib', 'C:\Users\LT GM\AppData\Local\Programs\Python\Python37', 'C:\Users\LT ' 'GM\AppData\Local\Programs\Python\Python37\lib\site-packages']
Server time: Mon, 4 Mar 2019 07:10:33 +0000
models.py
class Person(models.Model):
boolChoice = (
("Male","M"),("Female","F")
)
name = models.CharField(max_length=50)
date = models.DateTimeField()
description = models.TextField()
gender = models.BooleanField(choices= boolChoice)
def __str__(self):
return str(self.name)
urls.py
from django.urls import path, include
from django.contrib import admin
from map import views as mapviews
admin.autodiscover()
urlpatterns = [
path('admin/', admin.site.urls),
path('', mapviews.index),
path('addperson/',mapviews.addperson),
]
addperson.html
{% extends 'base.html' %} {% block content %}
<div class="hero__content">
<form method="POST" class="form-style-9">
{% csrf_token %} {{ form.as_p }}
<ul>
<script
type="text/javascript"
src="http://code.jquery.com/jquery-latest.min.js"
></script>
<li>
{#
<input
type="number"
name="field1"
class="field-style field-split align-right"
placeholder="اﻟﺴﻨﺔ"
id="year"
/>
#} {#
<input
type="date"
name="field2"
class="field-style field-split align-left"
placeholder="اﻟﺘﺎﺭﻳﺦ"
id="date"
/>
#}
<h2>Add Member</h2>
</li>
<li>
<input
type="text"
name="name"
class="field-style field-split align-right"
placeholder="enter ur name "
id="name"
/>
</li>
<li>
<input
type="text"
name="date"
class="field-style field-full align-none"
placeholder=" your birthdate"
id="birthdate"
/>
</li>
<li>
<input type="radio" name="gender" id="male" value="male" /> Male<br />
<input type="radio" name="gender" id="female" value="female" />
Female<br />
</li>
<li>
<textarea
name="description"
class="field-style"
placeholder="introduce yourself "
id="description"
></textarea>
</li>
<li>
<input
type="submit"
class="field-style field-full align-none"
id="save"
value="ADD"
/>
<script type="text/javascript">
$(function() {
$("#save").on("click", function(e) {
e.preventDefault();
name = $("#name").val();
birthdate = $("#birthdate").val();
description = $("#description").val();
radioValue = $("input[name = 'gender']:checked").val();
alert("radioValue =", radioValue);
$.ajax({
url: "/create/te2chira",
method: "POST",
data: {
na: name,
bi: birthdate,
de: description,
ra: radioValue
},
headers: {
"X-CSRFToken": "{{csrf_token}}"
}
})
.done(function(msg) {
document.location = "/home.html";
alert("ﻟﻘﺪ ﺗﻢّ ﺣﻔﻆ اﻟﻤﻌﻠﻮﻣﺎﺕ");
})
.fail(function(err) {
alert("ﻟﻢ ﻳﺘﻢ اﻟﺤﻔﻆ");
});
});
});
</script>
</li>
</ul>
</form>
</div>
{% endblock %}
views.py
def addperson(request):
name = request.POST['na']
birthdate = request.POST['bi']
description=request.POST['de']
radiovalue=request.POST['ra']
person=Person.objects.create(
name=name,date=birthdate,description=description,
gender=radiovalue
)
person.save()
return render(request,'./home.html')
Note that your URL pattern ends in a slash, but the URL your using in the Ajax call doesn't.
What's happening is that Django is automatically redirecting you from
/addperson to /addperson/. But a redirect is always a GET, so all your data is lost and therequest. POST lookups fail.
The solution is simply to use /addperson/ in the Ajax call, although you probably want to make the view more robust in any case.
Fetch data using get method
def addperson(request):
data = request.POST
name = data.get('na', '')
birthdate = data.get('bi', '')
description= data.get('de', '')
radiovalue= data.get('ra', '')
person=Person.objects.create(
name=name,date=birthdate,description=description,
gender=radiovalue
)
person.save()
return render(request,'./home.html')

Please tell me how to create a toggle out of an image?

I want multiple images in a window. When I click on a image I want toggle out showing some info. I want this on all my images.
You didn't post the technologies you're using so I assume you are using jQuery and html:
Here is the html example:
<div>
<img class="img" data-imgid="img1" src="https://i2.wp.com/beebom.com/wp-content/uploads/2016/01/Reverse-Image-Search-Engines-Apps-And-Its-Uses-2016.jpg?w=640&ssl=1" width="200px" />
<br/>
<text style="display:none;" id="img1">Image1 ......</text>
<br/><br/>
<img class="img" data-imgid="img2" src="http://www.111ideas.com/wp-content/uploads/2018/01/download-rose-image.jpg" width="200px" />
<br/>
<text style="display:none" id="img2" class="text" hide>Image2 </text>
<br/><br/>
<img class="img" data-imgid="img3" src="https://processing.org/tutorials/pixels/imgs/tint1.jpg" width="200px" />
<br/>
<text style="display:none" id="img3" class="text" hide>Finally Image3 :)</text>
</div>
​and here is the jQuery code which handle the toggling process.You need to use toggle method based on the id of any text tag in the html code inside onclick function to toggle it:
$(function () {
$('.img').on('click', function () {
var txtId = $(this).attr('data-imgid');
$('#' + txtId).toggle();
});
});
You can see live demo here:
http://jsfiddle.net/gtU56/342/

concdtional img src inside grdiview image template

I m using image template inside a gridview like this
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div1<%# Eval("bank_id") %>');">
<img alt="" id="imgdiv1<%# Eval("bank_id") %>" width="20px" border="0" src="../Images/Plus.gif" />
</a>
</ItemTemplate>
</asp:TemplateField>
here i am using src="../Images/Plus.gif" but i want to set to path conditionaly.like if Eval("bank_id") is -1 then there should no image displayed or path to b set.is there any one help me to set the conditonal image path
you can small trick here. instead of bind your data directly to your image you could call some function that 'll send to it directly the data from DB then in that function you check for that value and based on what you need you return the correct string(correct image src).
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div1<%# Eval("bank_id") %>');">
<img alt="" id='<%#getImageSRC(int.Parse(Eval("bank_id").ToString())) %>' width="20px" border="0" src="../Images/Plus.gif" />
</a>
</ItemTemplate>
</asp:TemplateField>
then in your cs file:
public string getImageSRC(int bankId)
{
if (bankId < 0)
return "";
else
return "/bank-images/" + bankId + ".jpeg";//return here the correct image path
}

How to get text between two strings with special characters in ruby?

I have a string (#description) that contains HTML code and I want to extract the content between two elements. It looks something like this
<b>Content title<b><br/>
*All the content I want to extract*
<a href="javascript:print()">
I've managed to do something like this
#want = #description.match(/Content title(.*?)javascript:print()/m)[1].strip
But obviously this solution is far from perfect as I get some unwanted characters in my #want string.
Thanks for your help
Edit:
As requested in the comments, here is the full code:
I'm already parsing an HTML document doing something where the following code:
#description = #doc.at_css(".entry-content").to_s
puts #description
returns:
<div class="post-body entry-content">
<img alt="Photo title" height="333" src="http://photourl.com" width="500"><br><br><div style="text-align: justify;">
Some text</div>
<b>More text</b><br><b>More text</b><br><br><ul>
<li>Numered item</li>
<li>Numered item</li>
<li>Numered item</li>
</ul>
<br><b>Content Title</b><br>
Some text<br><br>
Some text(with links and images)<br>
Some text(with links and images)<br>
Some text(with links and images)<br>
<br><br><img src="http://url.com/photo.jpg">
<div style="clear: both;"></div>
</div>
The text can include more paragraphs, links, images, etc. but it always starts with the "Content Title" part and ends with the javascript reference.
This XPath expression selects all (sibling) nodes between the nodes $vStart and $vEnd:
$vStart/following-sibling::node()
[count(.|$vEnd/preceding-sibling::node())
=
count($vEnd/preceding-sibling::node())
]
To obtain the full XPath expression to use in your specific case, simply substitute $vStart with:
/*/b[. = 'Content Title']
and substitute $vEnd with:
/*/a[#href = 'javascript:print()']
The final XPath expressions after the substitutions is:
/*/b[. = 'Content Title']/following-sibling::node()
[count(.|/*/a[#href = 'javascript:print()']/preceding-sibling::node())
=
count(/*/a[#href = 'javascript:print()']/preceding-sibling::node())
]
Explanation:
This is a simple corollary of the Kayessian formula for the intersection of two nodesets $ns1 and $ns2:
$ns1[count(.|$ns2) = count($ns2)]
In our case, the set of all nodes between the nodes $vStart and $vEnd is the intersection of two node-sets: all following siblings of $vStart and all preceding siblings of $vEnd.
XSLT - based verification:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vStart" select="/*/b[. = 'Content Title']"/>
<xsl:variable name="vEnd" select="/*/a[#href = 'javascript:print()']"/>
<xsl:template match="/">
<xsl:copy-of select=
"$vStart/following-sibling::node()
[count(.|$vEnd/preceding-sibling::node())
=
count($vEnd/preceding-sibling::node())
]
"/>
==============
<xsl:copy-of select=
"/*/b[. = 'Content Title']/following-sibling::node()
[count(.|/*/a[#href = 'javascript:print()']/preceding-sibling::node())
=
count(/*/a[#href = 'javascript:print()']/preceding-sibling::node())
]
"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the provided XML document (converted to a well-formed XML document):
<div class="post-body entry-content">
<a href="http://www.photourl">
<img alt="Photo title" height="333" src="http://photourl.com" width="500"/>
</a>
<br />
<br />
<div style="text-align: justify;">
Some text</div>
<b>More text</b>
<br />
<b>More text</b>
<br />
<br />
<ul>
<li>Numered item</li>
<li>Numered item</li>
<li>Numered item</li>
</ul>
<br />
<b>Content Title</b>
<br />
Some text
<br />
<br />
Some text(with links and images)
<br />
Some text(with links and images)
<br />
Some text(with links and images)
<br />
<br />
<br />
<a href="javascript:print()">
<img src="http://url.com/photo.jpg"/>
</a>
<div style="clear: both;"></div>
</div>
the two XPath expressions (with and without variable references) are evaluated and the nodes selected in each case, conveniently delimited, are copied to the output:
<br/>
Some text
<br/>
<br/>
Some text(with links and images)
<br/>
Some text(with links and images)
<br/>
Some text(with links and images)
<br/>
<br/>
<br/>
==============
<br/>
Some text
<br/>
<br/>
Some text(with links and images)
<br/>
Some text(with links and images)
<br/>
Some text(with links and images)
<br/>
<br/>
<br/>
To test your HTML, I have added tags around your code then pasting it in a file
xmllint --html --xpath '/html/body/div/text()' /tmp/l.html
output :
Some text
Some text
Some text
Some text
Now, you can use an Xpath module in ruby and re-use the Xpath expression
You will find many examples on stackoverflow website searches.

Resources