Skip to content

Instantly share code, notes, and snippets.

@justinramel
Created December 28, 2015 14:04
Show Gist options
  • Save justinramel/a206576652bdf8991b22 to your computer and use it in GitHub Desktop.
Save justinramel/a206576652bdf8991b22 to your computer and use it in GitHub Desktop.
import {Page, Modal, NavParams} from 'ionic/ionic';
import {TransactionsService} from './transactions.service';
@Page({
templateUrl: 'build/pages/transactions/input-modal.html',
providers: [TransactionsService]
})
export class TransactionInputModal {
constructor(modal: Modal, params: NavParams, transactionsService: TransactionsService) {
this.modal = modal;
this.transactionsService = transactionsService;
this.parent = params.get('parent');
const direction = params.get('direction');
if (direction) {
this.transaction = transactionsService.create({direction: direction});
} else {
this.transaction = params.get('transaction');
}
this.transaction.createdDateInput = this.toDateString(this.transaction.createdDate);
}
save(transaction) {
this.transaction.createdDate = new Date(this.transaction.createdDateInput);
this.transactionsService.save(transaction).then(transaction => {
this.parent.refresh();
this.close();
});
}
toDateString(date) {
var yyyy = date.getFullYear().toString();
var mm = (date.getMonth()+1).toString(); // getMonth() is zero-based
var dd = date.getDate().toString();
return yyyy + '-' +(mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]); // padding
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment