Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
loadJS: (url, async) => {
let deferred = new Deferred();
let script = document.createElement('script');
script.src = url;
script.async = async || false;
script.onload = deferred.resolve();
script.onerror = deferred.reject();
requestAnimationFrame(function () { document.getElementsByTagName('head')[0].appendChild(script); });
// let promise = new Promise((resolve, reject) => {
// let script = document.createElement('script');
// script.src = url;
// script.async = async || false;
// script.onload = resolve;
// script.onerror = reject;
// requestAnimationFrame(function () { document.getElementsByTagName('head')[0].appendChild(script); });
// });
fetch (layer, cartoId) {
const promise = new Deferred();
let url;
// If a technicalName is configured, fetch from the metadata API
// else, attempt to fetch it from the mapservice
if (layer.technicalName) {
url = `${urls.metadataApi}/${layer.technicalName}`;
getMetadataTask(url).then(results => {
_cache[layer.id] = results;
promise.resolve(results);
});
} else if (layer.itemId) {
// This commented out URL contains a good item id to use for testing
// url = urls.metadataXmlEndpoint('30e234e880c94a2ca54be9a132808eae');
url = urls.metadataXmlEndpoint(layer.itemId);
getXMLTask(url).then(xmlDocument => {
promise.resolve(reduceXML(xmlDocument));
}, () => {
getLatest (method: string) {
let deferred = new Deferred();
let qLayer;
if (method === 'changeRisk') {
qLayer = layersConfig.filter(layer => layer && layer.id === KEYS.fireWeather)[0];
} else {
qLayer = layersConfig.filter(layer => layer && layer.id === KEYS.lastRainfall)[0];
}
let queryTask = new QueryTask(qLayer.url);
let query = new Query();
query.where = '1=1';
query.returnGeometry = false;
query.outFields = ['OBJECTID', 'Name'];
// We sort by OBJECTID because we want to get the most recent image as the first returned feature
query.orderByFields = ['OBJECTID DESC'];
queryTask.execute(query, (results) => {
let newest = results.features[0];
Portal.prototype.createService = function (options) {
const deferred = new Deferred();
const fsState = lang.getObject('items.featureService',false,AppStore.getState());
const defaults = fsState;
const settings = $.extend(true, {}, defaults, options);
const username = this.getPortalUser().username;
const token = this.getPortalUser().credential.token;
const baseRequestPath = this.portalUrl.stripTrailingSlash() + '/content/users/' + username + (settings.item.ownerFolder ? ('/' + settings.item.ownerFolder) : '');
let response = {};
// Transform arrays
settings.item.tags = settings.item.tags ? settings.item.tags.join(',') : '';
settings.item.typeKeywords = settings.item.typeKeywords.join(',');
const createFeatureService = function createFeatureService() {
const dfd = new Deferred();
const url = baseRequestPath + '/createService';
performAction(params = {}) {
var resultDeferred = new Deferred();
var map = this._cache[this.id] ? this._cache[this.id].map : null;
if (params.isActive === false && ! params.isNewView) {
return;
}
if (! map) {
resultDeferred.reject();
return resultDeferred;
}
if (params.scrollPositionView) {
this._lastScrollPosition = params.scrollPositionView;
}
if (params.transition) {
});
if (dfd) {
return dfd;
} else {
this.setState({
resizingPhoto: false
});
return value;
}
} else if (typeof this.props.extras.photoSettings === 'object') {
const options = $.extend(true,{},{rawPhotoCanvas,optimizedPhotoCanvas},this.props.extras.photoSettings);
const photo = this.generateOptimizedPhoto(options);
if (photo.then) {
const dfd = new Deferred();
photo.then((res) => {
dfd.resolve(res);
});
return dfd;
} else {
return value;
}
}
}
}
this.props.extras.photoSettings.forEach((photoSettings,index) => {
const name = photoSettings.name ? photoSettings.name : 'photo' + index;
const options = $.extend(true,{},{rawPhotoCanvas,optimizedPhotoCanvas},photoSettings);
const photo = this.generateOptimizedPhoto(options);
value[name] = false;
if (photo.then) {
if (!dfd) {
dfd = new Deferred();
}
photo.then((res) => {
value[name] = res;
if (isFinished()) {
if (dfd) {
this.setState({
resizingPhoto: false
});
dfd.resolve(value);
} else {
return value;
}
}
});
} else {
value[name] = photo;
const _saveGraphic = function saveGraphic () {
const dfd = new Deferred();
let g = $.extend(true,{},_contributeGraphic);
let attachments = [];
if (g.attributes) {
$.each(g.attributes, (key,value) => {
if (typeof value === 'object' && value.attachment && value.type) {
switch (value.type) {
case 'photo':
g.attributes[key] = 'ATTACHMENT_' + key;
attachments.push({
field: key,
filename: key + value.ext,
attachment: Helper.attachmentUtils.dataURItoBlob(value.source)
});
break;
}
getAccountingSystem: function getAccountingSystem() {
if (!this._busy) {
this._busy = new BusyIndicator({ id: `${this.id}__busyIndicator` });
this._accountingBusy = new BusyIndicator({ id: `${this.id}__busyIndicator__accounting`, size: 'small', label: null, containerClass: 'busyField' });
this._accountingBusy.start();
}
this._firstLoad = true;
App.modal.showToolbar = false;
App.modal.disableClose = true;
App.modal.add(this._busy);
this._busy.start();
this._accountingDeferred = new Deferred();
this.initBackOfficeModel();
this.initIntegrationMappingModel();
this.initAccountingEntitiesModel();
return this._accountingDeferred.promise;
},
getContent: function getContent() {
const createFeatureService = function createFeatureService() {
const dfd = new Deferred();
const url = baseRequestPath + '/createService';
const content = $.extend(true, settings.item, {
createParameters: JSON.stringify(settings.serviceDefinition),
outputType: 'featureService',
f: 'json'
});
esriRequest({
url,
handleAs: 'json',
content
},{
usePost: true
}).then((res) => {
if (res.success) {