Open multiple tab creating function in controller in angularjs - angularjs

my controller function is :-
vm.selectSales = function () {
var url = "";
if ($scope.selection.length > 0) {
for (var i = 0, len = $scope.selection.length; i < len; i++) {
url=($state.href('work-area', { 'saleId': $scope.selection[i] ;
window.open(data, '_blank');
$window.location.reload();
}}};
According to this, i want to open multiple tab, but only one tab is open. Please suggest me a way to open multiple tab with different sale id.

After searched a lot i found that code is fine, i.e. below code work perfectly :-
vm.selectSales = function () {
var url = "";
if ($scope.selection.length > 0) {
for (var i = 0, len = $scope.selection.length; i < len; i++) {
url = ($state.href('work-area', { 'saleId': $scope.selection[i] }));
window.open(url, '_blank');
}}
};
But it is not work due to chrome popups setting its not work.
Now, to work with this code, i need to change my chrome setting :-
Click on Setting----->Advanced Setting----->Content Settings----->allow all sites to show popups.
Thanks to all.

For starters you didn't close $state.href's second parameter.
Also, ¿why are you doing a location.reload inside the for? It will reload the main page on execution, making it impossible for you to do what you want.
If window.open(url, '_blank') really opens a tab, you could give this a go:
vm.selectSales = function () {
var url = "";
if ($scope.selection.length > 0) {
for (var i = 0, len = $scope.selection.length; i < len; i++) {
url=($state.href('work-area', { 'saleId': $scope.selection[i]};
window.open(data, '_blank');
}
$window.location.reload();
}
};
Having serious doubts on the location reload though .

Related

Is it possible to show gradients with react-svgmt?

I would like to use react-svgmt to manipulate SVG's. These SVG's can be uploaded from the users. My problem is, that if the SVG has a gradient these parts of the SVG are not shown.
Has anybody a solution for my problem to reactivate these links after the import of the SVG via react-svgmt?
With the developertools of my browser I was be able the see that the elements are in the code, but the grandients will be linked to the elements and these links are broken.
I have seen that other people has the same problem with gradients and created an issue on github, but the developer did not respond.
I found a solution for my problem.
react-svgmt add to elements like linearGradients "-{nr}" to its id-names. Then this fill:url(#linear-gradient-2); does not work anymore in the style-tags, because it must be fill:url(#linear-gradient-2-{nr});.
So the first SVGProxy after loading is <SvgProxy selector="linearGradient" onElementSelected={handleGradients} ></ SvgProxy>
an the function handleGradients looks like following and saves the {nr}
const handleGradients = (gradients) => { if (typeof gradients.length !== 'undefined') { const output = gradients.map((g, i) => { nr = g.id.substring(g.id.lastIndexOf("-")+1); setNr(g.id.substring(g.id.lastIndexOf("-")+1)); if(g.href.baseVal.length > 0) { var base = g.href.baseVal; g.href.baseVal = base + '-' + nr; } return g; }); } else { nr = gradients.id.substring(gradients.id.lastIndexOf("-")+1); setNr(gradients.id.substring(gradients.id.lastIndexOf("-")+1)); if(gradients.href.baseVal.length > 0) { var base = gradients.href.baseVal; gradients.href.baseVal = base + '-' + nr; } } };
Then I had another SVGProxy
<SvgProxy selector="defs > style" onElementSelected={handleStyleElem} ></ SvgProxy>
with the following handlefunction which replaces all urls with the schema from above
const handleStyleElem = (svgStyle) => { var styleStr = svgStyle.outerHTML; styleStr = styleStr.replaceAll(/url\(#((\w|-)*)\);/g, 'url(#$1-'+ nr +');'); svgStyle.outerHTML = styleStr; };

AngularJS - Delete check box is not working correctly and only deleting one at a time

I've written out a block of code that allows the user to check or uncheck entities that will be added or removed via web services. My add function seems to be working correctly and provides the ability to add multiple entities. However, my delete function isn't working the same. It doesn't delete each time, and can only delete one at a time. I'm struggling since the code is effectively the same as the add, so I don't know if the issue is AngularJS related or perhaps my web service isn't working correctly.
Edit: I've actually noticed that the for loop goes through it all but doesn't select the correct id, it always starts from the first one.
var toDeleteService = [];
for (var i = 0; i < $scope.siteServices.length; i++) {
if ($scope.siteServices[i].chosen != $scope.siteServices[i].origChosen) {
if ($scope.siteServices[i].chosen == true) {
toAddService.push(i);
}
else {
toDeleteService.push(i);
}
}
}
if (toDeleteService.length > 0) {
var deleteRequest = {};
deleteRequest.services = [];
for (var i = 0; i < toDeleteService.length; i++) {
var parentServiceName = $scope.siteServices[i].parentServiceName;
var j = 0;
for (; j < deleteRequest.services.length; j++) {
if (deleteRequest.services[j].parentServiceName == parentServiceName) {
break;
}
}
if (j == deleteRequest.services.length) {
deleteRequest.services[j] = {};
deleteRequest.services[j].parentServiceName = parentServiceName;
deleteRequest.services[j].subservices = [];
}
var service = {};
service.serviceId = $scope.siteServices[i].serviceId;
deleteRequest.services[j].subservices.push(service);
}
var deleteUrl = "api/sites/" + $scope.targetEntity.siteId + "/services/" + service.serviceId;
$http.delete(deleteUrl)
.then(function (response) {
});
}
As I understood it you are trying to remove siteServices based by numbers stored in var toDeleteServices = [] so you need to access those numbers by its index. but in service.serviceId = $scope.siteServices[i].serviceId; you are using i instead.
service.serviceId = $scope.siteServices[toDeleteServices[i]].serviceId; as you need actual number of the service to delete.
If I understood your code correctly.

Code works in Plunkr but not when outputting from my editor

I have made a custom filter to filter a list with multiple criteria on one column.
I have made this plunk
var app = angular.module('main', ['angular.filter'])
.filter('filterIns', function() {
var obj = {};
return function(list, ins) {
var out = [];
for (var i = 0; i < list.length; i++) {
if (ins.indexOf(list[i].instrument) > -1) {
obj = list[i];
out.push(obj);
}
}
if (ins.length === 0) {
out = list;
}
return out;
};
})
[...]
Everything is working as expected. However when I copy this code to my localhost environment I get this nasty, (general?) error: 'undefined is not an object (evaluating 'list.length')' referring to line 11.
Why is it working perfectly in Plunkr but not on localhost?
Can anybody tell me?
Is your list loaded async or something? Clearly it is undefined when the filter runs for the first time. So just place a condition before line 11, like:
if (!list) { return []; }
// or
if (!list) { return undefined; }
// or even better
if (!list) { return list; } // this keeps things like 0, undefined or null intact
and you should be safe.

KendoUI Treeview with AngularJS uncheck checkboxes

I'm using KendoUI (v2015.1.318) with AngularJS (v1.3.14). After every click on a node, the data will be fetched from an API.
After selecting some items and clicking on the button "add", the items will be added in a seperated list, the expanded treenodes must stay visible but all the
checked items must be unchecked.
After I iterated through the datasource to uncheck the checked items , I have call SetDataSource again. When I have expanded a lot of nodes and checked a few, the UI freezes some seconds while it's processing.
I was wondering if there wasn't a more efficient way to execute this.
I made an example without API call:
$scope.saveTreeFields = function () {
var data = $scope.tree.dataSource._data;
for (var i = 0, j = data.length; i < j; i++) {
checkChildren(data[i]);
}
function checkChildren(data) {
if (data.checked) {
data.checked = false;
}
if (data.items !== undefined) {
for (var i = 0, j = data.items.length; i < j; i++) {
checkChildren(data.items[i]);
}
}
}
$scope.tree.setDataSource(data)
};
Plunker example
Received an answer from Telerik itself.
you can call the dataItem set("checked", false) method to notify the
model of the field change, and the TreeView will update automatically.
Code changes
$scope.saveTreeFields = function () {
var data = $scope.tree.dataSource.data();
for (var i = 0, j = data.length; i < j; i++) {
checkChildren(data[i]);
}
function checkChildren(data) {
if (data.checked) {
data.set("checked", false);
}
if (data.items !== undefined) {
for (var i = 0, j = data.items.length; i < j; i++) {
checkChildren(data.items[i]);
}
}
}
};

Get Count of selected files in Telerik Upload

I need to get a count of all selected files using Telerik MVC Upload Control. Can anyone tell me how can i do that. I tried code like this.
var count = e.files.length;
But its counting always as one.
try this code
[function onSelect(e) {
var selectedFiles = e.files.length;
totalFiles += selectedFiles;
}
function UploadRemove(e) {
totalFiles--;
if (totalFiles > 0) {
// Write true block code here.
}
else if (totalFiles == 0) {
// Write your false block code here.
}
}]
You could do this in your upload event handler:
upload: function (e) {
// File Count:
var fileCount = this.wrapper.find(".k-file").length;
// File Index:
var uid = e.files[0].uid;
var file = this.wrapper.find(".k-file[data-uid='" + uid + "']");
var fileIndex = file.index();
}

Resources