Update: SignalR v1.0.1 Migration; Json.NET

This commit is contained in:
Gary Sharp
2013-05-06 19:04:29 +10:00
parent 9431ec983e
commit f320db3538
39 changed files with 2150 additions and 1150 deletions
+100 -98
View File
@@ -43,17 +43,17 @@
</td>
</tr>
</table>
<div id="dialogUpload" title="Upload Attachment">
<div id="dialogUpload" class="hiddenDialog" title="Upload Attachment">
<div id="silverlightHostUploadAttachment">
</div>
</div>
<div id="dialogRemoveLog" title="Remove this Comment?">
<div id="dialogRemoveLog" class="hiddenDialog" title="Remove this Comment?">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Are you sure?
</p>
</div>
<div id="dialogRemoveAttachment" title="Remove this Attachment?">
<div id="dialogRemoveAttachment" class="hiddenDialog" title="Remove this Attachment?">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Are you sure?
@@ -74,6 +74,7 @@
var $CommentOutput = $Comments.find('.commentOutput');
var $CommentOutputContainer = $Comments.find('.commentOutputContainer');
var $CommentInput = $Comments.find('textarea.commentInput');
var $dialogRemoveLog;
window.setTimeout(function () {
$CommentOutput[0].scrollTop = $CommentOutput[0].scrollHeight; // Scroll to Bottom
@@ -93,14 +94,6 @@
});
$CommentOutput.find('span.remove').click(removePost);
$dialogRemoveLog = $('#dialogRemoveLog');
$dialogRemoveLog.dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false
});
function postComment() {
var comment = $CommentInput.val();
if (comment != '') {
@@ -130,8 +123,16 @@
$this = $(this);
var data = { id: $this.closest('div').attr('data-logid') };
$dialogRemoveLog.dialog("enable");
$dialogRemoveLog.dialog('option', 'buttons', {
if (!$dialogRemoveLog) {
$dialogRemoveLog = $('#dialogRemoveLog').dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false
});
}
$dialogRemoveLog.dialog("enable").dialog('option', 'buttons', {
"Remove": function () {
$dialogRemoveLog.dialog("disable");
$dialogRemoveLog.dialog("option", "buttons", null);
@@ -159,9 +160,7 @@
"Cancel": function () {
$dialogRemoveLog.dialog("close");
}
});
$dialogRemoveLog.dialog('open');
}).dialog('open');
return false;
}
@@ -210,30 +209,12 @@
// - Repository notifications now handles this
document.DiscoFunctions.addAttachment = function () { };
$Attachments = $('#Attachments');
$attachmentOutput = $Attachments.find('.attachmentOutput');
var $Attachments = $('#Attachments');
var $attachmentOutput = $Attachments.find('.attachmentOutput');
var $dialogUpload, $dialogRemoveAttachment;
$attachmentOutput.find('span.remove').click(removeLocalAttachment);
$('#dialogUpload').dialog({
autoOpen: false,
draggable: false,
modal: true,
resizable: false,
width: 860,
height: 550,
close: function () {
silverlightUploadAttachment.content.Navigator.Navigate('/Hidden');
}
});
$('#dialogRemoveAttachment').dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false
});
var onLoadNavigation = null;
var isLoaded = null;
Silverlight.createObject(
@@ -252,7 +233,7 @@
'UploadUrl=@(Url.Action(MVC.API.Job.AttachmentUpload(Model.Job.Id, null)))'
);
$attachmentInput = $Attachments.find('.attachmentInput');
var $attachmentInput = $Attachments.find('.attachmentInput');
$attachmentInput.find('.photo').click(function () {
showDialog('/WebCam');
});
@@ -260,9 +241,22 @@
showDialog('/File');
});
silverlightUploadAttachment = $('#silverlightUploadAttachment').get(0);
var silverlightUploadAttachment = $('#silverlightUploadAttachment').get(0);
function showDialog(navigationPath) {
$('#dialogUpload').dialog('open');
if (!$dialogUpload) {
$dialogUpload = $('#dialogUpload').dialog({
autoOpen: false,
draggable: false,
modal: true,
resizable: false,
width: 860,
height: 550,
close: function () {
silverlightUploadAttachment.content.Navigator.Navigate('/Hidden');
}
});
}
$dialogUpload.dialog('open');
if (isLoaded) {
silverlightUploadAttachment.content.Navigator.Navigate(navigationPath);
} else {
@@ -271,40 +265,41 @@
};
function addAttachment(id, quick) {
var data = { id: id };
$.ajax({
url: '@Url.Action(MVC.API.Job.Attachment())',
dataType: 'json',
data: data,
success: function (d) {
if (d.Result == 'OK') {
var a = d.Attachment;
dataType: 'json',
data: data,
success: function (d) {
if (d.Result == 'OK') {
var a = d.Attachment;
if (parseInt(a.ParentId) == jobId) {
var e = $('<a><span class="icon"><img alt="Attachment Thumbnail" /></span><span class="comments"></span><span class="author"></span><span class="remove"></span><span class="timestamp"></span></a>');
if (parseInt(a.ParentId) == jobId) {
var e = $('<a><span class="icon"><img alt="Attachment Thumbnail" /></span><span class="comments"></span><span class="author"></span><span class="remove"></span><span class="timestamp"></span></a>');
e.attr('data-attachmentid', a.Id).attr('data-mimetype', a.MimeType).attr('href', '@(Url.Action(MVC.API.Job.AttachmentDownload()))/' + a.Id);
e.find('.icon img').attr('src', '@(Url.Action(MVC.API.Job.AttachmentThumbnail()))/' + a.Id);
e.find('.comments').text(a.Comments);
e.find('.author').text(a.Author);
e.find('.timestamp').text(a.TimestampFuzzy).attr('title', a.TimestampFull);
e.find('.remove').click(removeLocalAttachment);
if (!quick)
e.hide();
$attachmentOutput.append(e);
if (!quick)
e.show('slow');
if (a.MimeType.toLowerCase().indexOf('image/') == 0)
e.shadowbox({ gallery: 'attachments', player: 'img', title: a.Comments });
e.attr('data-attachmentid', a.Id).attr('data-mimetype', a.MimeType).attr('href', '@(Url.Action(MVC.API.Job.AttachmentDownload()))/' + a.Id);
e.find('.icon img').attr('src', '@(Url.Action(MVC.API.Job.AttachmentThumbnail()))/' + a.Id);
e.find('.comments').text(a.Comments);
e.find('.author').text(a.Author);
e.find('.timestamp').text(a.TimestampFuzzy).attr('title', a.TimestampFull);
e.find('.remove').click(removeLocalAttachment);
if (!quick)
e.hide();
$attachmentOutput.append(e);
if (!quick)
e.show('slow');
if (a.MimeType.toLowerCase().indexOf('image/') == 0)
e.shadowbox({ gallery: 'attachments', player: 'img', title: a.Comments });
}
} else {
alert('Unable to add attachment: ' + d.Result);
}
} else {
alert('Unable to add attachment: ' + d.Result);
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Unable to add attachment: ' + textStatus);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Unable to add attachment: ' + textStatus);
}
});
}
});
}
function removeAttachment(id) {
var $element = $attachmentOutput.find('a[data-attachmentid="' + id + '"]');
if ($element.length > 0) {
@@ -321,9 +316,16 @@
var data = { id: $this.attr('data-attachmentid') };
var $dialogRemoveAttachment = $('#dialogRemoveAttachment');
$dialogRemoveAttachment.dialog("enable");
$dialogRemoveAttachment.dialog('option', 'buttons', {
if (!$dialogRemoveAttachment) {
$dialogRemoveAttachment = $('#dialogRemoveAttachment').dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false
});
}
$dialogRemoveAttachment.dialog("enable").dialog('option', 'buttons', {
"Remove": function () {
$dialogRemoveAttachment.dialog("disable");
$dialogRemoveAttachment.dialog("option", "buttons", null);
@@ -354,9 +356,7 @@
"Cancel": function () {
$dialogRemoveAttachment.dialog("close");
}
});
$dialogRemoveAttachment.dialog('open');
}).dialog('open');
return false;
}
@@ -371,30 +371,32 @@
//#region LiveEvents
function liveMessageRecieved(d) {
if (d) {
switch (d.EntityTypeName) {
case 'JobAttachment':
switch (d.EventType) {
case 0: // Added
addAttachment(d.EntityKey[0], false);
break;
case 1: // Removed
removeAttachment(d.EntityKey[0]);
break;
}
break;
case 'JobLog':
switch (d.EventType) {
case 0: // Added
loadLiveComment(d.EntityKey[0]);
break;
case 1: // Removed
$CommentOutput.children('div[data-logid="' + d.EntityKey[0] + '"]').slideUp(300).delay(300).queue(function () {
$(this).remove();
});
break;
}
break;
}
window.setTimeout(function () {
switch (d.EntityTypeName) {
case 'JobAttachment':
switch (d.EventType) {
case 0: // Added
addAttachment(d.EntityKey[0], false);
break;
case 1: // Removed
removeAttachment(d.EntityKey[0]);
break;
}
break;
case 'JobLog':
switch (d.EventType) {
case 0: // Added
loadLiveComment(d.EntityKey[0]);
break;
case 1: // Removed
$CommentOutput.children('div[data-logid="' + d.EntityKey[0] + '"]').slideUp(300).delay(300).queue(function () {
$(this).remove();
});
break;
}
break;
}
}, 100);
}
}
var liveMessagesConnection = $.connection('@(Url.Content("~/API/Repository/Notifications"))')