{ div, form, input, textarea, select, option, label, h4, p, a } = React.DOM class @PrintPrompt extends React.Component constructor: (props) -> super props @state = url: props.url collation: props.collation template: props.template paper: props.paper user_id: props.user_id user_email: props.user_email shared: new App.Shared() printers_url: "/admin/users/" + props.user_id + "/printers.json" wurl: "" args: "" @propTypes = url: React.PropTypes.string template: React.PropTypes.string paper: React.PropTypes.string user_id: React.PropTypes.number collation: React.PropTypes.string user_email: React.PropTypes.string @defaultProps = url: "" collation: "list" template: "" paper: "A4" user_id: 1 user_email: "" getPrinterList: (e) => jqxhr = $.ajax url: @state.printers_url method: 'GET' .done (printers) -> @obj=$("#user_suggested_printer_list") for printer in printers opt = document.createElement("option") opt.value = printer.id opt.text = printer.name @obj.append opt @obj.material_select() .fail (data) -> console.log 'fejl ved opslag i printer liste' hidePrinterList: (e) => $('.select-wrapper.printer_list').hide() showPrinterList: (e) => $('.select-wrapper.printer_list').show() hideEmailForm: (e) => $('.emailForm').hide() showEmailForm: (e) => $('.emailForm').show() hideDisplayForm: (e) => $('.displayForm').hide() showDisplayForm: (e) => $('.displayForm').show() onDisplay: (e) => @hidePrinterList() @hideEmailForm() @showDisplayForm() onEmail: (e) => @hidePrinterList() @hideDisplayForm() @showEmailForm() onPrint: (e) => @showPrinterList() @hideEmailForm() @hideDisplayForm() onDownload: (e)=> @hidePrinterList() @hideEmailForm() @hideDisplayForm() onHTML_PDF: (e) => if $(e.currentTarget).attr('id') == "display_file_as_pdf" $("#display_file_as_html").prop 'checked', !$("#display_file_as_pdf").prop('checked') else $("#display_file_as_pdf").prop 'checked', !$("#display_file_as_html").prop('checked') cancelModal: (e) => App.shared.spinWhileLoading() $("#print-dialog").closeModal() animatePrint: (e) => if e $(".print-ok-button").html('
') else $(".print-ok-button").html('Ok') sendPrintRequest: (e) => @animatePrint(e) wrl = @state.url arg = @state.args if wrl=='href' wrl = window.location.href.replace( /#!$/, "") if wrl.match /\?/ w = wrl.split("?")[0] + "/print" arg = wrl.split("?")[1] + "&" else w = wrl + "/print" arg = arg + "&collation=#{@state.collation}&template=#{@state.template}&paper=#{@state.paper}" @form = $('#print-dialog form') @setState {wurl: w, args: arg}, () => if $('input[name="print[medium]"]:checked').val()=="display" @animatePrint() $("#print-dialog").closeModal() window.open @state.wurl + "?" + @form.serialize() + '&' + @state.args return jqxhr = $.ajax url: @state.wurl method: "GET" data: @form.serialize() + '&' + @state.args dataType: 'html' .done (data) => @animatePrint() $("#print-dialog").closeModal() .fail (data) => @animatePrint() $("#print-dialog").closeModal() componentDidMount: -> $(document.body).on 'app:print-dialog:state:changed', (e) => @setState(e.state) @getPrinterList() @hidePrinterList() @hideEmailForm() $('#print_email_to').val @state.user_email render: -> div className: "modal" id: "print-dialog" div className: "modal-content" div className: "container" div className: "row" div className: "col s12 m12 l12" h4 className: "h4" "Se, sende eller udskrive?" p className: "p" "Dette printjob har du mulighed for at se på flere måder - du kan udskrive det direkte på en printer, sende en email besked hvor du hæfter det ved, eller få det vist som PDF på skærmen. Valget er dit" div className: "row" div className: "col s12 m12 l12" form className: "print_form" div className: "row" div className: "col s12 m6 l6" p className: "p" input className: "with-gap" id: "display" type: "radio" name: "print[medium]" value: "display" onClick: @onDisplay label className: "label" htmlFor: "display" "På skærmen" p className: "p" input className: "with-gap" id: "email" type: "radio" name: "print[medium]" value: "email" onClick: @onEmail label className: "label" htmlFor: "email" "Vedhæftet en email" p className: "p" input className: "with-gap" id: "printer" type: "radio" name: "print[medium]" value: "printer" onClick: @onPrint label className: "label" htmlFor: "printer" "til printer" p className: "p" input className: "with-gap" id: "download" type: "radio" name: "print[medium]" value: "download" onClick: @onDownload label className: "label" htmlFor: "download" "som fil" div className: "col s12 m6 l6" p className: "p" select className: "printer_list" name: "print[printer]" id: "user_suggested_printer_list" defaultValue: "0" option className: "printer_list_option" value:"0" disabled: "true" "Vælg en printer" label className: "label" "Printer" p className: "p displayForm" input className: "with-gap" id: "display_file_as_html" type: "checkbox" name: "print[output_type]" value: "html" onClick: @onHTML_PDF label className: "label" htmlFor: "display_file_as_html" "HTML" p className: "p displayForm" input className: "with-gap" id: "display_file_as_pdf" type: "checkbox" name: "print[output_type]" value: "pdf" onClick: @onHTML_PDF label className: "label" htmlFor: "display_file_as_pdf" "PDF" p className: "p emailForm" label className: 'label' htmlFor: "print_email_to" "Modtager:" input className: "text" id: "print_email_to" type: "text" name: "print[email_to]" div className: "col s12 m12 l12" p className: "p emailForm" label className: 'label' htmlFor: "print_message" "Besked:" textarea className: "materialize-textarea" id: "print_message" name: "print[message]" div className: "modal-footer" a className: "print-ok-button green btn modal-action waves-effect waves-green" href: "#!" onClick: @sendPrintRequest "Ok" a className: "orange btn modal-action waves-effect waves-orange" href: "#!" onClick: @cancelModal "Fortryd"