0002-Feature-764-Add-enable-disable-support-for-Users.patch

b) Add enable/disable support to Sunstone users - Hector Sanjuan, 08/31/2011 11:29 PM

Download (6.52 KB)

View differences:

src/sunstone/models/OpenNebulaJSON/UserJSON.rb
37 37
            end
38 38

  
39 39
            rc = case action_hash['perform']
40
                 when "passwd" then self.passwd(action_hash['params'])
40
                 when "enable"       then self.enable
41
                 when "disable"      then self.disable
42
                 when "passwd"       then self.passwd(action_hash['params'])
41 43
                 when "chgrp"        then self.chgrp(action_hash['params'])
42
                 when "addgroup" then self.addgroup(action_hash['params'])
43
                 when "delgroup" then self.delgroup(action_hash['params'])
44
                 when "addgroup"     then self.addgroup(action_hash['params'])
45
                 when "delgroup"     then self.delgroup(action_hash['params'])
44 46
                 else
45 47
                     error_msg = "#{action_hash['perform']} action not " <<
46 48
                         " available for this resource"
src/sunstone/public/js/opennebula.js
1722 1722
            });
1723 1723
        },
1724 1724

  
1725
        "enable" : function(params)
1726
        {
1727
            var callback = params.success;
1728
            var callback_error = params.error;
1729
            var id = params.data.id;
1730

  
1731
            var method = "enable";
1732
            var action = OpenNebula.Helper.action(method);
1733
            var resource = OpenNebula.User.resource;
1734
            var request = OpenNebula.Helper.request(resource,method, id);
1735

  
1736
            $.ajax({
1737
                url: "user/" + id + "/action",
1738
                type: "POST",
1739
                data: JSON.stringify(action),
1740
                success: function()
1741
                {
1742
                    if (callback)
1743
                    {
1744
                        callback(request);
1745
                    }
1746
                },
1747
                error: function(response)
1748
                {
1749
                    if(callback_error)
1750
                    {
1751
                        callback_error(request, OpenNebula.Error(response));
1752
                    }
1753
                }
1754
            });
1755
        },
1756

  
1757
        "disable": function(params)
1758
        {
1759
            var callback = params.success;
1760
            var callback_error = params.error;
1761
            var id = params.data.id;
1762

  
1763
            var method = "disable";
1764
            var action = OpenNebula.Helper.action(method);
1765
            var resource = OpenNebula.User.resource;
1766
            var request = OpenNebula.Helper.request(resource,method, id);
1767

  
1768
            $.ajax({
1769
                url: "user/" + id + "/action",
1770
                type: "POST",
1771
                data: JSON.stringify(action),
1772
                success: function()
1773
                {
1774
                    if (callback)
1775
                    {
1776
                        callback(request);
1777
                    }
1778
                },
1779
                error: function(response)
1780
                {
1781
                    if(callback_error)
1782
                    {
1783
                        callback_error(request, OpenNebula.Error(response));
1784
                    }
1785
                }
1786
            });
1787
        },
1788

  
1725 1789
        "delete": function(params)
1726 1790
        {
1727 1791
            var callback = params.success;
src/sunstone/public/js/plugins/users-tab.js
30 30
      <th>ID</th>\
31 31
      <th>Name</th>\
32 32
      <th>Group</th>\
33
      <th>Enabled</th>\
33 34
    </tr>\
34 35
  </thead>\
35 36
  <tbody id="tbodyusers">\
......
135 136
        error: onError
136 137
    },
137 138

  
139
    "User.enable" : {
140
        type: "multiple",
141
        call: OpenNebula.User.enable,
142
        callback: userShow,
143
        elements: userElements,
144
        error: onError,
145
        notify: true
146
    },
147

  
148
    "User.disable" : {
149
        type: "multiple",
150
        call: OpenNebula.User.disable,
151
        callback: userShow,
152
        elements: userElements,
153
        error: onError,
154
        notify: true
155
    },
156

  
138 157
    "User.delete" : {
139 158
        type: "multiple",
140 159
        call: OpenNebula.User.delete,
......
175 194
    //     tip: "Select the group from which to delete users:",
176 195
    //     condition: True
177 196
    // },
197
    "User.enable" : {
198
        type: "action",
199
        text: "Enable"
200
    },
201
    "User.disable" : {
202
        type: "action",
203
        text: "Disable"
204
    },
178 205
    "User.delete" : {
179 206
        type: "action",
180 207
        text: "Delete"
......
194 221
    return getSelectedNodes(dataTable_users);
195 222
}
196 223

  
224
function userShow(req){
225
    Sunstone.runAction("User.show",req.request.data[0]);
226
}
227

  
197 228
// Returns an array with the values from the user_json ready to be
198 229
// added to the dataTable
199 230
function userElementArray(user_json){
......
203 234
        '<input type="checkbox" id="user_'+user.ID+'" name="selected_items" value="'+user.ID+'"/>',
204 235
        user.ID,
205 236
        user.NAME,
206
        user.GNAME
237
        user.GNAME,
238
        parseInt(user.ENABLED,10) ? "yes" : "no"
207 239
    ]
208 240
}
209 241

  
......
308 340
        "bAutoWidth":false,
309 341
        "aoColumnDefs": [
310 342
            { "bSortable": false, "aTargets": ["check"] },
343
            { "sWidth": "100px", "aTargets": [4] },
311 344
            { "sWidth": "60px", "aTargets": [0] },
312 345
            { "sWidth": "35px", "aTargets": [1] }
313 346
        ]
......
315 348
    dataTable_users.fnClearTable();
316 349
    addElement([
317 350
        spinner,
318
        '','',''],dataTable_users);
351
        '','','',''],dataTable_users);
319 352

  
320 353
    Sunstone.runAction("User.list");
321 354

  
322
-