Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
destroy: function(callback) {
// Destroy the model. Will sync to store.
var self = this;
var d = m.deferred();
var id = this.__getDataId();
if (id[config.keyId]) {
store.destroy(this.url(), id).then(function(data) {
self.detach();
d.resolve();
if (_.isFunction(callback)) callback(null);
self.dispose();
}, function(err) {
d.reject(err);
if (_.isFunction(callback)) callback(err);
});
} else {
d.reject(true);
if (_.isFunction(callback)) callback(true);
}
return d.promise;
const payWithNewCard = (contribution_id, installment) => {
const deferred = m.deferred();
m.request({
method: 'GET',
url: `/payment/pagarme/${contribution_id}/get_encryption_key`,
config: setCsrfToken
}).then((data) => {
window.PagarMe.encryption_key = data.key;
const card = setNewCreditCard();
const errors = card.fieldErrors();
if (_.keys(errors).length > 0) {
deferred.reject({ message: window.I18n.t('submission.card_invalid', scope()) });
} else {
card.generateHash((cardHash) => {
const data = {
card_hash: cardHash,
save_card: creditCardFields.save().toString(),
payment_card_installments: installment
simpleModalComponent.config = function(ctrl) {
m.startComputation();
var deferred = m.deferred();
return function(element, isInitialized) {
var el = document.querySelector('.simple-modal-content');
if (!isInitialized) {
m.startComputation();
el = simpleModal({content: 'modal content'});
window.setTimeout(function() {
deferred.resolve();
//the service is done, tell Mithril that it may redraw
m.endComputation();
}, 1500);
//m.module(document.querySelector('.simple-modal-content'), xrefSearchResults);
/*
//set up simpleModalComponent (only if not initialized already)
el.simpleModalComponent()
//this event handler updates the controller when the view changes
const uploadImage = (project_id) => {
if (_.isEmpty(fields.upload_files_targets())) {
const deferred = m.deferred();
deferred.resolve({});
return deferred.promise;
}
return m.request({
method: 'POST',
url: `/projects/${project_id}/upload_image.json`,
data: fields.upload_files(),
config: h.setCsrfToken,
serialize(data) { return data; }
});
};
let range = moment.range(start, end);
let expensesInRange = expenses.filter(e => {
return range.contains(e.day(), false);
});
let categories = this.context
.listCategories()
.map(c => {
let data = expensesInRange.filter(e => {
return e.category().id() === c.id();
});
return new CategoryData(c, data);
});
let deferred = m.deferred();
deferred.resolve(categories);
return deferred.promise;
};
}
const sendPayment = (selectedCreditCard, selectedInstallment, contribution_id, project_id) => {
const deferred = m.deferred();
if (validate()) {
isLoading(true);
submissionError(false);
m.redraw();
updateContributionData(contribution_id, project_id)
.then(checkAndPayCreditCard(deferred, selectedCreditCard, contribution_id, project_id, selectedInstallment))
.catch(() => {
isLoading(false);
deferred.reject();
});
} else {
isLoading(false);
deferred.reject();
}
return deferred.promise;
};
const pay = ({creditCardId}) => {
const p = m.deferred();
if (creditCardId) {
_.extend(payload, {
card_id: creditCardId.id,
credit_card_id: creditCardId.id
});
}
if (commonData.subscription_id){
sendSubscriptionUpgrade(payload).then(p.resolve).catch(p.reject);
} else {
sendPaymentRequest(payload).then(p.resolve).catch(p.reject);
}
return p.promise;
};
function promisify(highlandStream) {
//tell Mithril to wait for this service to complete before redrawing
m.startComputation();
var deferred = m.deferred();
highlandStream.toArray(function(results) {
deferred.resolve(results);
//the service is done, tell Mithril that it may redraw
m.endComputation();
});
return deferred.promise;
}
const processCreditCard = (cardHash, fields) => {
const p = m.deferred();
saveCreditCard(cardHash)
.then(waitForSavedCreditCard(p))
.catch(p.reject);
return p.promise;
};
getBlogPosts() {
const deferred = m.deferred();
const posts = _.first(document.getElementsByTagName('body')).getAttribute('data-blog');
if (posts) {
deferred.resolve(JSON.parse(posts));
} else {
m.request({ method: 'GET', url: '/posts' })
.then(deferred.resolve)
.catch(deferred.reject);
}
return deferred.promise;
}
};