I load the WebContent edit portlet on a Popup window using the following code:
<liferay-ui:icon
image="edit"
label="true"
message="news-edit-url"
url="${oneNews.newsEditUrl}"
/>
editUrl:
taglibEditURL = "javascript:Liferay.Util.openWindow({dialog: {width: 960}," +
"id: '" + renderResponse.getNamespace() + "'," +
"title: '" + LanguageUtil.format(request.getLocale(), "edit-x", HtmlUtil.escape(assetRenderer.getTitle(request.getLocale()))) + "'," +
"uri:'" + HtmlUtil.escapeURL(editPortletURLString) + "'});";
When the content is saved or published, the portlet is loaded on the popup window. I want the popup window to close and the portlet with the editURL link to refresh.
Any help regarding this...
Here is the code to close the pop-up, this should be present in the parent page which opens the pop-up:
Liferay version 6.1
Liferay.provide(
window,
'<portlet:namespace />closePopup',
function(popupIdToClose) {
var A = AUI();
A.DialogManager.closeByChild('#' + popupIdToClose);
},
['aui-base','aui-dialog','aui-dialog-iframe']
);
Liferay version 6.2
Liferay.provide(
window,
'<portlet:namespace/>closePopup',
function(popupIdToClose) {
var popupDialog = Liferay.Util.Window.getById(popupIdToClose);
popupDialog.destroy();
},
['liferay-util-window']
);
Here is the code to refresh the portlet which opened the pop-up. This should be present in the parent page which opens the pop-up:
Liferay.provide(
window,
'<portlet:namespace />refreshPortlet',
function() {
<%-- refreshing the portlet [Liferay.Util.getOpener().] --%>
var curPortletBoundaryId = '#p_p_id<portlet:namespace />';
Liferay.Portlet.refresh(curPortletBoundaryId);
},
['aui-dialog','aui-dialog-iframe']
);
It is up to you how to call the closePopup & refreshPortlet functions. One way is you can let the pop-up refresh and call the closePopup function from the pop-up itself only when the request is successfully processed and then call the refreshPortlet function also from the pop-up.
Here is a code-snippet which would help you to call parent-page functions from the pop-up:
Liferay.Util.getOpener().<portlet:namespace />closePopup(popupIdToClose);
Liferay.Util.getOpener().<portlet:namespace />refreshPortlet();
The popupIdToClose is the same id which is used when opening the pop-up as shown:
taglibEditURL = "javascript:"
+ Liferay.Util.openWindow({"
+ "dialog: {width: 960},"
+ "id: '" + renderResponse.getNamespace() + "'," // This is the "popupIdToClose"
+ "title: '" + LanguageUtil.format(request.getLocale(), "edit-x", HtmlUtil.escape(assetRenderer.getTitle(request.getLocale()))) + "',"
+ "uri:'" + HtmlUtil.escapeURL(editPortletURLString)
+ "'}"
+ ");";
Hope this helps.
AUI taglib solution for 6.2 version. No additional JS required.
<aui:button cssClass="close-panel" type="cancel" value="close" />
Important part is cssClass="close-panel".
Related
Is there a way to show timeRange.from and timeRange.to in Grafana's Text panel or may be in an another panel?
I tried text-panels with markdown mode:
# Time From: $__interval
with different variables but no one did work. Neither did it if I defined a variable in Settings. The interval or timestamp is not showing.
I'm currently working on an HTML solution, but wondering if there is a simplier/proper way to present the time ranges?
My HTML-solution, in case somebody faces the same issue
(got the main part from maxreb's solution from: https://github.com/grafana/grafana/issues/1909) :
<script type="text/javascript">
refreshTimeFrom();
refreshTimeTo();
angular.element('grafana-app').injector().get('timeSrv').$rootScope.$on('refresh', function(event, data) { refreshTimeFrom(); });
function refreshTimeFrom( )
{
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var ts = new Date(angular.element('grafana-app').injector().get('timeSrv').timeRange().from);
document.getElementById("timeFrom").innerHTML = days[ts.getUTCDay() ] + " "
+ ts.getUTCDate() + "." + (ts.getUTCMonth()+1) + "."
+ ts.getUTCFullYear() + " " + ts.getUTCHours() + ":"
+ ts.getUTCMinutes() + ":" + ts.getUTCSeconds();
}
function refreshTimeTo( )
{
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var ts = new Date(angular.element('grafana-app').injector().get('timeSrv').timeRange().to);
document.getElementById("timeTo").innerHTML = days[ts.getUTCDay() ] + " "
+ ts.getUTCDate() + "." + (ts.getUTCMonth()+1) + "."
+ ts.getUTCFullYear() + " " + ts.getUTCHours() + ":"
+ ts.getUTCMinutes() + ":" + ts.getUTCSeconds();
}
</script>
<font size = "3"><b> From:</b> <span id="timeFrom" /></br></font>
<font size = "3"><b> To: </b> <span id="timeTo" /> </font>
Using the following code opens InAppBrowser. I would like to open the other browsers like Chrome and anything that comes with Android.
var data = '<form id="Form" action="http://www.example.com/api/form/" method="post">' +
'<input type="hidden" name="firstname" value="' + firstname + '">' +
'<input type="hidden" name="lastname" value="' + lastname + '">' +
'</form><script type="text/javascript">document.getElementById("Form").submit();</script>';
var pageContentUrl = 'data:text/html;base64,' + btoa( pageContent );
let browser = new InAppBrowser(data, '_blank', 'hidden=no,location=no,clearsessioncache=yes,clearcache=yes');
var ref = cordova.InAppBrowser.open(url, target, options);
target: The target in which to load the URL, an optional parameter that defaults to _self. (String)
_self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
_blank: Opens in the InAppBrowser.
_system: Opens in the system's web browser.
So therefore, your code with _system should do what you want
let browser = new InAppBrowser(data, '_system', 'hidden=no,location=no,clearsessioncache=yes,clearcache=yes');
You should read the documentation
How can I integrate FusionChart in my SPA application developed using MVVM architecture, Durandal and Knockout.js? I had created a simple HTML file, with hard coded data, in which the charts are working fine but I am not able to figure out how can I embed this code with my SPA Application.
I am sharing some details:
I have added following Js file in my HTML file :
<script type="text/javascript" src="./FusionCharts.js"></script>
<script type="text/javascript" src="./jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="./lib.js"></script>
My HTML file code in which fusion chart is rendered successfully is as follows :
<div id="chartdiv" align="center">Chart will load here</div>
<script type="text/javascript">
var chart = new FusionCharts("Column3D", "myChartId", "300", "200");
chart.setXMLData("<chart animation='0' caption='Aging' numberPrefix='$' showBorder='1'>" +
"<set label='Current' value='24000' color='00FF00' />" +
"<set label='30+' value='19600' color='0000FF' />" +
"<set label='60+' value='15700' color='FFFF00'/>" +
"<set label='90+' value='14400' color='FF0000' />" +
"<styles>" +
"<definition>" +
"<style name='myCaptionFont' type='font' align='right'/>" +
"</definition>" +
"<application>" +
"<apply toObject='Caption' styles='myCaptionFont' />" +
"</application>" +
"</styles> " +
"</chart>");
chart.render("chartdiv");
</script>
I am not able to figure out what should be the code in my ViewModel.js, and view.html file to render FusionChart.
Please Help.
I developed a working demo for including FusionCharts in DurandalJS. Just copy the project to a webserver and access the app.
https://github.com/bhargav3/fcdurandal
First thing is to include fusioncharts.js which can be done using requirejs or by directly adding it in the index file. To avoid creating duplicate charts we shall check if the FusionCharts('myChartId') exists and avoid redraws.
Your viewmodel will look something like this,
define(['durandal/http', 'durandal/app'], function() {
return {
displayText: 'FusionCharts in a SPA app!',
viewAttached: function(view) {
if (typeof FusionCharts('myChartId') === 'undefined') {
$('#binder').append('<div id="chartContainer"></div>');
var myChart = new FusionCharts("Column3D", "myChartId", "400", "300", "0");
myChart.setXMLData("<chart animation='0' caption='Aging' numberPrefix='$' showBorder='1'>" +
"<set label='Current' value='24000' color='00FF00' />" +
"<set label='30+' value='19600' color='0000FF' />" +
"<set label='60+' value='15700' color='FFFF00'/>" +
"<set label='90+' value='14400' color='FF0000' />" +
"</chart>");
myChart.render("chartContainer");
}
}
};
});
Where as your view will look like
<h2 data-bind="html:displayText"></h2>
<div id="binder"></div>
main.js is the bootstrap file and you can add your routers(for navigation) there.
If your JavaScript files are added via script tags on index.html, then Fusion Charts should be available to use from your view model. There is a way to utilize require.js to dynamically load into the scope of your view model if there was a reason you don't want it globally. I didn't include that below in the view model example in order to keep it simple to demonstrate the use of viewAttached.
viewAttached (http://durandaljs.com/documentation/Hooking-Lifecycle-Callbacks/) seems to be the last method called in the lifecycle. As the documentation indicates, the method indicates when the "view is attached to the parent DOM node." This should allow you to manipulate the view as needed after binding has occurred. See also: http://durandaljs.com/documentation/Interacting-with-the-DOM/
Below is an example of using viewAttached in your view model:
define(function() {
var activate = function() {
};
var viewAttached = function() {
var chart = new FusionCharts("Column3D", "myChartId", "300", "200");
chart.setXMLData("<chart animation='0' caption='Aging' numberPrefix='$' showBorder='1'>" +
"<set label='Current' value='24000' color='00FF00' />" +
"<set label='30+' value='19600' color='0000FF' />" +
"<set label='60+' value='15700' color='FFFF00'/>" +
"<set label='90+' value='14400' color='FF0000' />" +
"<styles>" +
"<definition>" +
"<style name='myCaptionFont' type='font' align='right'/>" +
"</definition>" +
"<application>" +
"<apply toObject='Caption' styles='myCaptionFont' />" +
"</application>" +
"</styles> " +
"</chart>");
chart.render("chartdiv");
};
return {
activate: activate,
viewAttached: viewAttached
};
};
Finally, your view should contain:
<div id="chartdiv" align="center">Chart will load here</div>
I use the following code to dynamically add input fields to form, based on this source:
http://www.infotuts.com/dynamically-add-input-fields-to-form-jquery/
Here's a part of my code:
$(document).ready(function(){
var counter = 2;
$("#btnAddIngredients").click(function () {
var newIngredientsData = $(document.createElement('div'))
.attr("id", 'ingredientsData' + counter);
newIngredientsData.html('<div id="ingredientsData'+ counter + '" class="row">' +
'<div class="col-ingredients">#'+ counter + ' : <select id="ingredient'+ counter + '" name="ingredient'+ counter + '" class="selectIngredients"><select/></div>' +
'<div class="col-extra"><input type="text" name="extra'+ counter + '" id="extra'+ counter + '" size="30" maxlength="100" /></div>' +
'<div class="col-quantity"><input type="text" name="quantity'+ counter + '" id="quantity'+ counter + '" size="5" maxlength="30" /></div>' +
'<div class="col-unit"><select id="unit'+ counter + '" name="unit'+ counter + '" class="selectUnit"><select/></div>'+
'</div>');
newIngredientsData.appendTo("#ingredientsList");
counter++;
});
$(".selectIngredients").live("click",function () {
$(this).empty();
$(this).append('<option value="">Loading...</option>');
$.post("getdata.php", {what: "ingredients"},
function (data){
alert(data);
$(this).append(data);
}
,"html");
});
});
What i'm expecting is for the selected value to be populated every time I click on it But the only thing that appeared is "<option value="">Loading...</option>", which I appended first. It seems $(this).append(data) didn't do it's job. nothing is being appended. The alert(data) above it correctly displays the contents that should be appended.
If I change $(this).append(data); to $("#ingredients1").append(data); for example, the select data is loaded correctly, but not when I use $(this).append(data);
What's wrong here? Why do the appends; in the function (data){} doesn't work, while the preceding $(this).append('<option value="">Loading...</option>'); works correctly every time?
this isn't referring to the same element inside of the post closure, use a context variable:
var that = $(this);
$.post("getdata.php", {what: "ingredients"}, function (data) {
alert(data);
that.append(data);
});
$(this) in your ajax response is the window, not the <select>.
You can use the "context" setting for ajax http://api.jquery.com/jQuery.ajax/ ... and it transfer "this" to the success scope
We are using facebook iframe app in https mode, from our app we need to send an invitation to multiple friends using multi-friend selector.
But when we click on Select Friends button, it is showing blank popup. It works fine for http (non secure browsing).
"<fb:serverfbml><script type=\"text/fbml\">" +
"<fb:fbml>" +
"<fb:request-form action=\"" + (HttpContext.Current.Request.IsSecureConnection ? ConfigurationManager.AppSettings["Callback"].Replace("http://", "https://") : ConfigurationManager.AppSettings["Callback"]) + "pagename.aspx?dbskip=true&fb_sig_user=" + fbuserid + "\"" +
"method=\"POST\"" +
"invite=\"true\"" +
"type=\"My App \"" +
"content=\"" + "my content" +
"<fb:req-choice url='" + "my choice"+ "'" +
"label='" + " my text "+ "'/>" +
"\">" +
"<fb:multi-friend-selector bypass=\"cancel\" email_invite=\"false\" max=\"35\" cols=\"5\" actiontext=\"Select friends to send invitation\" rows=\"3\"/>" +
"</fb:request-form></fb:fbml></script></fb:serverfbml>";
Thank in advance......
Maybe you shouldn't use legacy FBML now. It is deprecated.