Commit f722ba72 authored by Vladimir Baranov's avatar Vladimir Baranov

rref #5392. Add popups to add user/unit to channel

parent 964b97b2
...@@ -10,6 +10,18 @@ angular.module("ulakbus.messaging") ...@@ -10,6 +10,18 @@ angular.module("ulakbus.messaging")
return channelKey; return channelKey;
} }
function searchWrapper(scope, promiseWrapper){
scope.loading = true;
scope.searchResult = [];
promiseWrapper()
.then(function(result){
scope.searchResult = result;
})
.finally(function(){
scope.loading = false;
})
}
return { return {
templateUrl: 'components/messaging/templates/index.html', templateUrl: 'components/messaging/templates/index.html',
restrict: 'E', restrict: 'E',
...@@ -31,15 +43,9 @@ angular.module("ulakbus.messaging") ...@@ -31,15 +43,9 @@ angular.module("ulakbus.messaging")
rootElement: popupRootElement, rootElement: popupRootElement,
link: function(scope){ link: function(scope){
scope.onChange = function(query){ scope.onChange = function(query){
scope.loading = true; searchWrapper(scope, function(){
scope.searchResult = []; return MessagingService.search_user(query);
MessagingService.search_user(query) })
.then(function(users){
scope.searchResult = users;
})
.finally(function(){
scope.loading = false;
})
}; };
scope.onChange(""); scope.onChange("");
} }
...@@ -56,10 +62,48 @@ angular.module("ulakbus.messaging") ...@@ -56,10 +62,48 @@ angular.module("ulakbus.messaging")
scope.channel = {}; scope.channel = {};
} }
}).then(function(channel){ }).then(function(channel){
return MessagingService.create_channel(channel.name, channel.description); return MessagingService.create_channel(channel.name, channel.description||"");
});
};
iScope.addUserToChannel = function(channel){
MessagingPopup.show({
templateUrl: "components/messaging/templates/add_user_unit.html",
rootElement: popupRootElement,
link: function(scope){
scope.title = "Add User";
scope.placeholder = "Search User to Add";
scope.onChange = function(query){
searchWrapper(scope, function(){
return MessagingService.search_user(query);
})
};
scope.onChange("");
}
}).then(function(userKey){
return MessagingService.add_members([userKey]);
}); });
}; };
iScope.addUnitToChannel = function(){
MessagingPopup.show({
templateUrl: "components/messaging/templates/add_user_unit.html",
rootElement: popupRootElement,
link: function(scope){
scope.title = "Add Unit";
scope.placeholder = "Search Unit to Add";
scope.onChange = function(query){
searchWrapper(scope, function(){
return MessagingService.search_unit(query);
})
};
scope.onChange("");
}
}).then(function(unitKey){
var channelKey = getKey(iScope.selectedChannel);
return MessagingService.add_members(channelKey, unitKey);
});
};
}, },
controller: function ($scope) { controller: function ($scope) {
...@@ -117,6 +161,10 @@ angular.module("ulakbus.messaging") ...@@ -117,6 +161,10 @@ angular.module("ulakbus.messaging")
$scope.shared.message = ""; $scope.shared.message = "";
}); });
} }
$scope.canAddUserAndChannel = function (channel) {
return channel && channel.type == MessagingService.CHANNEL_TYPE.PUBLIC;
}
} }
}; };
}) })
......
<div class="chat-popup-window add-user-unit" style="display:block;"> <div class="chat-popup-window add-user-unit" style="display:block;">
<div class="close-chat-popup-window"><span class="glyphicon glyphicon-remove"></span></div> <div class="close-chat-popup-window"><span class="glyphicon glyphicon-remove"></span></div>
<h3>Add User/Unit</h3> <h3>{{title}}</h3>
<div class="text-center"> <div class="text-center">
<input type="text" placeholder="Search User/Unit to Add"><br> <input type="text" placeholder="{{placeholder}}">
<div class="search-results">
<span class="loader" ng-show="loading"></span>
<div class="user" ng-repeat="item in searchResult" ng-click="done(item[1])">
<img ng-src="{{item[2]}}" ng-show="item[2]">
<div class="user-name">{{item[0]}}</div>
</div>
</div>
</div> </div>
</div> </div>
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
<li><a ng-click="applyChannelAction(action)" ng-repeat="action in selectedChannel.actions">{{action[0]}}</a></li> <li><a ng-click="applyChannelAction(action)" ng-repeat="action in selectedChannel.actions">{{action[0]}}</a></li>
</ul> </ul>
</div> </div>
<div class="close-chat-app"> <div class="close-chat-app" ng-click="hideApp()">
<span class="glyphicon glyphicon-remove" ng-click="hideApp()"></span> <span class="glyphicon glyphicon-remove"></span>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment