managediscountcode.component.js 5.58 KB
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var managediscountcode_service_1 = require("./managediscountcode.service");
var router_1 = require("@angular/router");
var forms_1 = require("@angular/forms");
var datamodel_1 = require("../UserEntity/datamodel");
//import { Global } from '../../Shared/global';
//import { DBOperation } from 'S';
//import { Observable } from 'rxjs/Observable';
var ManageDiscountCode = /** @class */ (function () {
    function ManageDiscountCode(manageDiscountCodeService, router, fb) {
        this.manageDiscountCodeService = manageDiscountCodeService;
        this.router = router;
        this.fb = fb;
        this.Mode = 'Manage';
        this.divClass = '';
        this.topPos = '2000px';
        this.bsValue = new Date();
    }
    ManageDiscountCode.prototype.ngOnInit = function () {
        this.divClass = 'col-sm-12';
        this.discountCode = new datamodel_1.DiscountCode();
        this.alerts = '';
        this.manageDiscountCodeFrm = this.fb.group({
            searchDiscountCode: [''],
            searchStartDate: [''],
            searchEndDate: [''],
            discountCodes: this.fb.array([])
        });
        this.insertUpdateDiscountCodeFrm = this.fb.group({
            discountId: [''],
            discountCode: ['', forms_1.Validators.required],
            startDate: ['', forms_1.Validators.required],
            endDate: ['', forms_1.Validators.required],
            percentage: ['', forms_1.Validators.required],
            isActive: ['']
        });
        this.SearchDiscountCodes();
    };
    ManageDiscountCode.prototype.SearchDiscountCodes = function () {
        var _this = this;
        console.log(this.manageDiscountCodeFrm.controls['searchDiscountCode'].value + ', ' +
            this.manageDiscountCodeFrm.controls['searchStartDate'].value + ', ' +
            this.manageDiscountCodeFrm.controls['searchEndDate'].value);
        this.manageDiscountCodeService.GetDiscountCodes({
            discountCode: this.manageDiscountCodeFrm.controls['searchDiscountCode'].value,
            startDate: this.manageDiscountCodeFrm.controls['searchStartDate'].value,
            endDate: this.manageDiscountCodeFrm.controls['searchEndDate'].value
        })
            .subscribe(function (x) { _this.BindFormFields(x); }, function (error) { return _this.error = error; });
    };
    ManageDiscountCode.prototype.InsertUpdateDiscountCode = function () {
        var _this = this;
        console.log('InsertUpdateDiscountCode');
        this.alerts = '';
        if (this.alerts == '') {
            var obj = this.insertUpdateDiscountCodeFrm.value;
            return this.manageDiscountCodeService.InsertDiscountCode(obj)
                .subscribe(function (n) { return (_this.AfterInsertData(n)); }, function (error) { return _this.error = error; });
        }
    };
    ManageDiscountCode.prototype.AfterInsertData = function (data) {
        if (data.Status == "false") {
            this.alerts = "<span>Password change unsuccessfully</span>";
        }
        else {
            this.alerts = "<span>Password changed successfully</span>";
        }
    };
    ManageDiscountCode.prototype.BindFormFields = function (data) {
        this.discountCodes = data;
        this.manageDiscountCodeFrm.setControl('discountCodes', this.fb.array(this.discountCodes));
    };
    ManageDiscountCode.prototype.ResetFormFields = function () {
        this.manageDiscountCodeFrm.reset();
        //this.manageDiscountCodeFrm.controls['loginId'].setValue(this.user.LoginId);
        //this.manageDiscountCodeFrm.controls['oldPassword'].setValue('');
        //this.manageDiscountCodeFrm.controls['newPassword'].setValue('');
        //this.manageDiscountCodeFrm.controls['confirmPassword'].setValue('');
        this.alerts = '';
    };
    ManageDiscountCode.prototype.AddDiscountCode = function () {
        this.Mode = 'Add';
        this.topPos = '100px';
        this.divClass = 'col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3';
    };
    ManageDiscountCode.prototype.EditDiscountCode = function () {
        this.Mode = 'Edit';
        this.topPos = '100px';
        this.divClass = 'col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3';
    };
    ManageDiscountCode.prototype.CancelAddEdit = function () {
        this.Mode = 'Manage';
        this.topPos = '2000px';
        this.divClass = 'col-sm-12';
    };
    ManageDiscountCode = __decorate([
        core_1.Component({
            templateUrl: './managediscountcode.component.html'
        }),
        __metadata("design:paramtypes", [managediscountcode_service_1.ManageDiscountCodeService, router_1.Router, forms_1.FormBuilder])
    ], ManageDiscountCode);
    return ManageDiscountCode;
}());
exports.ManageDiscountCode = ManageDiscountCode;
//# sourceMappingURL=managediscountcode.component.js.map