Revision cbf7b384

b/snf-cyclades-app/synnefo/ui/static/snf/css/main.css
2579 2579
    margin-left: -15px;
2580 2580
}
2581 2581

  
2582
.createbutton.disabled, #networkscreate.disabled {
2583
  background-color: #888 !important;
2584
  border-left-color: #aaa !important;
2585
  cursor: help !important;
2586
  color: #ccc !important;
2587
}
2588

  
2582 2589
#networkscreate:hover {
2583 2590
    background-color: #FF9955;
2584 2591
}
b/snf-cyclades-app/synnefo/ui/static/snf/js/models.js
483 483
            this.bind("change:status", _.bind(this.update_state, this));
484 484
            return ret;
485 485
        },
486
        
487
        is_deleted: function() {
488
          return this.get('status') == 'DELETED';
489
        },
486 490

  
487 491
        toJSON: function() {
488 492
            var attrs = _.clone(this.attributes);
b/snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_main_view.js
740 740
            }
741 741
        },
742 742
        
743
        load_user_quotas: function() {
744
          var main_view = this;
745
          snf.api.sync('read', undefined, {
746
            url:'/ui/userquota', 
747
            success: function(d) {
748
              snf.user.quotas = {};
749
              snf.user.quotas['vms'] = d.vms_quota;
750
              snf.user.quotas['networks'] = d.networks_quota;
751
              main_view.init_quotas_handlers(['vms','networks']);
752
            }
753
          });
754
        },
755
        
756
        check_quotas: function(type) {
757
          var storage = synnefo.storage[type];
758
          var consumed = storage.length;
759
          if (type == "networks") {
760
            consumed = storage.filter(function(net){
761
              return !net.is_public() && !net.is_deleted();
762
            }).length;
763
          }
764
          if (snf.user.quotas && consumed >= snf.user.quotas[type]) {
765
            storage.trigger("quota_reached");
766
          } else {
767
            storage.trigger("quota_free");
768
          }
769
        },
770

  
771
        init_quotas_handlers: function(types) {
772
          var self = this;
773
          _.each(types, function(type) {
774
            var storage = synnefo.storage[type];
775
            if (!storage) { return };
776
            var check_quotas = function() {
777
              self.check_quotas(type);
778
            }
779
            storage.bind("add", check_quotas);
780
            storage.bind("remove", check_quotas);
781
            check_quotas();
782
          })
783
        },
784

  
743 785
        // initial view based on user cookie
744 786
        show_initial_view: function() {
745 787
          this.set_vm_view_handlers();
788
          this.load_user_quotas();
746 789
          this.hide_loading_view();
747 790
          
748 791
          bb.history.start();
......
751 794
        },
752 795

  
753 796
        show_vm_details: function(vm) {
754
            this.router.vm_details_view(vm.id);
797
            if (vm) {
798
              this.router.vm_details_view(vm.id);
799
            }
755 800
        },
756 801

  
757 802
        set_vm_view_handlers: function() {
758 803
            var self = this;
759 804
            $("#createcontainer #create").click(function(e){
760 805
                e.preventDefault();
806
                if ($(this).hasClass("disabled")) { return }
761 807
                self.router.vm_create_view();
762
            })
808
            });
809

  
810
            synnefo.storage.vms.bind("quota_reached", function(){
811
              $("#createcontainer #create").addClass("disabled");
812
              $("#createcontainer #create").attr("title", "Machines limit reached");
813
            });
814

  
815
            synnefo.storage.vms.bind("quota_free", function(){
816
              $("#createcontainer #create").removeClass("disabled");
817
              $("#createcontainer #create").attr("title", "");
818
            });
819

  
820
            this.check_quotas('vms');
763 821
        },
764 822

  
765 823
        check_empty: function() {
b/snf-cyclades-app/synnefo/ui/static/snf/js/ui/web/ui_networks_view.js
1249 1249
            storage.networks.bind("remove", _.bind(this.network_removed_handler, this, "remove"));
1250 1250

  
1251 1251
            this.$("#networkscreate").click(_.bind(function(e){
1252
                e.preventDefault();
1253
                this.create_view.show();
1252
              e.preventDefault();
1253
              if ($(this.$("#networkscreate")).hasClass("disabled")) { return }
1254
              this.create_view.show();
1254 1255
            }, this));
1255 1256
            
1257
            var self = this;
1258
            storage.networks.bind("quota_reached", function(){
1259
              self.$("#networkscreate").addClass("disabled").attr("title", 
1260
                                                            "Networks limit reached");
1261
            });
1262
            storage.networks.bind("quota_free", function(){
1263
              self.$("#networkscreate").removeClass("disabled").attr("title", 
1264
                                                            "");
1265
            });
1266
            
1267
            synnefo.ui.main.check_quotas("networks");
1256 1268
        },
1257 1269

  
1258 1270
        update_networks: function(nets) {
b/snf-cyclades-app/synnefo/ui/urls.py
38 38
urlpatterns = patterns('',
39 39
    url(r'^$', 'synnefo.ui.views.home', name='ui_index'),
40 40
    url(r'^feedback$', 'synnefo.ui.views.feedback_submit', name='ui_feedback'),
41
    url(r'^userquota$', 'synnefo.ui.views.user_quota', name='ui_userquota'),
41 42
    url(r'userdata/', include('synnefo.ui.userdata.urls'))
42 43
)
43 44

  
b/snf-cyclades-app/synnefo/ui/views.py
218 218
               'machine': machine, 'host_ip': host_ip, 'host_ip_v6': host_ip_v6}
219 219
    return template('machines_console', request, context)
220 220

  
221
def user_quota(request):
222
    get_user(request, settings.ASTAKOS_URL)
223
    vms_limit_for_user = \
224
        settings.VMS_USER_QUOTA.get(request.user_uniq,
225
                settings.MAX_VMS_PER_USER)
226

  
227
    networks_limit_for_user = \
228
        settings.NETWORKS_USER_QUOTA.get(request.user_uniq,
229
                settings.MAX_NETWORKS_PER_USER)
230
    return HttpResponse('{"vms_quota":%d, "networks_quota":%d}' % (vms_limit_for_user,
231
                                                               networks_limit_for_user),
232
                        mimetype="application/json")
233

  
221 234
def js_tests(request):
222 235
    return template('tests', request, {})
223 236

  

Also available in: Unified diff