Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==========================================================================
- // Project: McsDebugger.DebugNodeView
- // Copyright: ©2010 My Company, Inc.
- // ==========================================================================
- /*globals McsDebugger */
- /** @class
- (Document Your View Here)
- @extends SC.View
- */
- McsDebugger.DebugNodeView = SC.View.extend(
- /** @scope McsDebugger.DebugNodeView.prototype */ {
- classNames: ['debug-node-view'],
- displayProperties: 'debugNode displayDialogElement'.w(),
- displayDialogElement: SC.Object.create({
- 'Incoming Request' : YES,
- 'Incoming Request/Header' : YES,
- 'Incoming Request/Attributes' : YES,
- 'Incoming Request/Other Information' : YES,
- 'Outgoing Request' : YES,
- 'Outgoing Request/Header' : YES,
- 'Outgoing Request/Attributes' : YES,
- 'Outgoing Request/Other Information' : YES,
- 'Incoming Response' : YES,
- 'Incoming Response/Header' : YES,
- 'Incoming Response/Other Information' : YES,
- 'Outgoing Response' : YES,
- 'Outgoing Response/Header' : YES,
- 'Outgoing Request/Other Information' : YES
- }),
- /*
- * erichocean: you should use an array and then .join('') at the end of render()
- * erichocean: use SC.Benchmark to time your render() methods
- */
- _renderPayload: function(payload, context) {
- var columnCount = 3;
- var table = context.begin('table');
- table.begin('thead').begin('tr').begin('th').attr('colspan', columnCount).addClass('name').push(payload.content.name).end().end().end();
- var tbody = table.begin('tbody');
- this._renderHTTPDialogElement(payload.content.incomingRequest.request, 'Incoming Request', YES, tbody, columnCount);
- this._renderHTTPDialogElement(payload.content.outgoingRequest.request, 'Outgoing Request', YES, tbody, columnCount);
- this._renderHTTPDialogElement(payload.content.incomingResponse.response, 'Incoming Response', NO, tbody, columnCount);
- this._renderHTTPDialogElement(payload.content.outgoingResponse.response, 'Outgoing Response', NO, tbody, columnCount);
- tbody.end();
- table.end();
- },
- _renderHTTPDialogElement: function(element, caption, isRequest, tbody, columnCount) {
- tbody.begin('tr').begin('th').attr('colspan', columnCount).addClass('caption').push(caption).end().end();
- if (!this.get('displayDialogElement').get(caption)) return;
- var zebra = {
- cur: undefined,
- next: function() {
- this.cur = ((this.cur === 'even') ? 'odd' : 'even');
- return this.cur;
- },
- reset: function() {
- this.cur = undefined;
- }
- };
- tbody.begin('tr').begin('th').attr('colspan', columnCount).addClass('caption').addClass('subcaption').push(caption+'/Header').end().end();
- if (this.get('displayDialogElement').get(caption+'/Header')) {
- element.headers.forEach(function(header) {
- if (header.isSCArray) {
- var cookies = header.objectAt(0);
- var tr = tbody.begin('tr').addClass(zebra.next());
- tr.begin('th').attr('colspan', 1).attr('rowspan', cookies.get('length')).push('cookies').end();
- cookies.forEach(function(cookie) {
- if (tr == null) {
- tr = tbody.begin('tr').addClass(zebra.next());
- }
- tr.begin('td').attr('colspan', 1).push(cookie.name).end();
- tr.begin('td').attr('colspan', (columnCount - 2)).push(cookie.value).end();
- tr.end();
- tr = null;
- });
- } else {
- var index = header.indexOf(':');
- tbody.begin('tr').addClass(zebra.next())
- .begin('th').attr('colspan', 1).push(header.substring(0, index)).end()
- .begin('td').attr('colspan', (columnCount - 1)).push(header.substring(index + 1)).end()
- .end();
- }
- });
- }
- if (isRequest) {
- tbody.begin('tr').begin('th').attr('colspan', columnCount).addClass('caption').addClass('subcaption').push(caption+'/Attributes').end().end();
- if (this.get('displayDialogElement').get(caption+'/Attributes')) {
- element.attributes.forEach(function(attribute) {
- tbody.begin('tr').addClass(zebra.next())
- .begin('th').attr('colspan', 1).push(attribute.@name).end()
- .begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*attribute.#text*/).end()
- .end();
- });
- }
- }
- tbody.begin('tr').begin('th').attr('colspan', columnCount).addClass('caption').addClass('subcaption').push(caption+'/Other Information').end().end();
- if (this.get('displayDialogElement').get(caption+'/Other Information')) {
- if (isRequest) {
- var tr = tbody.begin('tr').addClass(zebra.next());
- tr.begin('th').attr('colspan', 1).push('Runtime (msec)').end();
- tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.runtime.#text*/).end();
- tr.end();
- tr = tbody.begin('tr').addClass(zebra.next());
- tr.begin('th').attr('colspan', 1).push('Request URI').end();
- tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.request-uri*/).end();
- tr.end();
- tr = tbody.begin('tr').addClass(zebra.next());
- tr.begin('th').attr('colspan', 1).push('Path Info').end();
- tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.path-info*/).end();
- tr.end();
- tr = tbody.begin('tr').addClass(zebra.next());
- tr.begin('th').attr('colspan', 1).push('Servlet Path').end();
- tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.servlet-path*/).end();
- tr.end();
- tr = tbody.begin('tr').addClass(zebra.next());
- tr.begin('th').attr('colspan', 1).push('Query String').end();
- tr.begin('td').attr('colspan', (columnCount - 1)).push('FIXME'/*element.query-string*/).end();
- tr.end();
- tr = tbody.begin('tr').addClass(zebra.next());
- tr.begin('th').attr('colspan', 1).push('Method').end();
- tr.begin('td').attr('colspan', (columnCount - 1)).push(element.method).end();
- tr.end();
- } else {
- //console.log(element);
- }
- }
- tbody.end();
- },
- render: function(context, firstTime) {
- var debugNode = this.get('debugNode');
- if (debugNode != null) {
- try {
- this._renderPayload(debugNode.get('payloadObject'), context);
- } catch (ex) {
- alert('Error rendering DebugNode: ' + ex);
- }
- }
- sc_super();
- },
- mouseDown: function(evt) {
- var caption = evt.target.textContent;
- if (!SC.none(this.get('displayDialogElement').get(caption))) {
- this.get('displayDialogElement').set(caption, !this.get('displayDialogElement').get(caption));
- this.notifyPropertyChange('displayDialogElement');
- }
- return YES;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement