Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there a standard process for removing html code from jQuery code ?
Often I encounter code such as :
var $lab = $('<label/>').html('Enter Name ');
var $text = $('<input id="name" type ="text" /> ');
$set.append($lab);
set.append($text);
I think this does not look very clean, can code like this be re-factored using AngularJS or similar type framework so there is seperation between UI and logic code ?
I could just break up the file into different .js files where each file contains a specific set of UI creation functions but this is not really solving the issue ?
There are some ways to maintain HTML and JS separated. I've used two frameworks and I'm currently using one of them because I think it's great! (talking about angularjs).
AngularJS
AngularJS is a very useful framework that works using MVC patterns:
https://angularjs.org/
With this framework you process the data and do all the tough work with JS and then inject that data directly to the HTML.
You should take a look, although it's a little bit hard at the beginning.
Html Templates based frameworks, like Backbone
Backbone is another MVC js framework and it uses HTML templates to maintain html and js separated. You create JS classes which have a 'render' function, that paints the data (usually using templates).
http://backbonejs.org/
Of course, there are many other frameworks and ways to do it, but you could start by checking this frameworks (I especially recommend angularjs!)
Good luck :>
AngularJs is MV* framework.
TodoMVC shows you the known MV* framework through a todo list application.
It covers a full bundle to make a frontend app, server-side is using to do REST.
Basically, an admin panel is a good place to use these frameworks.
If you simply want to separate html from js, you use a template engine.
Hogan shows you how a javascript template engine works.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm watching the udemy Django tutorial that requires using JavaScript as the front-end and Python for the back-end:
Can you replace JavaScript with Python?
What are the advantages and disadvantages of that?
No, python can't be used in frontend.
You need frontend technologies like html, css, javascript, jQuery etc...
for frontend.
Python can be used as scripting language in backend.
As others already said, basically you can't use Python at the front-end. You can use Django Template Language or something like Jinja2 in your templates, but generally speaking these engines run on your server, not in the browser.
Actually, you can use Python to write the code, that runs in the browser, using transpilers like Transcrypt. But I don't recommend you to do such a thing on a real project because of raising complexity and difference between these two languages. The only advantage would be that you can use one language to write both front-end and back-end. But the complexity of supporting this code will not worth it.
Its true that you can do something interesting with Django template system. but like #Astik said you cant replace javascript in front end. Personally I don't use javascript for some Django projects because I don't need it, but there are many situation that I have to. However that depends about your project is going to work.
Something better than Django templates system is jinja2 read more about it maybe help you
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm building an app in django that lets users create and edit flowcharts for the purpose of process/procedure control. There are three basic models: Procedure, Step, and Transition.
I've created and debugged all the model relationships and through the admin interface and shell, I can create Procedures with several Steps and Transitions. It's functional but not intended for the end user. I need to create a browser-based jgraphical interface.
Enter visjs, a javascript visualization library. Using visjs, I've created a basic block-diagram editor that lets users add/edit/delete nodes and edges (this is my first javascript attempt ever). I can load data from the database and post data back to the database through a couple of custom views and JSON serialization. However, it feels kludgey and hard to maintain. For example, it's not integrated into django's forms framework at all.
At the moment, when submitted, the javascript does the serialization to post JSON data and JSON data only. I'd really like this to be a standard form submission but I can't figure out how to structure the form.
How would you go about building a form to do handle this? I'm basically trying to get my javascript block diagram to be the form, if that makes any sense. Is this the use-case for a custom widget?
Another wrinkle here is that the editor needs to create/update/delete the top-level procedure, the steps, and the edges.
Thanks for your help
I think a custom widget is what your looking for and would start by learning from examples of other Django apps which do something similar. The project I am currently working on includes the app named django-ckeditor which creates a widget around ckeditor. I believe it solves a similar problem to yours in the sense that it creates a Django widget from a javascript widget.
Study how they approach a similar problem and see if it helps.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am acting as web developer for a small startup, taking over as the only in-house developer to maintain and adapt the application that was initially put together by a team of contractors. I would consider myself to be at an intermediate level with Ruby on Rails. I know enough about front end technologies like HTML and CSS to use Bootstrap or Foundation effectively and write my own tweaks when necessary. However, I only can read the JavaScript code of other developers well enough to make small modifications to what's already in place.
I would like to become proficient in JavaScript to help round out my skillset but there seem to be a lot of JavaScript "options" out there and I'm not sure what's on the way in, what's on the way out, what's popular, what's most useful, easiest to start with, best fit for Rails applications and so forth. And by "options" I mean "regular" Javascript, jQuery, Node, Angular, etc etc.
In hopes that my question will meet SO terms as "answerable" I'd like to focus on the question of what kind of Javascript fits best with Rails and which technologies are the most generally relevant today (i.e. not on the way out of popularity already).
Your choice should depend on what you're doing. One case might be using Rails primarily on the back-end, pulling data from it, and then generating your markup and displaying content primarily on the front-end with JavaScript. In that case, you should look into a JavaScript framework like Ember.js or AngularJS. If you're going to be generating your markup primarily on the back-end with Rails, having that markup being pre-populated with content before being sent to the user, you might be better off using jQuery for DOM manipulation and the occasional AJAX request to your Rails back-end.
In the case you're looking for a framework: Yehuda Katz is a leading voice in the Ruby on Rails core team, and has a similar role inside of the Ember.js project. While this isn't strictly objective, I'd say that Ember is the JavaScript framework that most closely matches "The Rails Way". That said, any framework will integrate well if you're using Rails as a backend, and AngularJS is currently more popular and might be easier if you're looking for examples and helper libraries.
I'd like to point out that Ember is just a framework, just like jQuery is just a library. Knowing JavaScript from the bottom up is a very helpful thing when working with anyone's code. I highly recommend checking out the Learn JavaScript page on MDN, and maybe picking up a copy of JavaScript: the Good Parts by Douglas Crockford. The former has a bunch of free information about getting up to speed on JavaScript. The latter is a dense, and somewhat controversial book, but (in my opinion) is one of the best books about dealing with the language's rough edges.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to develop a website using JavaScript/HTML5/CSS3, because it is more flexible in UI. I read internet about AngularJS for the client side and about NODEJS: it can be used to both clent side and server side.
Can anyone kindly inform me about the cons and pros of the following:
use AngularJs for client side and other language for server side (EX : PHP ).
Use NODE.JS for build website
or can I use both?
If you want to check for pros & consof Angular only, here is the list:
PROS
Angular follows MV-Whatever architecture. Hence you can either MVP, MVC or MVVM.
It gives the flexibility to do two way binding. Data binding tries to get rid of writing codes manually by relieving the backend server from creating templates. MVC pipeline is also maintained by the framework itself.
DOM Manipulations at one place: You can make use of angular directives to play with the dom giving a neater code.There are some reusable tags defined by angular folks themselves in directives like ng-class, or ng-show. See Angular Directive Documentation
Test Ready: The fact that AngularJS comes linked with Dependency Injection (DI) makes it ready for unit testing by injecting mock data into controller and measuring the output and behavior.
Ionic Framework: Ionic Framework is written on top of Angular and is mainly used to build hybrid apps. So Angular is useful if you are going to extend your website into a mobile hybrid app.
Cons:
Difficult to adapt the existing code: AngularJS requires the developer to re-implement the entire transformation code which makes it extremely hard to play around while adapting existing code.
Heavy: Their are lighter frameworks like backbone and knockout, however seeing the power of Angular it can be easily negated
Now moving to your question whether Nodejs be used in conjunction to Angularjs my answer to it is:
AWESOME COMBINATION
You can have your server code residing in nodejs and use angularjs at client side keeping the architectures completely different. Since Nodejs also uses javascript there would be less of uptime for developers to learn it and start developing. Infact MEAN (Mongo-Express-Angular-Node) methodology.
Their are various boilerplates available in order to kick start your development. One can be found at MEAN
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Now I don't have any specific question, rather a general, ask for opinions post.
Within a month we will receive the documentation of a project we have to develop. The website has a lot of potential and will be advertised in TV and radio as well when it'll be done. So it'll have a lot of visitors, members and it'll have a rich admin panel with lots of options. My friend who was asked to be the CTO is a senior PHP developer with almost 10 years of experience and I am a junior JS developer. (or less, I don't have years of experiences in JS, but I'm committed)
Is a JS MVC framework substitute for PHP? Is a PHP MVC framework substitute for JS? Are they both working well together or is it possible to not use any framework, but write the project in MVC approach?
For example:
model: PHP
controller: JS (jQuery+Ajax)
view: HTML, CSS
As my friend is a professional PHP developer and will have a daily job next to, but only in the beginning of this project, he doesn't really want to learn an other language (like Node.js), because almost everything is a routine for him now in PHP.
I know everything depends on the documentation and what we have to develop exactly, but I'm just a curious mind and want to understand more. I know I have much to make up and sometimes I worry of my current knowledge, but then I think that be whatever big the challenge, there will always be a solution for it.
MVC does not mean to use differenct languages for all of the modules (model, view, controller), but to loose couple and encapsulate certain parts of your application.
Against many opinions, MVC is not the panacea for application development. It really depends on the application you're developing.
It's not necessary to use any frameworks in order to follow the MVC approach. In fact it's a pattern that can be tied together very quickly, in it's most basic form.
If you decide to use your backend as an API and pull the data via frontend, you don't need to use MVC come hell or high water. For an API for example it's not necessary to perform most of the view tasks. Instead you should care about building a performant and scalable data storage layer (which for example is able to easily provide your data in many common formats, such as XML or JSON) and a strong router that can handle HTTP Requests nicely (See if REST is something for you).
In this case you want a strong frontend which can handle templates, and also has a strong layer for obtaining, sending and handling data in general. A strong controller layer that can delegate tasks to certain parts of your application would also come in handy.
Well you see what I'm talking about. It really depends on your application. In my example the backend wouldn't exactly follow the MVC approach, while my frontend would completely. MVC isn't about switching programming languages for certain parts of your application. Instead it decouples your application structure making things a lot easier.
Of course Frameworks come in handy when developing such an enterprise scale application, but it's not necessarily required.
To sum things up: MVC has not much to do with the code itself, it has much more to do with architecture and structure of your code. How exactely you're implementing it is absolutely up to you.