define([
    'Global',
    'ConsultOrders',
    'Text!../html/templates/consult-details.html'
],
    function (Global, ConsultOrders, consultDetailsTemplate) {
        'use strict';
        return Backbone.View.extend({
            tagName: "div",
            initialize: function () {
                this.template = _.template(consultDetailsTemplate);
            },
            render: function () {
	            this.id = $(document).jqmData('details-id');

                var $container = getMainContent(),
                    details = ConsultOrders
                                .instance()
                                .findById(this.id)
                                .toJSON();

                details.text = details.text.slice(0,-3);//details.text.slice(9).slice(0, -3);

                this.$el.append(this.template(details));

                $container
                    .empty()
                    .append(this.$el);

                this.$el.trigger('create');

				$(document).jqmData('requestHref-for-detail-viewing', '');

	            $('#print-consult').focus();

				return this;
            },
            events: {
                "tap #print-consult": "printConsult",
                "tap .book-appointment": "goToBooking"
            },
            printConsult: function (e) {
                e.preventDefault();
                var consult = ConsultOrders
                        .instance()
                        .findById(this.id);

                Global.getUtilities().flattenLinks(consult);

                var printUrl = consult.get('print-patient-consult-pdf').href;

                window.open(printUrl);
            }
        });
    }
);



