I´m new to dojo and I´m want to do the following:
Pretend you have a single page application but you have two views, which are built up totally different. One view is e.g. a startpage which would just fill the Bordercontainer-center. The second view would rather look like a standard webapp, with a header in the Bordercontainer-top, a menu in Bordercontainer-left and some content in Bordercontainer-center.
If the index.html (single page app) is now called I want the startpage to appeare first. There should be an onclick-event in it. With this event the views should change. This means the startpage disappears and the second webapp-view is shown.
What would be the best way to implement this?
I thought of using two Bordercontainers.
The first Bordercontainer would contain the startpage in the region center.
The second Bordercontainer would contain the webapp-view (top, left, center).
Would it now be possible to swap the center region from the frist Bordercontainer in a way that the startpage get´s swaped with the second Bordercontainer? Would this be a way how to solve my approach?
If yes I would need some kind of controller which would swap the view.
Could I solve this with using dojo.wire?
Or is there a straight forward approach in dojo, which I have not found yet?
If there is a small example or tutorial out there, it would be great to receive a link to it.
Thx for every hint.
You should take a look at dojox/mobile (http://dojotoolkit.org/reference-guide/1.10/dojox/mobile.html) it has support for what you are trying to do. You could also look at dojox/app (http://dojotoolkit.org/reference-guide/1.10/dojox/app.html or http://dojotoolkit.org/documentation/tutorials/1.9/dojox_app/contactsList/) to see if that gives you what you need.
I tried the following code:
require([
"dijit/form/Button"
], function() {
changeView = function(idShow, idHide) {
var showView = dojo.byId(idShow);
var showHide = dojo.byId(idHide);
if (showView.style.display == 'block') {
showView.style.display = 'none';
showHide.style.display = 'block';
} else {
showView.style.display = 'block';
showHide.style.display = 'none';
}
};
});
#view1 {
display: block;
}
#view2 {
display: none;
}
<html>
<head>
<title>Change View</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/resources/dojo.css">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dijit/themes/tundra/tundra.css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js" data-dojo-config="isDebug: true, parseOnLoad: true"></script>
</head>
<body class="tundra">
<div id="view1">
View1
<br>
<button dojoType="Button" widgetId="view1Button" onClick="changeView('view2', 'view1');">Change to View2</button>
</div>
<div id="view2">
View2
<br>
<button dojoType="Button" widgetId="view2Button" onClick="changeView('view1', 'view2');">Change to View1</button>
</div>
</body>
</html>
This lets me change the view with onclick and css and a little js.
I think this is one of the various ways you mentioned, for solving my approach. But what I think I´m missing now is to combine my function changeView with dojo - somehow.
What would be the right way to combine dojo and the function changeView now?
Would I write a dojo modul with a define and then work with it in my html and calling it with require?
Or generally.. for a dojo-beginner.
If I need javascript code for my app, is there a straight forward way to combine this with dojo?
e.g. with any kind of approuch
Look an see what dojo has to solve the approch
Write JS code, if there is no suitable dojo modul/function yet
Think about seperating the JS code it into modules
Write the modules in dojo with define
Use the modules in the app by calling them with require
Would this be a proper way for programming in dojo?
The question is more a general "howto glue JS and dojo together" to write webapps and use the advantages of dojo.
Thx in advance.
Related
Let me start by saying that I'm primarily a C# programmer who only extremely rarely ventures into JavaScript.
I can write myself some JS code as long as its mostly plain. I can handle jQuery and the odd self-sufficient 3rd-party library, but couldn't code myself out of a wet paper bag when React, Angular, Bootstrap and others enter the scene. I'm also not used to using npm or any other similar package manager.
It was never really my job nor interest, so I never went there. Whenever I code some JS, I reference the required JS files in my <script> tags and then use them as directly as possible.
I'm currently creating a very simple proof of concept web app which will have its client parts rebuilt by competent people sooner or later. But in the mean time I have to provide the bare-bones functionality that will serve as a rough guideline for the next team to take over, whenever that might be.
I've picked two libraries that each seem easy to use and get the job done, when used separately. But when I try to use them together on the same page, I run into a problem: they both use the same name for their main type, and I can't seem to disambiguate between them.
These are the libraries:
JSON Editor
JSON Schema Form Builder
They both declare a type named JSONEditor, which I can use as long as I don't reference both of the libraries at once.
So far I've tried to solve this by using modules and import-ing the type using different names, but it didn't work... I got a bunch of errors in the console about "import not found" and "e is not defined", which makes me think I'm tackling this wrong.
How would I solve this using plain JS if possible?
UPDATE: As suggested, I'm providing a minimal example that demonstrates my use:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Page</title>
<link href="/lib/jsoneditor/jsoneditor.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<div id="editor" style="width: 300px; height: 200px;"></div>
<div id="form"></div>
</div>
<!--library 1: https://github.com/josdejong/jsoneditor -->
<script src="/lib/jsoneditor/jsoneditor.min.js"></script>
<!--library 2: https://github.com/jdorn/json-editor -->
<script src="/lib/jsonform/jsonform.min.js"></script>
<script>
// Library 1: The JSON code editor.
var editor = new JSONEditor(document.getElementById("editor"), { mode: "code" });
// Library 2: The form builder.
var form = new JSONEditor(document.getElementById("form"), {
ajax: true,
schema: {
$ref: "/api/describe/service/test"
}
});
</script>
</body>
</html>
If I comment out the use of one library (whichever), the other works as expected and the content is displayed at the respective target <div>. But if I try both at once, as shown above, nothing is displayed, and the following error is output to console:
Uncaught TypeError: t is undefined
This happens at the var editor = new JSONEditor line, which makes me think that the type from the second library overwrites the first and causes the problem.
This is understandable to me and isn't the issue per-se. The issue is that I don't know how to import the two JSONEditor types so that they can be referenced separately.
The maintainer of the code editor (JSON Editor, not JSON Schema Form Builder) has addressed and closed an issue about exactly this in the past: https://github.com/josdejong/jsoneditor/issues/270
His recommended solution is something like the following:
<script src="assets/jsoneditor/dist/jsoneditor.min.js"></script>
<script>
var JSONEditorA = JSONEditor;
</script>
<script src="assets/json-editor/dist/jsoneditor.min.js"></script>
<script>
var JSONEditorB = JSONEditor;
</script>
If you must use script tags this is probably the way to go.
I would like to use i18n and i10n in my Angular app.
If I understood correctly I can inject a script into my index.html and the changes regarding the language will change on the fly. I tested it and it works when I added manually the script and refresh the page.
Unfortunately, I am trying to inject the script for the right language on the fly.
I created a button and I want to add Portuguese language script on the click button.
app.controller('appController', ['$scope', '$route', 'UserTopBarWidget',
function($scope, $route, UserTopBarWidgetService){
$scope.topBarWidget = UserTopBarWidget;
$scope.topBarWidget.loadTopBarWidget();
}
}]);
In this file I just load the service I created called UserTopBarWidget.
The UserTopBarWidget:
app.service('UserTopBarWidgetService', function($http){
this.loadTopBarWidget = function(){
//loading something
};
this.loadPortugueseLanguage = function(){
var locale = "pt-pt";
$.getScript("https://code.angularjs.org/1.2.16/i18n/angular-locale_" + locale + ".js");
}
});
I have a page html called index.html and inject to it my html files:
index.html:
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="../common/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="../common/css/style.css" />
<title></title>
</head>
<body ng-controller="AppCtrl">
<div id="container" ng-view></div>
</body>
</html>
The injected html:
<button type="button" id="searchButton" class="btn btn-default" ng-click="topBarWidget.loadPortugueseLanguage()">Portugese</button>
<h2>{{date | date: 'fullDate' }}</h2>
<h2>{{money | currency}}</h2>
The answer I get :
Tuesday, June 10, 2014
$500.00
I would like to see it in Portuguese.
What am I doing wrong?
Question
There is no way in pure angular to dynamically change locale so far, you can only do it on bootstrap level but there is a few projects that implement this functionality. This one is particularly good IMHO
https://github.com/lgalfaso/angular-dynamic-locale
There are two possible solutions to your problem really.
One is to use angular-dynamic-locale as #maurycy already explained. It's not the cleanest solution I can think of, but it's better than nothing.
The other possible solution is to create your own using other specialized i18n library like iLib for example.
Why would you ever want to do that?
Well, built-in AngularJS i18n routines does not allow for handling other calendars, time zones and formatting percents. These are serious drawbacks. The fact, that you cannot override a Formatting Locale based on user profile (or you can, but forgot about web site caching) is another.
I recommend using custom iLib-based solution (I used to recommend Globalize but after recent changes it seems a bit useless) combined with angular-translate for User Interface translation and built-in angular-locale for handling plural forms (at the time of writing angular-translate does not handle it particularly well).
As a proof of concept I would like to show the some Qooxdoo widgets (which i find pretty nice) in a very simple index.html file.
Here I try to show a button :
<head>
<title>Title</title>
<script type="text/javascript" src="http://demo.qooxdoo.org/3.5/framework/q-3.5.min.js"></script>
<script>
var button = new qx.ui.form.Button("Hello...");
this.getRoot().add(button, {left: 30, top: 20});
</script>
</head>
If I run the above I get this :
Uncaught ReferenceError: qx is not defined
Is my library link correct? Or is it even possible to link qooxdoo javascript in a HTML file? We already have a large established javascript application, and we would like to just drop in qooxdoo widgets that we like. Not sure if that is possible though.
You are including the qx.Website library and try to use qx.Desktop widgets. That ain't gonna work. Either you choose qx.Desktop and use the inline app approach [1] or you use the qx.Website widgets [2].
[1] http://manual.qooxdoo.org/current/pages/development/skeletons.html#inline
[2] http://demo.qooxdoo.org/devel/website-api/index.html#Accordion
I am currently switching a plugin from TinyMCE 3.x to the new version TinyMCE 4.0.26. I encountered heavy problems when trying to internationalize my plugin labels.
Within my plugin.js, I am loading the language pack by calling
tinymce.PluginManager.requireLangPack('myplugin');
with my i18n file langs/de.js looking something like this:
tinyMCE.addI18n('de', {
myplugin: {
button : 'Link einf\u00FCgen/bearbeiten',
title : 'Link einf\u00FCgen/bearbeiten'
}
});
When I access the the static context
tinymce.i18n.data.myplugin
I can see that both variables button and title are available.
THE PROBLEM:
When calling editor.getLang('myplugin.button') I get {#myplugin.button} instead of the appropriate variable value.
After I investigated the source code a little bit, I found out that it expects the language code to exist within the tinyMCE.i18n.data....., which is not available
getLang: function(name, defaultVal) {
return (
this.editorManager.i18n[(this.settings.language || 'en') + '.' + name] ||
(defaultVal !== undefined ? defaultVal : '{#' + name + '}')
);
},
#see https://github.com/tinymce/tinymce/blob/4.0.26/js/tinymce/classes/Editor.js#L1105
Have I done something wrong? Has anyone created a plugin for the new TinyMCE version and managed to get the internationalization working?
Thanks to everyone, who tried to help me out on this. Unfortunately I could not make my plugin work with translated labels in the popup window, but finally found a solution.
Everything below works perfectly okay and easy in TinyMCE version 4.2.6.
Here the steps to make everything work with a plugin named example:
Create your plugin directory at plugins/example
Create the required plugin JS file plugins/example/plugin.min.js ( take a look at the example http://pastebin.com/jEARrtWN ) - As #msqar recommended I added the requireLangPack call right before my plugin function.
Now create your translation files ( Please replace de_AT by your language code ) at langs/de_AT.js and plugins/example/langs/de_AT.js
tinymce.addI18n('de_AT', {
'Title': 'Titel',
'Example plugin': 'Beispielplugin'
});
All the ( in my example ) english labels are automatically translated to de_AT when setting up TinyMCE like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<body>
<textarea name="test"></textarea>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="tinymce/tinymce.min.js"></script>
<script>
jQuery(document).ready(function ($) {
$('textarea').tinymce({
theme: "modern",
plugins: 'example',
toolbar: 'example',
language:'de_AT'
});
})
</script>
</body>
</html>
The result
When opening the dialog using the button inside the toolbar, the window title Example plugin is automatically translated to Beispielplugin
NO special calls to editor.getLang required.
I hope this guide works for other developers around here too. I would appreciate any positive or negative feedback.
Thanks a lot to all the developers here at #stackoverflow.
You can use the following to directly access the right strings:
tinymce.EditorManager.i18n.data[ed.getParam('language') + '.myplugin_name']['my_key'];
I finally made it work, maybe it can help, this is 1 year old though, but can help others.
Since the entire way of creating a plugin changed from 3.X to 4.X, the requireLangPack i was adding to my plugin was in an incorrect location.
I was doing:
tinymce.PluginManager.add('myplugin', function(editor, url) {
tinymce.PluginManager.requireLangPack('myplugin');
...
});
When it should be:
tinymce.PluginManager.requireLangPack('myplugin');
tinymce.PluginManager.add('myplugin', function(editor, url) {
...
});
Also, the way I accessed those variables was:
editor.getLang("myplugin").title;
Instead of
editor.getLang("myplugin.title");
Hope it works for other people under the same circumstance.
I realize you are coming up with a way for panels to communicate. Until that time, I was thinking I could get some basic communication going with a preference object.
But how do I find a unique ID for the dashboard where an app resides?
In case there might be a better solution than sharing info via a preference object, let me describe the specific problem we want to solve: Certain projects within our project structure represent "programs" for which we want to display a "metrics dashboard"-- that dashboard would consist of multiple apps on a shared dashboard. But programs are not at consistent levels in the rally project hierarchy, and we only have about four programs though we have many many rally projects.
Because of this, I'd like this code metrics dashboard to be one page in Rally, which can easily switch between the various programs we have. I would prefer not to use the project hierarchy to do this, because we have a lot of projects, and its time consuming and tricky to find and select the programs.
I hacked at the sample to create an example of an app that can pass events between two panels.
This is very unsupported at this time and we reserve the right to break it whenever we want without any warning.
That being said you can see the current unsupported way to get an Apps ID and if you make two copies of this App you can see in your console the results of the Apps communicating on the global Rally message bus.
You can find the gist of it here
<!DOCTYPE html>
<html>
<head>
<title>My Custom App</title>
<!--Include SDK-->
<script type="text/javascript" src="/apps/2.0p/sdk.js"></script>
<!--App code-->
<script type="text/javascript">
Rally.onReady(function() {
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
mixins:['Rally.Messageable'],
launch: function() {
var brokenInTheFutureIdThatWillWorkForNow = Ext.Object.fromQueryString(window.location.href);
window.parent.Rally.Messages.subscribe("test",function(){console.error(brokenInTheFutureIdThatWillWorkForNow.panelOid,arguments);});
window.parent.Rally.Messages.publish("test",brokenInTheFutureIdThatWillWorkForNow.panelOid);
//Write app code here
}
});
Rally.launchApp('CustomApp', {
name: 'My Custom App'
});
});
</script>
<!--App styles-->
<style type="text/css">
.app {
/* Add app styles here */
}
</style>
</head>
<body class="myApp">
</body>
</html>