/* Minified: jquery.objectCompletion.js, jquery.objectPriority.js */
jQuery.fn.objectCompletion=function(s){var settings=jQuery.extend({complete_event:null,open_event:null},s);return this.each(function(){var wrapper=$(this);if(settings.complete_event){App.Wireframe.Events.bind(settings.complete_event,function(event,obj){wrapper.text(App.lang("Completed by :user on :date",{user:obj.completed_by["short_display_name"],date:obj.completed_on["formatted"]}))})}if(settings.open_event){App.Wireframe.Events.bind(settings.open_event,function(event,obj){wrapper.text(App.lang("Open"))})}})};
(function($){var methods={init:function(s){var settings=jQuery.extend({value:0,base_type_name:null,edit_url:null,success_event:null},s);return this.each(function(){var wrapper=$(this);if(settings.base_type_name&&settings.edit_url){wrapper.data("base_type_name",settings.base_type_name);wrapper.data("edit_url",settings.edit_url)}wrapper.objectPriority("set",settings.value)})},set:function(value){return this.each(function(){var wrapper=$(this).empty();value=parseInt(value);var label=$('<span class="priority"></span>').appendTo(wrapper);switch(value){case -2:label.text(App.lang("Lowest")).addClass("lowest_priority");break;case -1:label.text(App.lang("Low")).addClass("low_priority");break;case 1:label.text(App.lang("High")).addClass("high_priority");break;case 2:label.text(App.lang("Highest")).addClass("highest_priority");break;default:label.text(App.lang("Normal")).addClass("normal_priority")}if(wrapper.data("base_type_name")&&wrapper.data("edit_url")){label.css("cursor","pointer").click(function(){var change_priority_wrapper=$('<div class="change_priority" style="padding: 30px 25px;"><select><option value="-2">'+App.lang("Lowest")+'</option><option value="-1">'+App.lang("Low")+'</option><option value="0">'+App.lang("Normal")+'</option><option value="1">'+App.lang("High")+'</option><option value="2">'+App.lang("Highest")+"</option></select> <button>"+App.lang("Change")+"</button></div>");var select=change_priority_wrapper.find("select").val(value);var button=change_priority_wrapper.find("button");button.click(function(){if(select.val()!=value){var image=$('<img src="'+App.Wireframe.Utils.indicatorUrl()+'">');button.hide().after(image);var data={submitted:"submitted"};data[wrapper.data("base_type_name")+"[priority]"]=select.val();$.ajax({url:App.extendUrl(wrapper.data("edit_url"),{async:1}),type:"post",data:data,success:function(response){wrapper.objectPriority("set",response.priority);if(wrapper.data("success_event")){App.Wireframe.Events.trigger(wrapper.data("success_event"),[response])}App.Wireframe.ModalDialog.close("change_priority");App.Wireframe.Flash.success("Priority has been changed")},error:function(){image.remove();button.show();App.Wireframe.Flash.error("Failed to update priority. Please try again later")}})}else{App.Wireframe.ModalDialog.close("change_priority")}});App.Wireframe.ModalDialog.show("change_priority",App.lang("Change Priority"),change_priority_wrapper,{})})}})}};$.fn.objectPriority=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof method==="object"||!method){return methods.init.apply(this,arguments)}else{throw"Method "+method+" does not exist on jQuery.objectPriority"}}}})(jQuery);
