﻿BenefulMap.ModalRemoveSpot = BenefulMap.ModalForm.extend({
	init: function(modalTitle, modalElements, modalOptions, snippetPath, params, formElements, context) {
		this._super( modalTitle, modalElements, modalOptions, snippetPath, params, formElements);
		this.context;
	},
	getContext: function() {
		return this.context;
	},
	setContext: function(context) {
		this.context = context;
	},
	submitFormData: function() {
		this._super();
		var self = this;
		var fromEmail = this.getIndividualFormData('YourEmailAddress');
		var reasonForRemoval = this.getIndividualFormData('FeedbackMessage');
		
		console.log(this.getContext());
		if ( this.getContext() == "spot" ) {
			var id = parseInt(jQuery.url.attr("file").replace(".aspx", ""));
        } else if ( this.getContext() == "review" ) {
            console.log($(this.getFiredTarget()).parent().attr("id"));
            var id = parseInt($(this.getFiredTarget()).parent().attr("id").replace('review',""));
            console.log('id = ' + id);
        } else if (this.getContext() == "photo" ) {
            console.log($(this.getFiredTarget()).parent().attr("id"));
            var id = parseInt($(this.getFiredTarget()).parent().attr("id").replace('photo',""));
            console.log('id = ' + id);
        } else {
			var id = parseInt($(this.getFiredTarget()).parent().attr("id").replace(this.getContext(), ""));
			console.log(id);
		}
		WagWorld.Web.AjaxUtility.RequestRemoval(this.getContext(), id, fromEmail, reasonForRemoval, function(result) {
			self.checkResult(result.value.Pass, result.value.Reason);
		});
	},
	showThankYou: function() {
		this.setTitle("Your Removal Request Has Been Sent");
		var params = {};
		params.ph = 2;
		this.setParams(params);
		this.populate();
	},
	redisplayFormWithMessage: function(message) {
		var params = {};
		params.ph = 1;
        params.message = message;
        this.setParams(params);
        this.populate();
	},
	checkResult: function(pass, msg) {
        if (pass == true) {
            this.showThankYou();
        } else {
            this.redisplayFormWithMessage(msg);
        }
	},
	addModalTargetListener: function() {
		var self = this;
		$(this.targetEl).live('click', function(event) {
			event.preventDefault();
			var context = $(this).attr("rel");
			self.setContext(context);
			addedParams = {
				context: context,
				test: 'test'
			};
			self.extendParams(addedParams);
			self.setFiredTarget(this);
			self.populate();
		});
	}
});

