zettapi_client
Version:
Client side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project
75 lines (63 loc) • 2.02 kB
JavaScript
var app = angular.module('zapi', [
'ngSanitize',
'ngAnimate',
'ui.bootstrap',
'blockUI',
'chart.js',
'btford.socket-io',
'ngCsv',
'ngTable',
'selector',
'ngIdle',
'pascalprecht.translate',
'ngPasswordMeter'
]).config(function(TitleProvider, $locationProvider) {
TitleProvider.enabled(false);
$locationProvider.hashPrefix("");
}).provider('zapi', function(apiEntityMap) {
var map = {};
var idle = false;
var serverUrl = '',
websocketUrl;
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;
},
setIdle: function(state) {
idle = state;
},
$get: function() {
return {
entityMap: map,
idle: idle,
serverUrl: serverUrl,
websocketUrl: websocketUrl
};
}
};
});