# Path: wireframes/models.py
# class Component(models.Model):
#     """(Component description)"""
# 
#     author = models.ForeignKey(User, null=True, blank=True)
#     project = models.ForeignKey(Project, null=True, blank=True)
#     name = models.CharField(blank=False, max_length=255)
#     creation_date = models.DateTimeField(auto_now=True)
# 
#     default_content = models.TextField(blank=True)
#     javascript = models.TextField()
#     css = models.TextField(blank=True)
# 
#     def css_out(self):
#         rules = ""
#         r_list = self.css.strip().split('}')
#         for r in r_list:
#             if r.strip():
#                 rules += ".component-%d %s }\n" % (self.id , r.strip())
#         return rules
# 
#     def __str__(self):
#         return "Component %s" % (self.name)
# 
# class Wireframe(models.Model):
#     """(Project description)"""
# 
#     author = models.ForeignKey(User, null=True)
#     project = models.ForeignKey(Project, null=True)
#     name = models.CharField(blank=False, max_length=255)
#     creation_date = models.DateTimeField(auto_now=True)
#     #model = models.ForeignKey(Wireframe, null=True)
#     grid_width = models.PositiveIntegerField(default="50")
#     grid_spacing = models.PositiveIntegerField(default="10")
#     grid_columns = models.PositiveIntegerField(default="16")
# 
#     def total_width(self):
#         return (self.grid_columns * self.grid_width) + (self.grid_spacing *
#                                         (self.grid_columns-1))
# 
# 
#     def __str__(self):
#         return "wireframe %s %d" % (self.name, self.id)
# 
#     def save(self):
#         super(Wireframe, self).save()
# 
# class Project(models.Model):
#     """(Project description)"""
# 
#     admin = models.ForeignKey(User, related_name='selfs_as_admin', null=True)
#     members = models.ManyToManyField(User, related_name='selfs_as_member')
# 
#     name = models.CharField(blank=False, max_length=255)
#     grid_width = models.PositiveIntegerField(default="50")
#     grid_spacing = models.PositiveIntegerField(default="10")
#     grid_columns = models.PositiveIntegerField(default="16")
# 
#     def total_width(self):
#         return self.grid_columns * self.grid_width + (self.grid_spacing * self.grid_columns-1)
# 
#     def __str__(self):
#         return "%s" % (self.name)
# 
#     def get_absolute_url(self):
#         return 'not done'
# 
#     def save(self):
#         super(Project, self).save()
# 
# Path: wireframes/widgets.py
# class CSSTextarea(Textarea):
#     """A RichTextarea widget."""
#     class Media:
#         js = [join(settings.MEDIA_URL, path) for path in (
#             'wireframes/codemirror/js/codemirror.js',
#         )]
#         css = {
#             'all': [join(settings.MEDIA_URL, path) for path in (
#                 'wireframes/codemirror/css/csscolors.css',
#                 'wireframes/codemirror/css/jscolors.css',
#                 #'wireframes/codemirror/css/docs.css',
#                 
#             )]
#         }
# 
#     def __init__(self, attrs=None):
#         #attrs = {'class': 'rte'}
#         super(Textarea, self).__init__(attrs)


from os.path import join
from django.contrib import admin
from django.db import models
from django.conf import settings
from wireframes.models import Component, Wireframe, Project
from wireframes.widgets import CSSTextarea


class ComponentAdmin(admin.ModelAdmin):
    class Media:
        js = [join(settings.MEDIA_URL, path) for path in (
            'wireframes/codemirror/js/codemirror.js',
            'wireframes/js/jquery.js',
            'wireframes/js/admin.js',
        )]
        css = {
            'all': [join(settings.MEDIA_URL, path) for path in (
                'wireframes/css/admin.css',
            )]
        }
    class Meta:
        model = Component

    formfield_overrides = {
        models.TextField: {'widget': CSSTextarea},
    }

class WireframeAdmin(admin.ModelAdmin):
    pass

class ProjetAdmin(admin.ModelAdmin):
    pass


admin.site.register(Project)
admin.site.register(Wireframe)

# Path: wireframes/models.py
# class Component(models.Model):
#     """(Component description)"""
# 
#     author = models.ForeignKey(User, null=True, blank=True)
#     project = models.ForeignKey(Project, null=True, blank=True)
#     name = models.CharField(blank=False, max_length=255)
#     creation_date = models.DateTimeField(auto_now=True)
# 
#     default_content = models.TextField(blank=True)
#     javascript = models.TextField()
#     css = models.TextField(blank=True)
# 
#     def css_out(self):
#         rules = ""
#         r_list = self.css.strip().split('}')
#         for r in r_list:
#             if r.strip():
#                 rules += ".component-%d %s }\n" % (self.id , r.strip())
#         return rules
# 
#     def __str__(self):
#         return "Component %s" % (self.name)
# 
# class Wireframe(models.Model):
#     """(Project description)"""
# 
#     author = models.ForeignKey(User, null=True)
#     project = models.ForeignKey(Project, null=True)
#     name = models.CharField(blank=False, max_length=255)
#     creation_date = models.DateTimeField(auto_now=True)
#     #model = models.ForeignKey(Wireframe, null=True)
#     grid_width = models.PositiveIntegerField(default="50")
#     grid_spacing = models.PositiveIntegerField(default="10")
#     grid_columns = models.PositiveIntegerField(default="16")
# 
#     def total_width(self):
#         return (self.grid_columns * self.grid_width) + (self.grid_spacing *
#                                         (self.grid_columns-1))
# 
# 
#     def __str__(self):
#         return "wireframe %s %d" % (self.name, self.id)
# 
#     def save(self):
#         super(Wireframe, self).save()
# 
# class Project(models.Model):
#     """(Project description)"""
# 
#     admin = models.ForeignKey(User, related_name='selfs_as_admin', null=True)
#     members = models.ManyToManyField(User, related_name='selfs_as_member')
# 
#     name = models.CharField(blank=False, max_length=255)
#     grid_width = models.PositiveIntegerField(default="50")
#     grid_spacing = models.PositiveIntegerField(default="10")
#     grid_columns = models.PositiveIntegerField(default="16")
# 
#     def total_width(self):
#         return self.grid_columns * self.grid_width + (self.grid_spacing * self.grid_columns-1)
# 
#     def __str__(self):
#         return "%s" % (self.name)
# 
#     def get_absolute_url(self):
#         return 'not done'
# 
#     def save(self):
#         super(Project, self).save()
# 
# Path: wireframes/widgets.py
# class CSSTextarea(Textarea):
#     """A RichTextarea widget."""
#     class Media:
#         js = [join(settings.MEDIA_URL, path) for path in (
#             'wireframes/codemirror/js/codemirror.js',
#         )]
#         css = {
#             'all': [join(settings.MEDIA_URL, path) for path in (
#                 'wireframes/codemirror/css/csscolors.css',
#                 'wireframes/codemirror/css/jscolors.css',
#                 #'wireframes/codemirror/css/docs.css',
#                 
#             )]
#         }
# 
#     def __init__(self, attrs=None):
#         #attrs = {'class': 'rte'}
#         super(Textarea, self).__init__(attrs)


# Path: wireframes/admin.py
from os.path import join
from django.contrib import admin
from django.db import models
from django.conf import settings
from wireframes.models import Component, Wireframe, Project
from wireframes.widgets import CSSTextarea



class ComponentAdmin(admin.ModelAdmin):
    class Media:
        js = [join(settings.MEDIA_URL, path) for path in (
            'wireframes/codemirror/js/codemirror.js',
            'wireframes/js/jquery.js',
            'wireframes/js/admin.js',
        )]
        css = {
            'all': [join(settings.MEDIA_URL, path) for path in (
                'wireframes/css/admin.css',
            )]
        }
    class Meta:
        model = Component

    formfield_overrides = {
        models.TextField: {'widget': CSSTextarea},
    }

class WireframeAdmin(admin.ModelAdmin):
    pass

class ProjetAdmin(admin.ModelAdmin):
    pass


admin.site.register(Project)
admin.site.register(Wireframe)

admin.site.register(Component, ComponentAdmin)