servcomp WIP, get inlines working with drag-sortable
diff --git a/planetstack/servcomp/admin.py b/planetstack/servcomp/admin.py
index 65a646b..dc26b1e 100644
--- a/planetstack/servcomp/admin.py
+++ b/planetstack/servcomp/admin.py
@@ -12,6 +12,15 @@
 from suit.widgets import LinkedSelect
 from core.admin import SingletonAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, PlStackTabularInline
 
+class ServiceInline(PlStackTabularInline):
+    model = CompositionServiceThrough
+    verbose_name = "Service"
+    verbose_name_plural = "Services"
+    extra = 0
+    #suit_classes = 'suit-tab suit-tab-general'
+    fields = ('backend_status_icon', 'service', 'order')
+    readonly_fields = ('backend_status_icon',)
+
 class CompositionServiceAdmin(SingletonAdmin):
     model = CompositionService
     verbose_name = "Composition Service"
@@ -29,14 +38,22 @@
         ('serviceattrs','Additional Attributes'),
     )
 
+class CompositionForm(forms.ModelForm):
+    model = Composition
+    class Media:
+       js = ('/static/js/menu-sort-2.js',)
+
 class CompositionAdmin(ReadOnlyAwareAdmin):
     list_display = ('backend_status_icon', 'name' )
     list_display_links = ('backend_status_icon', 'name' )
+    form = CompositionForm
 
     fields = ('backend_status_text', 'name')
     readonly_fields = ('backend_status_text', )
     user_readonly_fields = ('name',)
 
+    inlines = [ServiceInline]
+
 class EndUserAdmin(ReadOnlyAwareAdmin):
     list_display = ('backend_status_icon', 'email', 'macAddress', 'composition' )
     list_display_links = ('backend_status_icon', 'email' )
diff --git a/planetstack/servcomp/models.py b/planetstack/servcomp/models.py
index a215409..3c17ffd 100644
--- a/planetstack/servcomp/models.py
+++ b/planetstack/servcomp/models.py
@@ -16,12 +16,16 @@
     name = models.CharField(max_length=255);
     services = models.ManyToManyField(Service, through='CompositionServiceThrough', blank=True);
 
+    def __unicode__(self):
+        return self.name
+
 class CompositionServiceThrough(PlCoreBase):
     class Meta:
         app_label = "servcomp"
+        ordering = ("order", )
 
-    Composition = models.ForeignKey(Composition)
-    Service = models.ForeignKey(Service, related_name="compositions")
+    composition = models.ForeignKey(Composition)
+    service = models.ForeignKey(Service, related_name="compositions")
     order = models.IntegerField(default=0)
 
 class EndUser(PlCoreBase):
@@ -34,3 +38,6 @@
     macAddress = models.CharField(max_length=80)
     composition = models.ForeignKey(Composition, related_name="endUsers", blank=True, null=True)
 
+    def __unicode__(self):
+        return self.email
+
diff --git a/planetstack/servcomp/static/js/menu-sort-2.js b/planetstack/servcomp/static/js/menu-sort-2.js
new file mode 100644
index 0000000..d7e3005
--- /dev/null
+++ b/planetstack/servcomp/static/js/menu-sort-2.js
@@ -0,0 +1,21 @@
+jQuery(function($) {
+    $("div.inline-group").sortable({ 
+        axis: 'y',
+        placeholder: 'ui-state-highlight', 
+        forcePlaceholderSize: 'true', 
+        items: '.row1, .row2', 
+        update: update
+    });
+    $("div.inline-group").disableSelection();
+});
+function update() {
+    $('.row1, .row2').each(function(i) {
+        $(this).find('input[id$=order]').val(i+1);
+    });
+}
+jQuery(document).ready(function($){
+//    $(this).find('input[id$=order]').parent('div').parent('div').hide().parent().parent().css('cursor','move');
+    $(this).find('input[id$=order]').parent('td').hide().parent('tr').parent('tbody').parent('table').find("th:contains('Order')").hide(); 
+    $(this).find('input[id$=order]').parent('td').hide().parent('tr').parent('tbody').parent('table').css('cursor','move');
+    $('.add-row a').click(update);
+});