Sha256: 0ab549195b0ee660bebe535bee04a6c21900eed931a4cf811209da494bcb8ba8

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

testApp.constant('SURVEY_EVENTS', {
	create: 'create',
	update: 'update',
	destroy: 'destroy',
})

testApp.factory('Survey', ['$rootScope', 'SURVEY_EVENTS', 'ApiAdapter',
	function($rootScope, SURVEY_EVENTS, ApiAdapter) {
		ApiAdapter.addRoute(
			"get_surveys",
			"/surveys"
		);
		ApiAdapter.addRoute(
			"get_survey",
			"/surveys/{surveyId}"
		);
		ApiAdapter.addRoute(
			"create_survey",
			"/surveys",
			{
				"type": "POST",
				"processData": false,
				"contentType": "application/json",
				"success": function(result) {
					$rootScope.$broadcast(SURVEY_EVENTS.create, result.response);
				}
			}
		);
		ApiAdapter.addRoute(
			"update_survey",
			"/surveys/{surveyId}",
			{
				"type": "PUT",
				"processData": false,
				"contentType": "application/json",
				"success": function(result) {
					$rootScope.$broadcast(SURVEY_EVENTS.update, result.response);
				}
			}
		);
		ApiAdapter.addRoute(
			"delete_survey",
			"/surveys/{surveyId}",
			{
				"type": "DELETE",
				"success": function(result) {
					$rootScope.$broadcast(SURVEY_EVENTS.destroy, result);
				}
			}
		);

		return {
			get: function(params, args, noCache) {
				return ApiAdapter.execute("get_survey", params, args, ((typeof(noCache) != "boolean")? true : noCache));
			},
			index: function(params, args, noCache) {
				return ApiAdapter.execute("get_surveys", params, args, ((typeof(noCache) != "boolean")? true : noCache));
			},
			create: function(params, args, noCache) {
				return ApiAdapter.execute("create_survey", params, args, ((typeof(noCache) != "boolean")? true : noCache));
			},
			update: function(params, args, noCache) {
				return ApiAdapter.execute("update_survey", params, args, ((typeof(noCache) != "boolean")? true : noCache));
			},
			destroy: function(params, args, noCache) {
				return ApiAdapter.execute("delete_survey", params, args, ((typeof(noCache) != "boolean")? true : noCache));
			}
		};
	}
]);

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_record_survey_api-0.0.7 spec/test_app/app/assets/javascripts/services/SurveyService.js
active_record_survey_api-0.0.6 spec/test_app/app/assets/javascripts/services/SurveyService.js