Issue opening an Abp Modal that has scripts inside, it clear the below page - abp

I have a strange issue with Abp.Io and opening a modal that has a script file inside (which loads data). The issue is that is clears the below grid. I've understood that the problem is with the Layout = null of the modal.
Here's what's happening.
Modal with Layout not null: (so it takes the scripts section):
Then I click the lens
You see the popup opens and load data correctly (now they're mocked), but below the Grid disappeared.
Instead if I put the layout of the modal to null:
You see in this case that it keep the grid below , but It doesn't load any data (since I think it doesn't know what to do with #script section.
Here's my modal:
#page
#using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
#model IlDiamante.Web.Pages.Shared.MetalliUtilizzatiInSemilavoratiModel
#{
Layout = null;
string headerName = $"Semilavorati che utilizzano il metallo '{Model.NomeMetallo}'";
}
#section scripts
{
<abp-script src="/Pages/Shared/MetalliUtilizzatiInSemilavorati.js" />
}
<input id="metalloGuid" hidden="true" value="#this.Model.Id"/>
<abp-modal>
<abp-modal-header title="#headerName"></abp-modal-header>
<abp-modal-body>
<abp-table striped-rows="true" id="SemilavoratiTable"></abp-table>
</abp-modal-body>
<abp-modal-footer buttons="#(AbpModalButtons.Close)"></abp-modal-footer>
</abp-modal>
Any advice?
Thanks

Layout should be null for modals, there is no problem there. However, if you want the script to be loaded, you must declare it where you opened the modal.
For instance:
When opening the modal, you need to specify a modal class as below:
var productInfoModal = new abp.ModalManager({
viewUrl: '/Products/ProductInfoModal',
modalClass: 'ProductInfo' //Matches to the abp.modals.ProductInfo
});
Then the modal class you specify should match inside your modal script as in the code below:
abp.modals.ProductInfo = function () {
function initModal(modalManager, args) {
// your logic
};
return {
initModal: initModal
};
};
Then add the modal to the script of the page you opened as follows:
#section scripts{
<abp-script-bundle>
<abp-script src="/Pages/Products/ProductInfoModal.js"/> // modal script
<abp-script src="/Pages/Products/Index.js"/> // page script
</abp-script-bundle>
}
For more information see here: https://docs.abp.io/en/abp/latest/UI/AspNetCore/Modals#modals-with-script-files
Since script files are loaded while opening the page, it is normal that it does not work even if you declare the script in the modal.cshtml(ProductInfo.cshtml) file. However, you can still use lazy load if you want. For that, I recommend you look here.

Related

Ask to confirm when changing tabs in angular bootstrap

I have tabs with forms and I want ask the user to confirm or discard their changes when changing tabs. My current code works
<uib-tab heading="..." index="3" deselect="main.onDeselect($event)" ... >
this.onDeselect = function($event) {
if(...isDirty...) {
if($window.confirm("Do you want to discard?")) {
... discard (and go to new tab) ...
} else {
$event.preventDefault(); //stays on current tab
}
}
}
The problem is I want to change confirm to javascript dialog and I will get result in callback.
I planed to preventDefault() all and then switch manually, but I cannot figure out where to get new tab id.
Any solution is appreciated. Even if it is easier in other tab implementations.
I use AngularJS v1.4.7, ui-bootstrap-tpls-1.3.3.min.js
You can make use of $selectedIndex and the active property for that purpose. See this Plunk
One thing to be noted here is that when we manually change the active property, it again fires the deselect event which needed to be handled. Otherwise it seems to do what you wanted.
Edit
Indeed as noted in the comments, the deselect carries the HTML index rather than what is passed in in the tab index property. A workaround could be in this: Another Plunk. Here I'm pulling the actual index from the HTML index.
And a little research indicates that this issue might as well be fixed already with 3.0 bootstrap tpl See this.
I spent some time with different approaches and this one is stable for some time. What I do is to prevent deselect at the beginning and set the new tab in callback if confirmed to loose changes...
this.onDeselect = function($event, $selectedIndex) {
var me = this;
if(this.tabs.eventDirty || this.tabs.locationDirty || this.tabs.contractDirty) {
$event.preventDefault();
var alert = $mdDialog.confirm({
title: 'Upozornění',
textContent: 'Na záložce jsou neuložené změny. Přejete si tyto změny zrušit a přejít na novou záložku?',
ok: 'Přijít o změny',
cancel: 'Zůstat na záložce'
});
$mdDialog
.show( alert )
.then(function() {
$rootScope.$emit("discardChanges");
me.tabs.activeTab = $selectedIndex;
})
}
};

how can I load a joomla module as a link?

this is my problem...
I have some of images and links that I want to load different joomla modules when user click on them.
mean each hyperlink can load another module|position
thanks all
In case that you just want to call a module's content from a url the following answer will help you.
If you just want to show / hide a module in the same page you could use something similar to my previous answer: Joomla 3 Show different modules on same position depending on toggler
Joomla provides the functionality to call a specific file of the active template by adding the tmpl=FILENAME key/value to the url's query string.
All built-in templates have a component.php file if user wants to load the template with the component only. You could check the following link for more details: Adding print pop-up functionality to a component.
You could do something similar to only show the modules that you want to load.
You could copy the component.php to a new file (I have used custom.php) and added the following php code in the <body> ... </body> part.
<?php
$jinput = JFactory::getApplication()->input;
$selectedPosition = $jinput->getString("position", "");
$selectedModule = $jinput->getString("module", "");
$selectedModuleTitle = $jinput->getString("title");
if($selectedPosition !== "") {
$modules = JModuleHelper::getModules($selectedPosition);
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module);
}
} elseif ($selectedModule !== "") {
$module = JModuleHelper::getModule($selectedModule, $selectedModuleTitle);
echo JModuleHelper::renderModule($module);
}
?>
So with a similar way as loadposition / loadmodule works you could call the new template file using:
index.php?tmpl=custom&position=MODULE_POSITION
or
index.php?tmpl=custom&module=MODULE_TYPE
or
index.php?tmpl=custom&module=MODULE_TYPE&title=MODULE_TITLE
Optionally if you want to load the module with a specific style, you could pass it to the second paramter of the renderModule method like:
echo JModuleHelper::renderModule($module, array("style" => "xhtml"));
Hope this helps

Removing a fMath image properties dialog in ckeditor

I am a bit stuck with this so it would be great if you could help.
I am using Drupal 7 and Ckeditor 4.3. I am developing a site which has fmath equation editor integrated.
I have disabled the image button, as I don't want end users being able to upload their own images. On the other hand, users can use fMath to insert equations. The way fMath handles equation insertion is by inserting a img tag.
When users double click this image or when they right click over the image, they access the image properties dialog, where they can change source url of the image and few other things. On the url input text, they could change the source of the image so that they could insert their own images on the page, which is something I don't want.
The have been working with two different unsuccessful approaches until now trying to solve this problem:
Removing elements from the dialog, as the URL input text on the dialog (and the alt text as well).
Trying to disable the dialog itself.
I'd like to use a custom plugin to accomplish the desired behavior as I have different CKeditor profiles in Drupal.
I haven't been successful. Do you know how could I handle this undesirable behavior?
Ok, I ended up with something like this in the plugin.js file:
CKEDITOR.plugins.add( 'custom_doubleclick',
{
init: function( editor )
{
// First part, dialogDefinition allow us to remove the
// "Link" and "Advanced" tabs on the dialog
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if ( dialogName == 'image' ) {
dialogDefinition.removeContents( 'Link' );
dialogDefinition.removeContents( 'advanced' );
}
});
// Second part, it disables the textUrl and txtAlt input text boxes
editor.on( 'dialogShow', function( ev ) {
var dialog = ev.data;
var dialogName = dialog.getName();
if ( dialogName == 'image' ) {
//var dialog = CKEDITOR.dialog.getCurrent();
// Get a reference to the Link Info tab.
console.log(dialog)
dialog.getContentElement( 'info','txtUrl' ).disable();
dialog.getContentElement( 'info','txtAlt' ).disable();
}
});
}
});
As you can see I didn't disable the dialog itself, but the non useful elements. I hope this can help to someone else.

How to open a VF page as popup and pass parameters to that VF page?

I have a VF page which has 2 date fields and search button.
On click of search i get some results. i also have another button to print those results which is nothing but a new VF page rendered as pdf.
I want to pass this date values into the printVF page. i also want to have this page come up as popup.
I have the pageref with parameters set. Since i need to open this page as popup i need to find a way to use the pageref in the window.open.
Anybody has ideas on how to accomplish this?
Thanks
Prady
EDIT :What i did was build the url in the controller and use the controller variable in window.open. Something very strange is happening... The first time search results are displayed and i click the print button, the dates dont get populated in the string, they default to todays date.. if i again click the print button the dates are populated correctly on the url from the dateinput.
public Class1(){
System.debug('inside constructor');
fieldContainer=new DummyTable__c(); // it contains date fields for date inputs
date todays=date.today();
If (fieldContainer.Start_Date__c== null)
{
startdate1=todays;
}else
{
startdate1=fieldContainer.Start_Date__c;
}
If (fieldContainer.End_Date__c== null)
{
enddate1=todays;
}
else
{
enddate1=fieldContainer.End_Date__c;
}
}
public void search()
{
startdate1=fieldContainer.Start_Date__c;
system.debug('startdate1'+startdate1);
enddate1=fieldContainer.End_Date__c;
system.debug('enddate1'+enddate1);
system.debug('inside search()....after clicking search button');
system.debug('startdate1'+startdate1);
system.debug('url'+url);
LoadData();
}
public string geturl()
{
url='apex/VF1?Pstartdate='+string.valueof(startdate1)+'&Penddate='+string.valueof(enddate1);
return url;
}
public string geturlRec()
{
urlRec='apex/VF2?Pstartdate='+string.valueof(startdate1)+'&Penddate='+string.valueof(enddate1);
return urlRec;
}
VF Page
<script language="javascript" type="text/javascript">
function printOut()
{
window.open("{!url}");
}
function printIn()
{
window.showModalDialog("{!urlRec}","dialogWidth:800px; dialogHeight:200px; center:yes");
}
</script>
<div style="width:900px;margin:0 auto;" id="pagediv">
<span style="padding-left:30px;padding-right:10px">From </span><apex:inputfield value="{!fieldContainer.Start_Date__c}" id="startdt" style="padding-left:5px;padding-right:20px;"/>
<span style="padding-left:30px;padding-right:10px">To </span><apex:inputfield value="{!fieldContainer.End_Date__c}" id="enddt" style="padding-left:5px;padding-right:20px;"/>
<span style="padding-left:30px;padding-right:10px"><apex:commandButton action="{!search}" value="Search" ReRender="dtshipdep,dtshiprec,shippageblock"> </apex:commandButton></span>
<apex:commandButton action="{!saveDeparted}" value="Update " ReRender="dtshipdep"></apex:commandButton>
<apex:commandButton value="Print " onclick="printOut();"></apex:commandButton>
The salesforce recommended way to generate URLs is through URLFOR() function. Or, alternatively, you can create a PageReference in the extension/controller code.
Though, keep in mind, before any form data can become part of the URL it has to be posted to the server and come back in newly generated pageReference, for that reason you cannot jut click on it in the first run.
One way I used to solve this server side is using this code on VF
<apex:outputBlock rendered="{!openPopup}">
<script>
window.open('{!myTargetUrl}');
<script>
</apex:outputBlock>
openPopup is a bool that control whether this segment gets rendered (transient, you set it to true when you click on open button). myTarget is a PageReference based URL (alternatively you can use URLFOR here to generate URL in VF). If you have any more questions, ask.
Another option is to have your javascript code in VF which will pickup button click event and build the URL client side and open it up. You can use $Component to locate form fields.
You should be able to pass the values you need in the QueryString.
window.open("/apex/YourPage?VariableName=Value&SecondVariableName=SecondValue");
Then once you have the variables send to the new page, you can get them using a PageReference.
String myVariable = PageReference.getParameters().get('VariableName');

bread crumbs for views drupal 7

Am working with views and am wondering if there is a way to get the view to update the breadcrumb trail. When on my first view called homme the breadcrumbs are not updated it still just says "home >" as if it is still on the homepage. When I click a post the breadcrumbs update to "Home › Blogs › admin's blog › ". I need it to say Home > Homme > Name of Article, basically what you would expect when going to a blog site or post.
Can I get the view to act like a blog?
One option is to try overriding the themeable output generated by the default breadcrumb function.
Assuming you've created your own theme - create a file called template.php at the root of your theme. Create a function named YOURTHEME_breadcrumb, where YOURTHEME is the name of the theme. The HTML returned by this function will be the breadcrumb. Modify the return values as necessary here to get what you want. Consider using Drupal's menu functions to build a more satisfactory breadcrumb.
Check the comments of this API article for more detail: http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_breadcrumb/7
Adding this to your template.php file should work with d7 sites:
function theme_breadcrumb($breadcrumb)
{
if (substr($_GET['q'], 0, 13) == 'news/category') {
$breadcrumb[] = l('News', 'news/');
}
if (count($breadcrumb) > 1) {
if ($breadcrumb) {
return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) ."</div>\n";
}
}
}

Resources