Browse Source

Open edit window above main contactsmanager window.

pull/88/head
Evan Theurer 12 years ago
parent
commit
5381166c13
  1. 39
      static/js/controllers/contactsmanagercontroller.js
  2. 33
      static/js/directives/contactsmanager.js
  3. 22
      static/js/directives/settings.js
  4. 4
      static/partials/contactsmanager.html

39
static/js/controllers/contactsmanagercontroller.js

@ -25,27 +25,14 @@ define([], function() { @@ -25,27 +25,14 @@ define([], function() {
$scope.header = data.header;
$scope.contacts = [];
$scope.search = {};
var tmp = {};
tmp.displayName = data.contact ? data.contact.Status.displayName : null;
$scope.contact = data.contact;
$scope.contact = null;
$scope.session = null;
// Reference to use in contactsmanager directive
$scope.dlg = {
openEditContact: null,
openContactsManager: data.setupContactsManager
};
if (data.contact) {
var sessions = buddySession.sessions();
for (var id in sessions) {
if (sessions.hasOwnProperty(id) && sessions[id].Userid === $scope.contact.Userid) {
$scope.session = sessions[id] ? sessions[id].sessions[id] : null;
//console.log('contact manager session', $scope.session);
}
}
}
var tmp = {
displayName: data.contact ? data.contact.Status.displayName : null
};
var totalUnnamed = 0;
$scope.incrementUnnamedCount = function() {
return totalUnnamed += 1;
};
@ -67,6 +54,18 @@ define([], function() { @@ -67,6 +54,18 @@ define([], function() {
updateContacts(true);
});
// Values to check include 0, so check for number to get around incorrect 'false' type conversion
if(angular.isNumber(data.contactIndex)) {
$scope.contact = $scope.contacts[data.contactIndex];
var sessions = buddySession.sessions();
for (var id in sessions) {
if (sessions.hasOwnProperty(id) && sessions[id].Userid === $scope.contact.Userid) {
$scope.session = sessions[id] ? sessions[id].sessions[id] : null;
//console.log('contact manager session', $scope.session);
}
}
}
var setContactInfo = function(contact) {
contacts.update(contact.Userid, contact.Status);
};
@ -91,8 +90,8 @@ define([], function() { @@ -91,8 +90,8 @@ define([], function() {
$modalInstance.dismiss();
};
$scope.edit = function(contact) {
$modalInstance.close($scope.dlg.openEditContact(contact));
$scope.edit = function(index) {
$scope.$broadcast('openEditContact', index);
};
}];

33
static/js/directives/contactsmanager.js

@ -18,48 +18,29 @@ @@ -18,48 +18,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define(['underscore', 'jquery', 'modernizr'], function(_, $, Modernizr) {
define(['underscore', 'jquery'], function(_, $) {
// contactsmanager
return [function() {
var controller = ['$scope', 'dialogs', 'translation', '$templateCache', function($scope, dialogs, translation, $templateCache) {
var controller = ['$scope', 'dialogs', 'translation', function($scope, dialogs, translation) {
var ContactsManager = {};
ContactsManager._editDialog = function(contact) {
var editContactDialog = function(index) {
return dialogs.create(
"/contactsmanager/edit.html",
"ContactsmanagerController",
{
header: translation._("Edit Contact"),
contact: contact,
contactIndex: index,
}, {
wc: "contactsmanager"
}
);
};
ContactsManager.openMainModal = function() {
var that = this;
var dlgMain = $scope.dlg.openContactsManager();
dlgMain.result.then(function(contact) {
if (contact && contact.Id) {
that.openEditModal(contact);
}
});
};
ContactsManager.openEditModal = function(contact) {
var that = this;
var dlgEdit = that._editDialog(contact);
dlgEdit.result.finally(function(final) {
that.openMainModal();
});
};
$scope.dlg.openEditContact = function(contact) {
ContactsManager.openEditModal(contact);
};
$scope.$on('openEditContact', function(event, index) {
editContactDialog(index);
});
}];
return {

22
static/js/directives/settings.js

@ -52,19 +52,15 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -52,19 +52,15 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
});
$scope.openContactsManager = function() {
var setupContactsManager = function() {
return dialogs.create(
"/contactsmanager/main.html",
"ContactsmanagerController",
{
header: translation._("Contacts Manager"),
setupContactsManager: setupContactsManager
}, {
wc: "contactsmanager"
}
);
};
setupContactsManager();
return dialogs.create(
"/contactsmanager/main.html",
"ContactsmanagerController",
{
header: translation._("Contacts Manager")
}, {
wc: "contactsmanager"
}
);
};
$scope.saveSettings = function() {
var user = $scope.user;

4
static/partials/contactsmanager.html

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<div default-dialog contacts-manager>
<div default-dialog contactsmanager>
<div class="row head">
<div class="col-xs-7" ng-if="contacts.length === 0">
<p>{{_('You have no contacts.')}}</p>
@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
<span ng-if="!contact.Status.displayName" ng-init="i = incrementUnnamedCount()">Unnamed Contact {{i}}</span>
</td>
<td class="action">
<button class="btn btn-primary" ng-click="edit(contact)">{{_('Edit')}}</button>
<button class="btn btn-primary" ng-click="edit($index)">{{_('Edit')}}</button>
</td>
</tr>
</tbody>

Loading…
Cancel
Save