@angular-jz/jz
Version:
jim jz
134 lines • 5.6 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var router_1 = require("@angular/router");
var ng_bootstrap_1 = require("@ng-bootstrap/ng-bootstrap");
var angular2_toaster_1 = require("angular2-toaster");
var CurdPageComponentOptions = /** @class */ (function () {
function CurdPageComponentOptions() {
}
return CurdPageComponentOptions;
}());
exports.CurdPageComponentOptions = CurdPageComponentOptions;
var CrudPageComponent = /** @class */ (function () {
function CrudPageComponent(injector, options) {
var _this = this;
this.injector = injector;
this.options = options;
this.items = [];
this.totalCount = 0;
this.criteria = {
keyword: null,
page: {
pageNo: 1,
pageSize: 10
}
};
this.dics = {};
this.deleteItemSucess = function (data) {
_this.toasterService.pop('success', '', '操作成功!');
_this.searchItems();
};
this.deleteItemFailed = function (error) {
_this.toasterService.pop('error', '', error);
};
this.operationSucess = function (data) {
_this.toasterService.pop('success', '', '操作成功!');
_this.searchItems();
};
this.operationFailed = function (error) {
_this.toasterService.pop('error', '', error);
};
this.crudService = options.crudService;
this.modalService = injector.get(ng_bootstrap_1.NgbModal);
this.toasterService = injector.get(angular2_toaster_1.ToasterService);
this.route = injector.get(router_1.ActivatedRoute);
//this.toasterService = injector.get(ToasterService);
}
CrudPageComponent.prototype.ngOnInit = function () {
var _this = this;
this.routeSub = this.route.queryParams.subscribe(function (params) {
_this.criteria = __assign({}, _this.criteria, params);
});
this.crudService.pageLoad(this.criteria).then(function (data) {
_this.items = data.items.items;
_this.totalCount = data.items.totalCount;
for (var objKey in data) {
if (objKey != 'items' && objKey != 'dics') {
_this.dics[objKey] = data[objKey];
}
else if (objKey == 'dics') {
data[objKey].forEach(function (dic) {
_this.dics[dic.dicKey] = dic.children;
});
}
}
_this.hookAfterPageLoadDataReceived(data);
});
};
CrudPageComponent.prototype.hookAfterPageLoadDataReceived = function (data) { };
CrudPageComponent.prototype.ngOnDestory = function () {
this.routeSub.unsubscribe();
};
CrudPageComponent.prototype.loadItems = function () {
var _this = this;
this.crudService.getItems(this.criteria)
.then(function (data) {
_this.items = data.items.items;
_this.totalCount = data.items.totalCount;
});
};
CrudPageComponent.prototype.searchItems = function () {
this.criteria.page.pageNo = 1;
this.loadItems();
};
CrudPageComponent.prototype.pageChange = function (pageNo) {
if (pageNo != this.criteria.page.pageNo) {
this.criteria.page.pageNo = pageNo;
this.loadItems();
}
};
CrudPageComponent.prototype.openViewItem = function (item) {
var modalRef = this.modalService.open(this.options.itemViewComponent, { backdrop: 'static' });
modalRef.componentInstance.item = {};
if (item)
modalRef.componentInstance.item = __assign({}, item);
modalRef.componentInstance.dics = __assign({}, this.dics);
modalRef.result.then(function (result) { });
};
CrudPageComponent.prototype.openCreateItem = function (item) {
var _this = this;
var modalRef = this.modalService.open(this.options.itemCreateComponent, { backdrop: 'static' });
modalRef.componentInstance.item = {};
if (item)
modalRef.componentInstance.item = __assign({}, item);
modalRef.componentInstance.dics = __assign({}, this.dics);
modalRef.result.then(function (result) {
if (result && result.success)
_this.searchItems();
});
};
CrudPageComponent.prototype.openEditItem = function (item) {
var _this = this;
var modalRef = this.modalService.open(this.options.itemEditComponent, { backdrop: 'static' });
modalRef.componentInstance.item = __assign({}, item);
modalRef.componentInstance.dics = __assign({}, this.dics);
modalRef.result.then(function (result) {
if (result && result.success)
_this.searchItems();
});
};
CrudPageComponent.prototype.deleteItem = function (item) {
this.crudService.deleteItem(item).then(this.deleteItemSucess, this.deleteItemFailed);
};
return CrudPageComponent;
}());
exports.CrudPageComponent = CrudPageComponent;
//# sourceMappingURL=crud.page.component.js.map