Error In Rendering Jade Files - mongodb

I get an error while rendering the Jade file. The code that I use in app.js is:
app.get('/photos/new' function(req, res) {
res.render('/photos/new', {
locals: {
photo: new Photo()
}
});
});
The corresponding Jade file is:
h1 New Photo
form(action='/photos', method ='post', enctype ='form-data')
!= partial('../partials/photo_form', { locals: { photo: photo}})
p
input(type = 'submit')
But I get an error saying photo is not defined. I don't know where I am doing wrong. Please help.

The locals in the partial is implied, so give this a try:
!= partial('../partials/photo_form', {photo: photo})

when doing partial include, it refers to the current directory the view is in..
so the response you are rendering comes from:
/views/photos/new.jade
right?
so then the partial include is in the new.jade file.. which means if you do
partial('../partials/photo_form',{'whatever':'whatever'})
its looking in:
/views/partials/photo_form.jade
is that what you are expecting?
because if it is in
/views/photos/photo_form.jade
just do partials('photo_form',{'whatever':'whatever'})
and it will default to the directory the parent view is in.
http://expressjs.com/guide.html
and check view lookup
cheers

Related

How to get path of selected directory into renderer process

I want to store in variable the path of local directory selected using dialog.showOpenDialog.
I tried every tutorial and stack answer without any luck.
Best part is that even the electron-api-demos solution isn't working (I am using one here)
So, dialog opens, I can select a folder or a file - but nothing is send back to renderer process.
Here I am testing this with opening files but also no results.
I am using jquery btw and elcetron v 12.
Here is my code:
Renderer process:
$('.js_select_folder').on('click', (e) =>{
ipcRenderer.send('open-folder')
e.preventDefault();
})
ipcRenderer.on('selected-folder', (event, path) => {
console.log('wtf',path)
$('#info').text('Result :'+path)
})
Main process:
ipcMain.on('open-folder', (event) => {
dialog.showOpenDialog({ properties:['openFile']}, (files) => {
if(files){
console.log(files)
event.reply('selected-folder', files)
}
})
})
No trace of console.log(files) anywhere.
Any ideas what I am doing wrong?
I figured it out:
renderer process:
$('.js_test').on('click', (e)=>{
e.preventDefault();
ipcRenderer.send('open-folder')
})
ipcRenderer.on('sel-dir', (event, path) => {
const message = `This app is located at: ${path}`
$('#info').text(message)
})
main process:
ipcMain.on('open-folder', (event, arg) => {
dialog.showOpenDialog({properties: ['openDirectory']}).then(result=>{
event.sender.send('sel-dir', result.filePaths)
})
})
So it is actually super simple as you can see but took me two days to figure it out.
The result is that I get the path (or any data) back to renderer after choosing dir or file.
Regards, Mac.

After find span in UI grid and click got failed: Element is no longer valid

I run function on UI-grid that all element in the grid are clickable.
it('Test1', function() {
element.all(by.css('span.ft-grid-click')).each(function(elmt) {
elmt.getText().then(function(txt) {
if (txt == 'ORO_B_IN_002') {
elmt.click();
return;
}
})
})
});
On screen the element clicked but I got this error:
Failed: Element is no longer valid (WARNING: The server did not provide any stacktrace information).
Help please.
Thanks!
There is a much better way to find an element by text Content: cssContainingText()
Here is, how it will look in your code:
it('Test1', function() {
element(by.cssContainingText('span.ft-grid-click', 'ORO_B_IN_002')).click();
});
This should work for you.

How to render a view into a string in SailsJS?

In one controller I want to render a certain view with a certain layout to send an email with the resulting string, but I obviously do not need to show the result to the user. Is there a way to use the EJS engine that I'm using to render views to achieve this? Here's my a bit simplified controller action:
setEmail: function(req, res) {
var update = {
activationToken: _getToken(),
email: req.param('email')
};
Profile.update(res.locals.profile.id, update).then(function(profile) {
res.redirect(profileUrl);
mailer.sendActivationEmail(
update.email,
res.i18n('Подтвердите свой адрес электронной почты'),
emailString); // <=== Here is where I need the string rendered from a view
});
},
Use the view-hook
Profile.update(res.locals.profile.id, update).then(function(profile) {
res.redirect(profileUrl);
sails.hooks.views.render("viewname",profile, function(err,html){
if(err) return console.log(err);
mailer.sendActivationEmail(
update.email,
res.i18n('Подтвердите свой адрес электронной почты'),
html
);
})
});
Edit: right callback
I think I would rather use a specific email module like this one:
https://github.com/niftylettuce/node-email-templates
Which can access EJS templates

Using a javascript XPCOM component to create a custom autocomplete box in a FireFox add-on

I've spent a few days reading over all manner of tutorials, MDN entries, and S.O. posts, and I've come to suspect that I'm missing something obvious, but I'm too inexperienced with XPCOM to spot it. I'm about 80% sure there error is somewhere in my custom component (components/fooLogin.js).
Problem: When the add-on initializes (when I call loadData() from chrome/content/foologin.js), I get an error saying:
TypeError: Components.classes['#foo.com/foologinautocomplete;1'] is undefined
Am I maybe trying to create the component before the class has been registered? Is there something else I need to do to register it? Any tips would be appreciated.
Relevant Code: (happy to supply any additional code, if need be)
components/fooLogin.js:
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function fooLoginAutoComplete(){
this.wrappedJSObject = this;
}
fooLoginAutoComplete.prototype = {
classID: Components.ID("loginac#foo.com"),
contractID: "#foo.com/foologinautocomplete;1",
classDescription: "Auto complete for foo",
QueryInterface: XPCOMUtils.generateQI([]),
complete: function(str){ // Autocomplete functionality will in this function
return null;
}
};
var NSGetFactory = XPCOMUtils.generateNSGetFactory([fooLoginAutoComplete]);
chrome/content/foologin.js:
let fooLogin = {
dataLoaded : false,
searchFilter = null,
...
loadData : function(){
...
try{
alert(1); // This alert fires
this.searchFilter = Components.classes['#foo.com/foologinautocomplete;1']
.getService().wrappedJSObject;
alert(2); // I get the error before this alert
}catch(e){alert(e);}
this.dataLoaded = true;
}
}
window.addEventListener("load", function(){
if(!fooLogin.dataLoaded) fooLogin.loadData();
}
chrome.manifest:
content foologin chrome/content/
content foologin chrome/content/ contentaccessible=yes
skin foologin classic chrome/skin/
locale foologin en-US chrome/locale/en-US/
component loginac#foo.com components/fooLogin.js
contract #foo.com/foologinautocomplete;1 loginac#foo.com
overlay chrome://browser/content/browser.xul chrome://foologin/content/foologin.xul
In your chrome.manifest, you have this:
component loginac#foo.com components/fooLogin.js
contract #foo.com/foologinautocomplete;1 loginac#foo.com
and in fooLogin.js you have:
classID: Components.ID("loginac#foo.com"),
loginac#foo.com is not a valid class ID for a component.
They have to be of the form:
{00000000-0000-0000-0000-000000000000}
Only add-ons can have a foo#bar.com format.

How to manipulate forms with Mootools

I'm trying to manipulate forms with Mootools. My purpose is to inject the response content of a form into a div element named result.
Here a code that works, but it replaces the content of the result div. This is not what I want : I want to ADD the form response content to the result div existing content. I just can't find on the web how to do this, and I've tried many things that are not working ... Please help
window.addEvent('domready', function() {
$('myform').addEvent('submit', function(e) {
e.stop();
var result = $('result').empty();
this.set('send',{
url: this.get('action'),
data: this,
onSuccess: function() {
result.set("html", this.response.text);
}
}).send();
});
});
If it's only text you want to add, just remove the empty method, and replace result.set() with result.appendText().
If you need to append an element tree, repeat the first step, and do:
onSuccess: function(){
Elements.from(this.response.text).inject(result);
}
Btw. It's all in the documentation - http://mootools.net/docs/core/Element/Element