I am currently changing the code for a Web application (written with Angular.JS and the ionic framework with jQuery) that has a page generator. This generator page writes the image information into a relational database (phpMyAdmin, 10.1.22-MariaDB). What I have to do is to add a new form to this app where the user selects an existing page from a list & opens it in the page generator.
The div element that holds the image object is created in the page generator with a $templateCache.put command and has the following form:
"$templateCache.put("ivm-image-builder/templates/image-builder.html", "
"<div class=\"hero\"\n" +
[…]
" <div class=\"hero-image\" ivm-bg-axis=\"y\" ivm-bg-drag ivm-bg-disabled=\"disabled\" ng-style=\"imageOptions.style\" ngf-background=\"ngModel\"></div>\n" +
[…]
The code runs properly when creating a new page. When using this generator page for an existing page that had been saved in the database, I can easily fill the text fields (like "page name" or "URL" (a text field)), but I wonder how the images can be displayed properly. I wonder if a longtext field or a BLOB is the appropriate field type in the DB.
Edit: To save the image in a database record, I need something that reads in pseudo-code
var cache = new BrowserCache();
var imageURL= cache.querySelector('url["blob:null/520cf0e0-fa19-438c-9db7-68af87f30f56"]');
var image = cache.getElement(imageURL);
// Convert image to appropriate format, if necessary
// Add image information to record to be sent to the server
My question is: How can I display an image received from the database, which has no associated URI & is not saved at any accessible location? Is it the right way to associate the image information with the ngModel tag?
Related
Documentation doesn't help at all,no Table or Grid is specified...(or I cant find it)
I tried to create a grid from inside InDesign and it shows up as TextFrame,but still I dont understand how to manage it.
The tool I need to do takes a file(CSV/JSON) and generates a Table(or whatever is called in Adobe) from it,but the problem is that I can't find anything about Table generation.
Basically you can make a table from a selected text with the method convertToTable() this way:
var doc = app.activeDocument; // your document
var frame = doc.pages[0].textFrames[0]; // first text frame on first page
frame.texts.everyItem().select(); // select all text inside the frame
var table = app.selection[0].convertToTable(); // convert the selection into a table
Before:
After:
Reference:
Text object
As for the rest... it's need more details about your workflow. JSON and CSV are quite different beasts, it would be different parsing algorithms for each of the formats. Will you copy the contents of the files manually or the script should read all csv or json files from some predefined folder? Or there should be some interface to select a file(s). Or a folder? How it supposed to handle a page size and formatting of the table? Etc...
All is working good except of the fact that, i am trying to display user profile images of user who sent a chat message in a chat room .
this is what my image patth prints "profilepics/images_g9LwcHF.jpg".
Note i am using django framework
<script>
chatSocket.onmessage=function(e){
var tag_img=document.createElement('img');
var get_user=document.querySelector('#user').value
var tagname=document.createElement('li');
var data =JSON.parse(e.data);
document.querySelector('.img_tag').src=data.message.sender_img
</script>
Dom
<img class ="img_tag">
This is my consumer.py
messaage_json={
'user':me.username,
'message':message_object.message,
'sender':message_object.sender.username,
'sender_img':str(message_object.sender.profilepicture),
'created':str(message_object.created)
}
#coverting data to string
myResponse={
"message":messaage_json,
}
#broad cast the message event to be send
# in the layaer
await self.channel_layer.group_send(
self.room_group_name,{
# call the chat_message method
"type":"chat_message",
#covert string data to json objects
"text":json.dumps(myResponse),
}
)
It prints out the user profile image path in the media file, but cannot display the image using javascript.
Note i am using django .
I do not see you actually injecting the newly created image DOM-node into the DOM, e.g. somewhere you would need to do that for the image to be displayed:
chatSocket.onmessage=function(e){
var data =JSON.parse(e.data);
var tag_img=document.createElement('img');
tag_img.src = data.message.sender_img;
document.querySelector('.img_tag').appendChild(tag_img);
yes i solved the problem . To display the image path, since all uploaded images are stored in django media file , i am to use the following bellow
tag_img.src = '/'+'media'+'/'+ data.message.sender_img;
I am beginner in Javascript. I am currentlyworking on a Phonegap app with it. I am stuck in between as I have 4 html pages for signup process, and I have to pass all the html pages input value to single js file as in final all data must be POSTed to server URL and also I have read on many sites that they have recommended using same js file for all the pages of your site to speed up the site. So I have two problems to solve. I searched on many sites but could not find the accurate answer.
I need to pass 4 html page's input value to single js file.
I have to make single js file for both sign-in and sign-up.
My codes for JS page is:
var firstName="";
var lastName="";
var email="";
var password="";
var retypePassword="";
var gender="";
var DOB="";
var institute="";
var course="";
var branch="";
var semester="";
var teachers = [];
function signUpStarting() {
alert(firstName + " "+lastName+" "+email+" "+password+" "+retypePassword+" "+gender+" "+DOB+" "+institute+" "+course+" "+branch+" "+semester+" "+teachers.join(","));
}
function signUp1() {
firstName[0] = $("#first_name").val().trim();
firstName[1] = $("#last_name").val().trim();
email = $("#email").val().trim();
password = $("#password").val();
retypePassword = $("#retype_password").val();
alert(firstName + " "+lastName+" "+email+" "+password+" "+retypePassword);
}
function signUp2() {
gender = $('#gender').find(":selected").text();
DOB = $('#DOB').val();
alert(gender+" "+DOB);
}
function signUp3() {
institute = $('#institute').find(":selected").text();
course = $('#course').find(":selected").text();
branch = $('#branch').find(":selected").text();
semester = $('#semester').find(":selected").text();
alert(institute+" "+course+" "+branch+" "+semester);
}
function signUp4() {
$(":checkbox" ).map(function() {
if($(this).is(':checked')){
teachers.push($('label[for="' + this.id + '"]').text());
}
});
signUpStarting();
}
In html pages I am calling JS functions for each pages:
On first page:
<a onclick="signUp1()" href="register-two.html">continue</a>
On second page:
<a onclick="signUp2()" href="register-three.html">continue</a>
On third page:
<a onclick="signUp3()" href="register-four.html">continue</a>
On fourth page:
<a onclick="signUp4()">continue</a>
On each transaction from one page to next I have set alert in JS, and I am getting alert with accurate values also. But after clicking the continue button from fourth page of html, I transferred the code to main signup function. I tried to see alert in signUpStarting() function but there I am getting response of just fourth page values and other values are showing nothing as the variables are null.
I am not getting how to save variable values for always without using localStorage or cookies and POSTing all data to server.And I think this would have been easier if I would know to code for all html pages for my site to single JS file.
Please help me !
I am not getting how to save variable values for always without using localStorage or cookies and POSTing all data to server.And I think this would have been easier if I would know to code for all html pages for my site to single JS file.
This is exactly right. You cannot store data in memory between page loads in a web browser environment because all javascript variables are naturally destroyed when the browser navigates away from the page to a new page (even if they use the same javascript on both pages). Thus, you have to save it somewhere with more permanence: localStorage, cookies, or on the server via POST or GET.
What I would recommend is scrapping the four different html pages and simply using one html page that changes dynamically as the user fills in data. This way the browser will not eliminate data before you are ready to POST it to the server.
How do i save entered/ inputted text using JavaScript/ html.
What do I want:
Name or code etc to be entered in a box (prompt box eksample) and then I want it to be displayed/ printed on the page and I want it to remain there so other people that visit can see it.
What I have:
I have code that shows a prompt box where you can enter text then displays it in green. However what i want is for the entered text to remain on the website for others to see...
function mobCode() {
mobCode = prompt("Insert Code", "Code here");
document.getElementById("mC").innerHTML = mobCode;
document.getElementById("mC").style.color="green";
}
<p id="mC"> Mob Code </p>
<button type="button" onclick="mobCode()"> Click to Add </button>
What you will probably have to do is write a script that will send the entered input to a database you build which can store that information,and then have your js access the database to display it in a certain area of your page.
Check out this Q & A one of the answers is a nice article to help explain the idea behind it: Send data from javascript to a mysql database
If you want to deal easier with persistence of the data, instead of setting up database and using server side script you can look at Facebook's Parse. The free plan is quite usefull for small projects. There is a JavaScript SDK that can be used directly from your javascript code.
Also you can view statistics from the Parse dashboard.
Here is some saple code for example:
// Create a new Parse object
var Post = new ParseObject("Post");
var post = new Post();
// Save it to Parse
post.save({"title": "Hello World"}).then(function(object) {
alert("Yay! It worked!");
});
I have an html site with a form in it and I want the user to be able to create a text/xml file depending on the input. But I wan't to avoid setting up a webserver only for this task.
Is there a good way, to do that, e.g. with Javascript? I think you can't create files with Javascript, but maybe create a data url and pass the text, so the user can save it to file?
Or is there another way to achieve this simple task without a webserver?
Solved it, somehow. I create a data url data:text/xml;charset=utf-8, followed by the XML.
function createXML() {
var XML = 'data:text/xml;charset=utf-8,<MainNode>';
var elements = document.getElementsByTagName('input'),i;
for (i in elements) {
if (elements[i].checked == true) {
XML += elements[i].value;
}
}
XML += '</MainNode>';
window.open(XML);
}
So the url looks like data:text/xml;charset=utf-8,<MainNode><SubNode>...</SubNode>...</MainNode>
Unfortunately this doesn't work for me on Chromium(Chrome) and on Firefox. It just displays the XML instead of showing a save dialog. But I think that's because of my settings and at least you can save it as a XML-file manually.
I haven't tried this but it should work.
After getting form data, system will call page A.
page A will have javascript that gets query strings and builds the page accordingly.
After finishing page build, user can save current page with following statement in javascript
document.execCommand('SaveAs',true,'file.html');