diff --git a/webclient/app-directive.js b/webclient/app-directive.js index d788475f46..c1ba0af3a9 100644 --- a/webclient/app-directive.js +++ b/webclient/app-directive.js @@ -41,18 +41,44 @@ angular.module('matrixWebClient') } }; }]) -.directive('elastic', [ // http://stackoverflow.com/questions/17772260/textarea-auto-height - '$timeout', - function($timeout) { - return { +.directive('asjson', function() { + return { restrict: 'A', - link: function($scope, element) { - var resize = function() { - return element[0].style.height = "" + element[0].scrollHeight + "px"; - }; - element.on("blur keyup change", resize); - $timeout(resize, 10); + require: 'ngModel', + link: function (scope, element, attrs, ngModelCtrl) { + function isValidJson(model) { + var flag = true; + try { + angular.fromJson(model); + } catch (err) { + flag = false; + } + return flag; + }; + + function string2JSON(text) { + try { + var j = angular.fromJson(text); + ngModelCtrl.$setValidity('json', true); + return j; + } catch (err) { + //returning undefined results in a parser error as of angular-1.3-rc.0, and will not go through $validators + //return undefined + ngModelCtrl.$setValidity('json', false); + return text; + } + }; + + function JSON2String(object) { + return angular.toJson(object, true); + }; + + //$validators is an object, where key is the error + //ngModelCtrl.$validators.json = isValidJson; + + //array pipelines + ngModelCtrl.$parsers.push(string2JSON); + ngModelCtrl.$formatters.push(JSON2String); } - }; } -]);; +}); diff --git a/webclient/app.js b/webclient/app.js index 099e2170a0..8d9b662ee9 100644 --- a/webclient/app.js +++ b/webclient/app.js @@ -31,7 +31,8 @@ var matrixWebClient = angular.module('matrixWebClient', [ 'eventStreamService', 'eventHandlerService', 'infinite-scroll', - 'ui.bootstrap' + 'ui.bootstrap', + 'monospaced.elastic' ]); matrixWebClient.config(['$routeProvider', '$provide', '$httpProvider', diff --git a/webclient/index.html b/webclient/index.html index 35c8051298..d8b9c95353 100644 --- a/webclient/index.html +++ b/webclient/index.html @@ -20,6 +20,7 @@ + diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index fcbcd75364..ce513990f2 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -1018,6 +1018,13 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput']) }; $scope.openRoomInfo = function() { + var stateFilter = $filter("stateEventsFilter"); + var stateEvents = stateFilter($scope.events.rooms[$scope.room_id]); + // The modal dialog will 2-way bind this field, so we MUST make a deep + // copy of the state events else we will be *actually adjusing our view + // of the world* when fiddling with the JSON!! Apparently parse/stringify + // is faster than jQuery's extend when doing deep copies. + $scope.roomInfoStateEvents = JSON.parse(JSON.stringify(stateEvents)); var modalInstance = $modal.open({ templateUrl: 'roomInfoTemplate.html', controller: 'RoomInfoController', @@ -1040,7 +1047,9 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput']) console.log("Displaying room info."); $scope.submit = function(event) { - console.error("submit >>> " + JSON.stringify(event)); + if (event.content) { + console.error("submit >>> " + JSON.stringify(event)); + } }; $scope.dismiss = $modalInstance.dismiss; diff --git a/webclient/room/room.html b/webclient/room/room.html index cc79d6b778..627918223a 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -16,7 +16,7 @@