I replicated all of the code used in the AspNetZero solution for the "profile picture" functionality. I'm referring to the function that allows the user to upload their own photo.
I have copied the existing modal, JS file and controller methods into my employee controller and employee folders respectively, as I wanted the same functionality.
The upload of the image and saving into the binary objects table is all working just fine.
The issue comes up when I try to display the thumbnail of the uploaded photo in my employee index view datatable column. I copied this functionality from the user index view in the solution.
When my employee index view is rendered the thumbnail does not appear. When I click on the image thumbnail it opens the new tab and throws a 404 error for my copied controller method.
Here is the JS code that displays the thumbnail image in the users index view:
targets: 1,
data: "userName",
render: function (userName, type, row, meta) {
var $container = $("<span/>");
if (row.profilePictureId) {
var profilePictureUrl = "/Profile/GetProfilePicture?t=" + row.profilePictureId;
var $link = $("<a/>").attr("href", profilePictureUrl).attr("target", "_blank");
var $img = $("<img/>")
.addClass("img-circle")
.attr("src", profilePictureUrl);
$link.append($img);
$container.append($link);
}
$container.append(userName);
return $container[0].outerHTML;
}
Here is the same code in my employee index view:
targets: 4,
orderable: true,
autoWidth: true,
data: "fullName",
render: function(fullName, type, row, meta) {
var $container = $("<span/>");
if (row.employeePictureId) {
var profilePictureUrl = "/Employee/GetProfilePictureById?id=" + row.employeePictureId;
var $link = $("<a/>").attr("href", profilePictureUrl).attr("target", "_blank");
var $img = $("<img/>").addClass("img-circle").attr("src", profilePictureUrl);
$link.append($img);
$container.append($link);
}
$container.append(fullName);
return $container[0].outerHTML;
}
The line of code that does not work is the ProfilePictureUrl line.
var profilePictureUrl = "/Employee/GetProfilePictureById?id=" + row.employeePictureId;
If I replace the above line with the line from the user index.js and call the profile controller method, it works just fine. But when I try to call my employee controller method it keeps throwing the 404 error.
My employee controller is at the same level in my solution as the profile controller. Both controller are part of the same area in my MVC app.
I just solved my issue. There is another profile controller which sits outside of the area folder. So the URL used in the users index.js does not need to mention the full path.
The users photo function is hitting the profile controller at the root level of the app and not the one inside of the area.
In my case I had to treat the URL just like I do with all the modals and scripts that are in my area.
Here is the solution that worked.
var empPhotoUrl = abp.appPath + 'AreaName/Employee/GetProfilePictureById?id=';
Related
I have a created a page that contains a list of reviews. If the user clicks on a name, he will be directed to a page where he can edit the review details if needed.
In order to achieve this I have adapted the methods from the travel approval template.
The names in the list are link widgets that contain the onClick event which I simply adapted from the template to get a quick result. The client script is integrated in the onAttach event of the page.
//button method
if (event.ctrlKey === false && event.metaKey === false) {
event.preventDefault();
app.showPage(app.pages.ReviewDetails);
replaceUrlForEditRequest(widget.datasource.item._key);
}
//client script
function startLoadingEditRequestPage() {
google.script.url.getLocation(function(location) {
var requestId = location.parameter.requestId;
var requestDs = app.datasources.Reviews;
if (requestDs.creating) {
return;
}
if (!requestId) {
app.showPage(app.pages.Dashboard);
return;
}
if (requestDs.loaded && requestDs.query.filters._key._equals === requestId) {
return;
}
requestDs.unload();
requestDs.query.filters._key._equals = requestId;
requestDs.load();
});
}
The handover to the edit page works perfectly. The user will see the review details of the person he has clicked on (ex: Mary Poppins) and not the one who has the active index in the list. If the user clicks on a link "personal information" in the review details page he will be directed to another edit page where he can see other information of the person. For this I have simply amended the method from the template by adding another target page to the history.
function replaceUrlForEditRequest(requestId) {
var params = {
requestId: requestId
};
google.script.history.replace(null, params, app.pages.EditReview.name);
google.script.history.replace(null, params, app.pages.EditReviewDetails.name);
}
But when I duplicate the button method in the link on the review details page, it is not working. I always see the first name in my list and not the one that I had clicked on. How can I fix that?
The issue has been resolved. Although both pages were on the same model, they were not on the same datasource. After setting them to the same datasource, everything works fine.
I have ASP.NET application where we use AngularJS. The issue is when we click "edit" the new view is openinig in the same window (tab). How to open it in new window (tab)? Here's the code:
List.html:
<td><a ng-click="editUser(u.ID)">edit</a></td>
AngularJS:
AdminUsersApp.controller("ListController", function ($scope, $location, $http, ErrorUI, Users, Cashdesks) {
...
$scope.editUser = function (id) {
$location.path("/edit/" + id);
};
$location.path just returns the path of current page. instead you need the url which actually points to a different location, so when you call window s open function it should have window.open('example.com/admin/Admin_Users.aspx#/edit/id'). If you want to build the url dynamically use $location.host(), $location.protocol() etc to build a url and then append /edit/id at the end
this work for me
$window.open(url);
I am working on a mvc3 controller which loads a page on search. In the main index page, there is a search button and that loads another (details list) page in the given div.
I have incorporated pagination to the child view (details list). So, upon clicking on the "Next" link, it loads the next page.
cshtml of the index page: The flat id refers to where the details list loads.
<div id='FlatDetailcontainer'>Select a Project for Flat Details.. Loading...</div>
<script type="text/javascript" language="javascript">
// $(document).ready(function () {
function login() {
var check = document.getElementById("rad").value;
$("input[name=selectproj][value="+check+"]").attr('checked', true);
//document.getElementById("selectproj").checked = document.getElementById("rad").value;
if (check != "") {
handleprojselect(check);
}
}
function handleprojselect(myRadio) {
// document.getElementById("rad").value = myobj["proj"];
$.get('#Url.Action("Details", "ProjectDetails")?id=' + myRadio,
function (viewResult) {
$("#FlatDetailcontainer").html(viewResult);
});
}
function createproj() {
var url = '#Url.Action("Create")';
window.location.href = url;
}
</script>
The details page has the links of next and url action is as follows:
#if (Model.HasNextPage)
{
#Html.ActionLink("Next >", "Details", new { page = Model.PageNumber + 1 })
#Html.Raw(" ");
#Html.ActionLink(">>", "Details", new { page = Model.PageCount })
}
else
{
#:Next >
#Html.Raw(" ")
#:>>
}
However, this link always loads on a fresh page as there is no reference to the main Index page's div id. Please can someone suggest how to go ahead with this?
As far as you are loading part of the page via AJAX call you should also use AJAX to handle your pagination. You should create JS function like the following:
function nextPageClick(e)
{
e.preventDefault();
$.get($(this).attr("href"), //getting the URL from your link and loading the content via AJAX
function (viewResult) {
$("#FlatDetailcontainer").html(viewResult);
});
}
and bind it to the paging links on page load:
$(function (){
$('.nextPageLink').live('click', nextPageClick);
})
Notice that "live" jQuery method assigns click handler to the dynamically loaded content as well as on existing static content, so you have no need to reassing handler after each data reload.
You shoud add CSS class to your link to be able to locate it:
#Html.ActionLink("Next >", "Details", new { page = Model.PageNumber + 1, #class="nextPageLink" })
Of course you may use IDs or any other way to uniquely identify your pagination links.
I am new to meteor and learning to create web application looking at examples. I want to append the updated values of the database to html textarea.
For example if i update value for key "sensor", the sensor value needs to be appended to textarea. How can I do that using meteor?
You use a handlebars helper and bind changes to your text area to update the field: e.g
html
<template name="hello">
<textarea name="address">{{address}}</textarea>
</template
client side js
//Your collection that stores your data
MyCollection = new Meteor.Collection("mycollection");
//Your handlebars helper to give some data to address
Template.hello.address = function() {
var address = MyCollection.findOne({name:address});
if(address) return address.value;
}
//Something to bind changes to your address to your collection
Template.hello.events({
'change [name=address]' : function(e,cxt) {
var address = MyCollection.findOne({name:address});
MyCollection.update(address._id, {$set:{value:e.currentTarget.value}});
}
});
Finally you need something on your server side js too:
//The same collection as on your client
MyCollection = new Meteor.Collection("mycollection");
//Insert an address on the first time if there is nothing in yet:
Meteor.startup(function() {
if(!MyCollection.findOne({name:address})) {
MyCollection.insert({name:address,value:"10 Downing St, London, United Kingdom"});
}
});
Thats the basic gist of it to update a text area when its changed, and to show a value in your template . When its updated it will also reflect the update across to all tabs/everyone viewing the page.
I have this following requirement. Need to display the html Body of the Mime message in IFrame
View
<iframe id="myIframe1" src="http://localhost:23245/Home/GetMimeMessageContent?FilePath=D \MimeFiles/htmlBody-small1.eml&PartName=HtmlBody" style="width:600px;height:600px;" >
Controller
public ActionResult GetMimeMessageContent(string filePath,string partName)
{
var mimeModel = BuildMimeModel(filePath, partName);
MimeHeaderModel mimeHeadermodel = new MimeHeaderModel();
mimeHeadermodel.FromAddress = mimeHeadermodel.ToAddress = mimeHeadermodel.Subject = string.Empty;
mimeModel.MimeHeader = mimeHeadermodel;
return View("MailDetailsView", mimeModel.MimeBody.HtmlBody);
}
it's not showing the HtmlBody in the Iframe. But Its calling the controller. I dont know what I am missing.
Not sure if your using jquery or not, but:
$(function() {
var $frame = $('<iframe style="width:200px; height:100px;">');
$('body').html( $frame );
setTimeout( function() {
$.ajax(
url="/Home/GetMimeMessageType/small1.eml/HtmlBody",
type:'GET',
success: function(data){
var doc = $frame[0].contentWindow.document;
var $body = $('body',doc);
$body.html(data);
}
);
},1 );
});
I have not tested the above code, but this should work fine. A few things to note:
You will need to create a custom Route to map this to your controller:
http://msdn.microsoft.com/en-us/library/cc668201(v=vs.100).aspx
You will also need to change the javascript $('body').html() to be the ID of a div as a placeholder
also you will notice i have no path, if this never changes, you should add the path to your code or you can use formcollection and change the jquery ajax to a post, and set the variables and values there.
Your content will then up up in an iframe.
Forget the whole html.renderaction, this solution gives you a little more scope