zettapi_client
Version:
Admin panel and client-side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project.
65 lines (52 loc) • 1.53 kB
JavaScript
app.provider('zapi', function (apiEntityMap) {
var map = {};
var idle = false;
var serverUrl = '';
var websocketUrl;
var useInputLarge = true;
return {
getRoutes: function (param) {
if (typeof map[param.entity] === 'undefined') return 'entity/entity.notfound.html';
if (typeof map[param.entity][param.action] === 'undefined') return 'entity/entity.notfound.html';
switch (param.action) {
case 'edit':
return 'entity/entity.edit.html';
case 'view':
if (typeof param.id === 'undefined') return 'entity/entity.notfound.html';
return 'entity/entity.view.html';
case 'list':
if (typeof param.id !== 'undefined') return 'entity/entity.notfound.html';
return 'entity/entity.list.html';
default:
return 'entity/entity.notfound.html';
}
},
setMap: function (entityMap) {
map = apiEntityMap;
for (var key in entityMap) {
map[key] = entityMap[key];
}
},
setServerUrl: function (url) {
serverUrl = url || '';
},
setWebsocket: function (url) {
websocketUrl = url || undefined;
},
setUseInputLarge: function (inputlg) {
useInputLarge = inputlg;
},
setIdle: function (state) {
idle = state;
},
$get: function () {
return {
entityMap: map,
idle: idle,
serverUrl: serverUrl,
websocketUrl: websocketUrl,
useInputLarge: useInputLarge,
};
}
};
});